shouldUseSQLQuery returns true for statements that return row sets and must use QueryContext. INSERT/UPDATE/DELETE without RETURNING should use ExecContext so DuckDB applies mutations reliably (Query-only INSERTs could be invisible to subsequent SELECTs on some paths).
(sql string)
| 283 | // so DuckDB applies mutations reliably (Query-only INSERTs could be invisible |
| 284 | // to subsequent SELECTs on some paths). |
| 285 | func shouldUseSQLQuery(sql string) bool { |
| 286 | u := strings.TrimSpace(strings.ToUpper(sql)) |
| 287 | if strings.Contains(u, "RETURNING") { |
| 288 | return true |
| 289 | } |
| 290 | switch { |
| 291 | case strings.HasPrefix(u, "SELECT"): |
| 292 | return true |
| 293 | case strings.HasPrefix(u, "WITH"): |
| 294 | return true |
| 295 | case strings.HasPrefix(u, "SHOW"): |
| 296 | return true |
| 297 | case strings.HasPrefix(u, "DESCRIBE"): |
| 298 | return true |
| 299 | case strings.HasPrefix(u, "PRAGMA"): |
| 300 | return true |
| 301 | case strings.HasPrefix(u, "EXPLAIN"): |
| 302 | return true |
| 303 | default: |
| 304 | return false |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | func sqlStringLiteral(value string) string { |
| 309 | escaped := strings.ReplaceAll(value, "'", "''") |