TestFallbackPreparedStatement tests that DuckDB-specific syntax works with the extended query protocol (prepared statements)
(t *testing.T)
| 203 | // TestFallbackPreparedStatement tests that DuckDB-specific syntax works |
| 204 | // with the extended query protocol (prepared statements) |
| 205 | func TestFallbackPreparedStatement(t *testing.T) { |
| 206 | if testHarness == nil || testHarness.DuckgresDB == nil { |
| 207 | t.Skip("Test harness not available") |
| 208 | } |
| 209 | |
| 210 | db := testHarness.DuckgresDB |
| 211 | |
| 212 | t.Run("describe_simple", func(t *testing.T) { |
| 213 | skipIfKnown(t) |
| 214 | // Execute a DESCRIBE statement (no parameters) |
| 215 | rows, err := db.Query("DESCRIBE SELECT 1 AS num, 'hello' AS str") |
| 216 | if err != nil { |
| 217 | t.Fatalf("Failed to execute DESCRIBE: %v", err) |
| 218 | } |
| 219 | defer func() { _ = rows.Close() }() |
| 220 | |
| 221 | // Just verify we got some results |
| 222 | if !rows.Next() { |
| 223 | t.Error("Expected at least one row from DESCRIBE") |
| 224 | } |
| 225 | }) |
| 226 | |
| 227 | t.Run("pragma_table_info", func(t *testing.T) { |
| 228 | skipIfKnown(t) |
| 229 | // Use function-style PRAGMA which returns a table |
| 230 | rows, err := db.Query("SELECT * FROM pragma_table_info('users')") |
| 231 | if err != nil { |
| 232 | t.Fatalf("Failed to execute pragma_table_info: %v", err) |
| 233 | } |
| 234 | defer func() { _ = rows.Close() }() |
| 235 | |
| 236 | if !rows.Next() { |
| 237 | t.Error("Expected at least one row from pragma_table_info") |
| 238 | } |
| 239 | }) |
| 240 | |
| 241 | t.Run("from_first_syntax_no_params", func(t *testing.T) { |
| 242 | skipIfKnown(t) |
| 243 | // Test FROM-first syntax without parameters |
| 244 | // Note: Prepared statements with parameters don't work with fallback |
| 245 | // because EXPLAIN validation can't handle unbound parameters |
| 246 | rows, err := db.Query("FROM users SELECT name LIMIT 1") |
| 247 | if err != nil { |
| 248 | t.Fatalf("Failed to execute FROM-first query: %v", err) |
| 249 | } |
| 250 | defer func() { _ = rows.Close() }() |
| 251 | // Query executed successfully, that's the main test |
| 252 | }) |
| 253 | |
| 254 | t.Run("from_first_with_parameter", func(t *testing.T) { |
| 255 | skipIfKnown(t) |
| 256 | // Test FROM-first syntax WITH a parameter - this demonstrates the issue |
| 257 | // where ParamCount=0 for fallback queries |
| 258 | rows, err := db.Query("FROM users SELECT name WHERE id = $1", 1) |
| 259 | if err != nil { |
| 260 | t.Fatalf("Failed to execute FROM-first query with parameter: %v", err) |
| 261 | } |
| 262 | defer func() { _ = rows.Close() }() |