Skip to content

Commit ab91e93

Browse files
committed
make column metadata functionality opt-in
1 parent 95e88ca commit ab91e93

File tree

5 files changed

+61
-44
lines changed

5 files changed

+61
-44
lines changed

.github/workflows/go.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
run: go-acc . -- -race -v -tags "libsqlite3"
4545

4646
- name: 'Tags: full'
47-
run: go-acc . -- -race -v -tags "sqlite_allow_uri_authority sqlite_app_armor sqlite_foreign_keys sqlite_fts5 sqlite_icu sqlite_introspect sqlite_json sqlite_preupdate_hook sqlite_secure_delete sqlite_see sqlite_stat4 sqlite_trace sqlite_userauth sqlite_vacuum_incr sqlite_vtable sqlite_unlock_notify"
47+
run: go-acc . -- -race -v -tags "sqlite_allow_uri_authority sqlite_app_armor sqlite_foreign_keys sqlite_fts5 sqlite_icu sqlite_introspect sqlite_json sqlite_preupdate_hook sqlite_secure_delete sqlite_see sqlite_stat4 sqlite_trace sqlite_userauth sqlite_vacuum_incr sqlite_vtable sqlite_unlock_notify sqlite_column_metadata"
4848

4949
- name: 'Tags: vacuum'
5050
run: go-acc . -- -race -v -tags "sqlite_vacuum_full"

sqlite3.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package sqlite3
1919
#cgo CFLAGS: -DSQLITE_OMIT_DEPRECATED
2020
#cgo CFLAGS: -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1
2121
#cgo CFLAGS: -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT
22-
#cgo CFLAGS: -DSQLITE_ENABLE_COLUMN_METADATA
2322
#cgo CFLAGS: -Wno-deprecated-declarations
2423
#cgo linux,!android CFLAGS: -DHAVE_PREAD64=1 -DHAVE_PWRITE64=1
2524
#ifndef USE_LIBSQLITE3
@@ -2015,14 +2014,6 @@ func (s *SQLiteStmt) Readonly() bool {
20152014
return C.sqlite3_stmt_readonly(s.s) == 1
20162015
}
20172016

2018-
// ColumnTableName returns the table that is the origin of a particular result
2019-
// column in a SELECT statement.
2020-
//
2021-
// See https://www.sqlite.org/c3ref/column_database_name.html
2022-
func (s *SQLiteStmt) ColumnTableName(n int) string {
2023-
return C.GoString(C.sqlite3_column_table_name(s.s, C.int(n)))
2024-
}
2025-
20262017
// Close the rows.
20272018
func (rc *SQLiteRows) Close() error {
20282019
rc.s.mu.Lock()

sqlite3_opt_column_metadata.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// +build sqlite_column_metadata
2+
3+
package sqlite3
4+
5+
/*
6+
#ifndef USE_LIBSQLITE3
7+
#cgo CFLAGS: -DSQLITE_ENABLE_COLUMN_METADATA
8+
#include <sqlite3-binding.h>
9+
#else
10+
#include <sqlite3.h>
11+
#endif
12+
*/
13+
import "C"
14+
15+
// ColumnTableName returns the table that is the origin of a particular result
16+
// column in a SELECT statement.
17+
//
18+
// See https://www.sqlite.org/c3ref/column_database_name.html
19+
func (s *SQLiteStmt) ColumnTableName(n int) string {
20+
return C.GoString(C.sqlite3_column_table_name(s.s, C.int(n)))
21+
}

sqlite3_opt_column_metadata_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// +build sqlite_column_metadata
2+
3+
package sqlite3
4+
5+
import "testing"
6+
7+
func TestColumnTableName(t *testing.T) {
8+
d := SQLiteDriver{}
9+
conn, err := d.Open(":memory:")
10+
if err != nil {
11+
t.Fatal("failed to get database connection:", err)
12+
}
13+
defer conn.Close()
14+
sqlite3conn := conn.(*SQLiteConn)
15+
16+
_, err = sqlite3conn.Exec(`CREATE TABLE foo (name string)`, nil)
17+
if err != nil {
18+
t.Fatal("Failed to create table:", err)
19+
}
20+
_, err = sqlite3conn.Exec(`CREATE TABLE bar (name string)`, nil)
21+
if err != nil {
22+
t.Fatal("Failed to create table:", err)
23+
}
24+
25+
stmt, err := sqlite3conn.Prepare(`SELECT * FROM foo JOIN bar ON foo.name = bar.name`)
26+
if err != nil {
27+
t.Fatal(err)
28+
}
29+
30+
if exp, got := "foo", stmt.(*SQLiteStmt).ColumnTableName(0); exp != got {
31+
t.Fatalf("Incorrect table name returned expected: %s, got: %s", exp, got)
32+
}
33+
if exp, got := "bar", stmt.(*SQLiteStmt).ColumnTableName(1); exp != got {
34+
t.Fatalf("Incorrect table name returned expected: %s, got: %s", exp, got)
35+
}
36+
if exp, got := "", stmt.(*SQLiteStmt).ColumnTableName(2); exp != got {
37+
t.Fatalf("Incorrect table name returned expected: %s, got: %s", exp, got)
38+
}
39+
}

sqlite3_test.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,40 +1604,6 @@ func TestDeclTypes(t *testing.T) {
16041604
}
16051605
}
16061606

1607-
func TestColumnTableName(t *testing.T) {
1608-
d := SQLiteDriver{}
1609-
conn, err := d.Open(":memory:")
1610-
if err != nil {
1611-
t.Fatal("failed to get database connection:", err)
1612-
}
1613-
defer conn.Close()
1614-
sqlite3conn := conn.(*SQLiteConn)
1615-
1616-
_, err = sqlite3conn.Exec(`CREATE TABLE foo (name string)`, nil)
1617-
if err != nil {
1618-
t.Fatal("Failed to create table:", err)
1619-
}
1620-
_, err = sqlite3conn.Exec(`CREATE TABLE bar (name string)`, nil)
1621-
if err != nil {
1622-
t.Fatal("Failed to create table:", err)
1623-
}
1624-
1625-
stmt, err := sqlite3conn.Prepare(`SELECT * FROM foo JOIN bar ON foo.name = bar.name`)
1626-
if err != nil {
1627-
t.Fatal(err)
1628-
}
1629-
1630-
if exp, got := "foo", stmt.(*SQLiteStmt).ColumnTableName(0); exp != got {
1631-
t.Fatalf("Incorrect table name returned expected: %s, got: %s", exp, got)
1632-
}
1633-
if exp, got := "bar", stmt.(*SQLiteStmt).ColumnTableName(1); exp != got {
1634-
t.Fatalf("Incorrect table name returned expected: %s, got: %s", exp, got)
1635-
}
1636-
if exp, got := "", stmt.(*SQLiteStmt).ColumnTableName(2); exp != got {
1637-
t.Fatalf("Incorrect table name returned expected: %s, got: %s", exp, got)
1638-
}
1639-
}
1640-
16411607
func TestPinger(t *testing.T) {
16421608
db, err := sql.Open("sqlite3", ":memory:")
16431609
if err != nil {

0 commit comments

Comments
 (0)