Skip to content

Commit a5bdd08

Browse files
committed
Support DESC {OWNER}.{TABLE} in SQLite3
1 parent f8c5f67 commit a5bdd08

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

dialect/query.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,20 @@ func (e *Entry) BuildSQLForTables() string {
7272
}
7373

7474
// BuildSQLForColumns returns the SQL statement used to retrieve the list of columns
75-
// for the given table name. The placeholder "{table_name}" in the template will be replaced.
75+
// for the given table name. The placeholder "{table}" in the template will be replaced.
7676
func (e *Entry) BuildSQLForColumns(table string) string {
77-
return strings.ReplaceAll(e.SQLForColumns, "{table_name}", table)
77+
var schema string
78+
var schemaDot string
79+
if dotPos := strings.IndexByte(table, '.'); dotPos >= 0 {
80+
schema = table[:dotPos]
81+
schemaDot = table[:dotPos+1]
82+
table = table[dotPos+1:]
83+
}
84+
sql := e.SQLForColumns
85+
sql = strings.ReplaceAll(sql, "{table}", table)
86+
sql = strings.ReplaceAll(sql, "{schema}", schema)
87+
sql = strings.ReplaceAll(sql, "{schema.}", schemaDot)
88+
return sql
7889
}
7990

8091
// Tables executes the SQL to list all table names defined by the dialect.

dialect/sqlite/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var Entry = &dialect.Entry{
2222
where type = 'table'`,
2323
TypeConverterFor: typeNameToConv,
2424
PlaceHolder: &placeHolder{},
25-
SQLForColumns: `PRAGMA table_info({table_name})`,
25+
SQLForColumns: `PRAGMA {schema.}table_info({table})`,
2626
TableNameField: "name",
2727
ColumnNameField: "name",
2828
IsTransactionSafe: canUseInTransaction,

0 commit comments

Comments
 (0)