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