IsPureDataQuery inspects if the plan is a pure data query, i.e., it operates on (>=1) data tables and does not touch any system tables. The following examples are NOT pure data queries: - `SELECT * FROM mysql.*` - `TRUNCATE mysql.user` - `SELECT DATABASE()`
(n sql.Node)
| 289 | |
| 290 | // Execute the DuckDB query |
| 291 | rows, err := conn.QueryContext(ctx.Context, duckSQL) |
| 292 | if err != nil { |
| 293 | return nil, err |
| 294 | } |
| 295 | |
| 296 | return NewSQLRowIter(rows, n.Schema(ctx)) |
| 297 | } |
| 298 | |
| 299 | func (b *DuckBuilder) executeDML(ctx *sql.Context, n sql.Node, conn *stdsql.Conn) (sql.RowIter, error) { |
| 300 | // Translate the MySQL query to a DuckDB query |
| 301 | duckSQL, err := transpiler.TranslateWithSQLGlot(queryForTranslation(ctx)) |
| 302 | if err != nil { |
| 303 | return nil, catalog.ErrTranspiler.New(err) |
| 304 | } |
| 305 | |
| 306 | if log := ctx.GetLogger(); log.Logger.IsLevelEnabled(logrus.TraceLevel) { |
| 307 | log.WithFields(logrus.Fields{ |
| 308 | "Query": ctx.Query(), |
| 309 | "DuckSQL": duckSQL, |
| 310 | }).Trace("Executing DML...") |
| 311 | } |
| 312 | |
| 313 | var affected, insertID int64 |
| 314 | if _, ok := n.(*plan.TableCopier); ok { |
| 315 | // DuckDB returns the CTAS insert count as a one-row result. Its C API |
| 316 | // rows-changed value is defined only for INSERT, UPDATE, and DELETE. |
| 317 | err = conn.QueryRowContext(ctx.Context, duckSQL).Scan(&affected) |
| 318 | } else { |
| 319 | var result stdsql.Result |
| 320 | result, err = conn.ExecContext(ctx.Context, duckSQL) |
| 321 | if err == nil { |