Commit e238c754 authored by gwenn's avatar gwenn

Add binding to sqlite3_limit

parent dbabae2f
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package sqlite
/*
#include <sqlite3.h>
*/
import "C"
type Limit int32
const (
LimitLength Limit = C.SQLITE_LIMIT_LENGTH
LimitColumn Limit = C.SQLITE_LIMIT_COLUMN
LimitExprDepth Limit = C.SQLITE_LIMIT_EXPR_DEPTH
LimitCompoundSelect Limit = C.SQLITE_LIMIT_COMPOUND_SELECT
LimitVdbeOp Limit = C.SQLITE_LIMIT_VDBE_OP
LimitFunctionArg Limit = C.SQLITE_LIMIT_FUNCTION_ARG
LimitAttached Limit = C.SQLITE_LIMIT_ATTACHED
LimitLikePatternLength Limit = C.SQLITE_LIMIT_LIKE_PATTERN_LENGTH
LimitVariableNumber Limit = C.SQLITE_LIMIT_VARIABLE_NUMBER
LimitTriggerLength Limit = C.SQLITE_LIMIT_TRIGGER_DEPTH
)
// Limit queries the current value of a limit.
// (See http://www.sqlite.org/c3ref/c_limit_attached.html)
func (c *Conn) Limit(id Limit) int32 {
return int32(C.sqlite3_limit(c.db, C.int(id), -1))
}
// SetLimit changes the value of a limit.
// (See http://www.sqlite.org/c3ref/c_limit_attached.html)
func (c *Conn) SetLimit(id Limit, newVal int32) int32 {
return int32(C.sqlite3_limit(c.db, C.int(id), C.int(newVal)))
}
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package sqlite_test
import (
"testing"
"github.com/bmizerany/assert"
. "github.com/gwenn/gosqlite"
)
func TestLimit(t *testing.T) {
db := open(t)
defer checkClose(db, t)
limitVariableNumber := db.Limit(LimitVariableNumber)
assert.T(t, limitVariableNumber < 1000, "unexpected value for LimitVariableNumber")
oldLimitVariableNumber := db.SetLimit(LimitVariableNumber, 99)
assert.Equalf(t, limitVariableNumber, oldLimitVariableNumber, "unexpected value for LimitVariableNumber: %d <> %d", limitVariableNumber, oldLimitVariableNumber)
limitVariableNumber = db.Limit(LimitVariableNumber)
assert.Equalf(t, int32(99), limitVariableNumber, "unexpected value for LimitVariableNumber: %d <> %d", 99, limitVariableNumber)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment