Fork github.com/mattn/go-sqlite3 with adjustment for go1.16.2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB

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