NewFlightSQLHandler creates a new multi-session Flight SQL handler.
(pool *SessionPool)
| 1783 | rollbackCtx, rollbackCancel := context.WithTimeout(context.Background(), 1*time.Second) |
| 1784 | if _, err := conn.ExecContext(rollbackCtx, "ROLLBACK"); err != nil { |
| 1785 | // ROLLBACK with no active txn returns a no-op error in some drivers; not fatal. |
| 1786 | slog.Debug("ROLLBACK during cleanup returned an error.", "error", err) |
| 1787 | } |
| 1788 | rollbackCancel() |
| 1789 | |
| 1790 | ok := dropTemporary(conn, |
| 1791 | "SELECT table_name FROM duckdb_tables() WHERE temporary = true", |
| 1792 | `DROP TABLE IF EXISTS temp."%s"`, |
| 1793 | ) |
| 1794 | // Run views even if tables failed — gives best-effort progress and a |
| 1795 | // consistent ok=false signal if anything didn't complete. |
| 1796 | ok = dropTemporary(conn, |
| 1797 | "SELECT view_name FROM duckdb_views() WHERE temporary = true", |
| 1798 | `DROP VIEW IF EXISTS temp."%s"`, |
| 1799 | ) && ok |
| 1800 | return ok |
| 1801 | } |
| 1802 | |
| 1803 | func dropTemporary(conn *sql.Conn, query, dropFmt string) bool { |
| 1804 | // Per-step contexts: previously a single 5s context spanned both the |
| 1805 | // SELECT and every DROP. A slow SELECT could exhaust the budget before |