Commit aa28066a authored by gwenn's avatar gwenn

Add bindings to sqlite3_column_database|table|origin_name.

parent 28b88271
......@@ -147,6 +147,24 @@ func (c *Conn) Column(dbName, tableName, columnName string) (*Column, error) {
autoinc == 1, C.GoString(zCollSeq)}, nil
}
// The left-most column is column 0
// (See http://www.sqlite.org/c3ref/column_database_name.html)
func (s *Stmt) ColumnDatabaseName(index int) string {
return C.GoString(C.sqlite3_column_database_name(s.stmt, C.int(index)))
}
// The left-most column is column 0
// (See http://www.sqlite.org/c3ref/column_database_name.html)
func (s *Stmt) ColumnTableName(index int) string {
return C.GoString(C.sqlite3_column_table_name(s.stmt, C.int(index)))
}
// The left-most column is column 0
// (See http://www.sqlite.org/c3ref/column_database_name.html)
func (s *Stmt) ColumnOriginName(index int) string {
return C.GoString(C.sqlite3_column_origin_name(s.stmt, C.int(index)))
}
// See Conn.ForeignKeys
type ForeignKey struct {
Table string
......
......@@ -111,3 +111,18 @@ func TestIndexes(t *testing.T) {
column := columns[0]
assertEquals(t, "Wrong column name: %q <> %q", "a_string", column.Name)
}
func TestColumnMetadata(t *testing.T) {
db := open(t)
defer db.Close()
s, err := db.Prepare("SELECT name AS table_name FROM sqlite_master")
check(err)
defer s.Finalize()
databaseName := s.ColumnDatabaseName(0)
assertEquals(t, "wrong database name: %q <> %q", "main", databaseName)
tableName := s.ColumnTableName(0)
assertEquals(t, "wrong table name: %q <> %q", "sqlite_master", tableName)
originName := s.ColumnOriginName(0)
assertEquals(t, "wrong origin name: %q <> %q", "name", originName)
}
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