can1357/oh-my-pi · error · ToolError

SQLite query parameters require a table selector or q=SELECT

Error message

SQLite query parameters require a table selector or q=SELECT...

What it means

Thrown when query parameters are supplied but there is neither a table sub-path nor a q= raw query. Parameters like limit/where/order only make sense in table-select mode, so a bare path with params is ambiguous and rejected.

Source

Thrown at packages/coding-agent/src/tools/sqlite-reader.ts:579

export function parseSqliteSelector(subPath: string, queryString: string): SqliteSelector {
	const normalizedSubPath = subPath.replace(/^:+/, "").trim();
	const params = new URLSearchParams(queryString);
	const rawQuery = params.get("q");

	if (rawQuery !== null) {
		const otherKeys = [...params.keys()].filter(key => key !== "q");
		if (normalizedSubPath || otherKeys.length > 0) {
			throw new ToolError("SQLite raw queries cannot be combined with table selectors or pagination");
		}
		if (!rawQuery.trim()) {
			throw new ToolError("SQLite query parameter 'q' cannot be empty");
		}
		return { kind: "raw", sql: rawQuery };
	}

	if (!normalizedSubPath) {
		if (params.size > 0) {
			throw new ToolError("SQLite query parameters require a table selector or q=SELECT...");
		}
		return { kind: "list" };
	}

	const separatorIndex = normalizedSubPath.indexOf(":");
	const table = separatorIndex === -1 ? normalizedSubPath : normalizedSubPath.slice(0, separatorIndex);
	const key = separatorIndex === -1 ? undefined : normalizedSubPath.slice(separatorIndex + 1);
	if (!table) {
		throw new ToolError("SQLite selectors must include a table name");
	}

	if (key !== undefined && key.length > 0) {
		if (params.size > 0) {
			throw new ToolError("SQLite row lookups cannot be combined with query parameters");
		}
		return { kind: "row", table, key };
	}

View on GitHub (pinned to 9690622007)

Solutions

  1. Add the table name: 'db.sqlite/users?limit=5'
  2. Add a raw query: 'db.sqlite?q=SELECT ...'
  3. Remove the stray params if you intended a plain database listing

Example fix

// before
db.sqlite?limit=5
// after
db.sqlite/users?limit=5
Defensive patterns

Strategy: validation

Validate before calling

if (!table && !rawSql && Object.keys(params).length > 0) {
  throw new Error('query params require a table path or q=...');
}

Try / catch

try {
  await reader.read(url);
} catch (err) {
  if (err instanceof ToolError && err.message.includes('require a table selector')) {
    // fix URL construction: ensure the table segment is present
  } else throw err;
}

Prevention

When it happens

Trigger: 'db.sqlite?limit=5' with no table; a URL where the table segment was dropped but params kept; sub-path consisting only of ':' leaving an empty table.

Common situations: Constructing URLs from parts where the table variable is empty; renaming endpoints and forgetting the table segment; copy-paste that lost the '/table' portion.

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 can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/36ef94c7365b2eb2. Report an issue: GitHub.