Execute SQL statement synchronously and return row data or error. rowLimit caps the result set when > 0; 0 means no limit (used by sync and dump paths). DDL/DML callers should pass 0.
(ctx context.Context, statement string, rowLimit int64)
| 161 | // rowLimit caps the result set when > 0; 0 means no limit (used by sync |
| 162 | // and dump paths). DDL/DML callers should pass 0. |
| 163 | func (d *Driver) execStatementSync(ctx context.Context, statement string, rowLimit int64) ([][]string, []dbsql.ColumnInfo, error) { |
| 164 | // Bind the connected Bytebase database (= Unity Catalog) to the |
| 165 | // session, so unqualified `schema.table` references resolve like in |
| 166 | // other RDBMSes. Equivalent to issuing `USE CATALOG <name>` first. |
| 167 | req := dbsql.ExecuteStatementRequest{ |
| 168 | Statement: statement, |
| 169 | WarehouseId: d.WarehouseID, |
| 170 | Catalog: d.curCatalog, |
| 171 | } |
| 172 | // Honor the user-selected row limit (default 1000 from the SQL Editor). |
| 173 | // Without it, INLINE results above ~25 MiB are aborted server-side |
| 174 | // with no result available — see DispositionExternalLinks for the |
| 175 | // large-result path. |
| 176 | if rowLimit > 0 { |
| 177 | req.RowLimit = rowLimit |
| 178 | } |
| 179 | resp, err := d.Client.StatementExecution.ExecuteAndWait(ctx, req) |
| 180 | if err != nil { |
| 181 | return nil, nil, err |
| 182 | } |
| 183 | if resp.Result == nil { |
| 184 | return nil, nil, errors.New("no response") |
| 185 | } |
| 186 | |
| 187 | if len(resp.Result.DataArray) != 0 { |
| 188 | if resp.Manifest == nil || resp.Manifest.Schema == nil || len(resp.Manifest.Schema.Columns) == 0 { |
| 189 | return nil, nil, errors.New("missing column info") |
| 190 | } |
| 191 | return resp.Result.DataArray, resp.Manifest.Schema.Columns, nil |
| 192 | } |
| 193 | return nil, nil, nil |
| 194 | } |
| 195 | |
| 196 | // return a column type name array and a column name array. |
| 197 | func toStrColInfo(colInfo []dbsql.ColumnInfo) ([]string, []string) { |
no outgoing calls
no test coverage detected