| 76 | } |
| 77 | |
| 78 | func prepareQueryForGetTables(cmd flightsql.GetTables) string { |
| 79 | var b strings.Builder |
| 80 | b.WriteString(`SELECT 'main' AS catalog_name, '' AS schema_name, |
| 81 | name AS table_name, type AS table_type FROM sqlite_master WHERE 1=1`) |
| 82 | |
| 83 | if cmd.GetCatalog() != nil { |
| 84 | b.WriteString(" and catalog_name = '") |
| 85 | b.WriteString(*cmd.GetCatalog()) |
| 86 | b.WriteByte('\'') |
| 87 | } |
| 88 | |
| 89 | if cmd.GetDBSchemaFilterPattern() != nil { |
| 90 | b.WriteString(" and schema_name LIKE '") |
| 91 | b.WriteString(*cmd.GetDBSchemaFilterPattern()) |
| 92 | b.WriteByte('\'') |
| 93 | } |
| 94 | |
| 95 | if cmd.GetTableNameFilterPattern() != nil { |
| 96 | b.WriteString(" and table_name LIKE '") |
| 97 | b.WriteString(*cmd.GetTableNameFilterPattern()) |
| 98 | b.WriteByte('\'') |
| 99 | } |
| 100 | |
| 101 | if len(cmd.GetTableTypes()) > 0 { |
| 102 | b.WriteString(" and table_type IN (") |
| 103 | for i, t := range cmd.GetTableTypes() { |
| 104 | if i != 0 { |
| 105 | b.WriteByte(',') |
| 106 | } |
| 107 | fmt.Fprintf(&b, "'%s'", t) |
| 108 | } |
| 109 | b.WriteByte(')') |
| 110 | } |
| 111 | |
| 112 | b.WriteString(" order by table_name") |
| 113 | return b.String() |
| 114 | } |
| 115 | |
| 116 | func prepareQueryForGetKeys(filter string) string { |
| 117 | return `SELECT * FROM ( |