Update Introspect

* Add Tests
* Fix Compile time option
This commit is contained in:
Gert-Jan Timmer 2018-06-14 10:21:04 +02:00
parent de6249ddc9
commit 9e093e4702
2 changed files with 107 additions and 1 deletions

View File

@ -9,7 +9,7 @@
package sqlite3 package sqlite3
/* /*
#cgo CFLAGS: -DSQLITE_INTROSPECTION_PRAGMAS #cgo CFLAGS: -DSQLITE_INTROSPECTION_PRAGMAS=1
#cgo LDFLAGS: -lm #cgo LDFLAGS: -lm
*/ */
import "C" import "C"

View File

@ -0,0 +1,106 @@
// Copyright (C) 2014 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
// Copyright (C) 2018 G.J.R. Timmer <gjr.timmer@gmail.com>.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
// +build sqlite_introspect
package sqlite3
import (
"database/sql"
"os"
"testing"
)
func TestIntrospectFunctionList(t *testing.T) {
tempFilename := TempFilename(t)
defer os.Remove(tempFilename)
db, err := sql.Open("sqlite3", "file:"+tempFilename)
if err != nil {
t.Fatal(err)
}
defer db.Close()
rows, err := db.Query("PRAGMA function_list;")
if err != nil {
t.Fatal(err)
}
defer rows.Close()
var list []string
for rows.Next() {
var s string
var s2 string
err := rows.Scan(&s, &s2)
if err != nil {
t.Fatal(err)
}
list = append(list, s)
}
if len(list) == 0 {
t.Fatal("Introspect: No Function List Available")
}
}
func TestIntrospectModuleList(t *testing.T) {
tempFilename := TempFilename(t)
defer os.Remove(tempFilename)
db, err := sql.Open("sqlite3", "file:"+tempFilename)
if err != nil {
t.Fatal(err)
}
defer db.Close()
rows, err := db.Query("PRAGMA module_list;")
if err != nil {
t.Fatal(err)
}
defer rows.Close()
var list []string
for rows.Next() {
var s string
err := rows.Scan(&s)
if err != nil {
t.Fatal(err)
}
list = append(list, s)
}
if len(list) == 0 {
t.Fatal("Introspect: No Module List Available")
}
}
func TestIntrospectPRAGMAList(t *testing.T) {
tempFilename := TempFilename(t)
defer os.Remove(tempFilename)
db, err := sql.Open("sqlite3", "file:"+tempFilename)
if err != nil {
t.Fatal(err)
}
defer db.Close()
rows, err := db.Query("PRAGMA pragma_list;")
if err != nil {
t.Fatal(err)
}
defer rows.Close()
var list []string
for rows.Next() {
var s string
err := rows.Scan(&s)
if err != nil {
t.Fatal(err)
}
list = append(list, s)
}
if len(list) == 0 {
t.Fatal("Introspect: No PRAGMA List Available")
}
}