2018-06-29 12:39:30 +03:00
|
|
|
// Copyright (C) 2018 The Go-SQLite3 Authors.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by an MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build cgo
|
2018-07-03 15:20:44 +03:00
|
|
|
// +build !libsqlite3
|
2018-06-29 12:39:30 +03:00
|
|
|
|
|
|
|
package sqlite3
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLimit(t *testing.T) {
|
|
|
|
tempFilename := TempFilename(t)
|
|
|
|
defer os.Remove(tempFilename)
|
|
|
|
|
|
|
|
driverName := fmt.Sprintf("sqlite3-%s", t.Name())
|
|
|
|
|
|
|
|
var driverConn *SQLiteConn
|
|
|
|
sql.Register(driverName, &SQLiteDriver{
|
|
|
|
ConnectHook: func(conn *SQLiteConn) error {
|
|
|
|
driverConn = conn
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
db, err := sql.Open(driverName, tempFilename)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer db.Close()
|
|
|
|
if err := db.Ping(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-07-03 15:04:11 +03:00
|
|
|
if rv := driverConn.SetLimit(SQLITE_LIMIT_TRIGGER_DEPTH, 5); rv != 1000 && rv != -1 {
|
2018-07-22 23:32:19 +03:00
|
|
|
t.Fatalf("unable to set limit; %d", rv)
|
2018-06-29 12:39:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if limit := driverConn.GetLimit(SQLITE_LIMIT_TRIGGER_DEPTH); limit != 5 {
|
2018-07-22 23:32:19 +03:00
|
|
|
t.Fatal("limit was not set correctly")
|
2018-06-29 12:39:30 +03:00
|
|
|
}
|
|
|
|
}
|