t8y2/dbx · error

SQL is required

Error message

SQL is required

What it means

get_explain_info runs 'EXPLAIN <sql>' and requires non-empty SQL. trim_sql strips whitespace; if nothing remains, the driver rejects the call instead of sending a meaningless EXPLAIN statement to the server.

Source

Thrown at agents/drivers/tdengine/src/driver.rs:436

            affected_rows += i64::from(result_set.affected_rows());
        }
        if statements.iter().any(|statement| may_change_metadata(statement)) {
            self.table_cache = None;
        }
        Ok(QueryResult {
            columns: Vec::new(),
            column_types: Vec::new(),
            rows: Vec::new(),
            affected_rows,
            execution_time_ms: start.elapsed().as_millis() as i64,
            truncated: false,
        })
    }

    pub async fn get_explain_info(&self, sql: &str, token: &CancellationToken, timeout_secs: u64) -> Result<String> {
        let sql = trim_sql(sql);
        if sql.is_empty() {
            bail!("SQL is required");
        }
        let rows = self.query_rows(&format!("EXPLAIN {sql}"), token, timeout_secs).await?;
        Ok(rows
            .into_iter()
            .map(|row| row.iter().map(display_json_value).collect::<Vec<_>>().join("\t"))
            .collect::<Vec<_>>()
            .join("\n"))
    }

    async fn prepare_database(&mut self, options: &QueryOptions, token: &CancellationToken) -> Result<()> {
        let database = if options.schema.trim().is_empty() { options.database.trim() } else { options.schema.trim() };
        if database.is_empty() || database == self.current_database {
            return Ok(());
        }
        self.use_database(database, token, options.timeout_secs).await
    }

    async fn use_database(&mut self, database: &str, token: &CancellationToken, timeout_secs: u64) -> Result<()> {

View on GitHub (pinned to c0390bff16)

Solutions

  1. Pass the actual SQL text to get_explain_info
  2. Check sql.trim().is_empty() at the caller/API layer and return a 400-style validation error before invoking the driver

Example fix

// before
driver.get_explain_info("", &token, 10).await?;
// after
if sql.trim().is_empty() { return Err(anyhow!("SQL is required")); }
driver.get_explain_info(sql, &token, 10).await?;
Defensive patterns

Strategy: validation

Validate before calling

anyhow::ensure!(!sql.trim().is_empty(), "SQL is required before EXPLAIN");

Type guard

fn has_sql(s: &str) -> bool { !s.trim().is_empty() }

Prevention

When it happens

Trigger: Calling get_explain_info with an empty string or a string containing only whitespace/newlines.

Common situations: A UI sends the explain request before the user typed a query, or an upstream variable holding the SQL was never populated.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/275dde1cc7d127ce. Report an issue: GitHub.