{"record":{"id":"b204f97924e08e5d","repo":"paperclipai/paperclip","slug":"ctx-db-execute-only-allows-insert-update-or-dele","errorCode":null,"errorMessage":"ctx.db.execute only allows INSERT, UPDATE, or DELETE","messagePattern":"ctx\\.db\\.execute only allows INSERT, UPDATE, or DELETE","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/src/services/plugin-database.ts","lineNumber":285,"sourceCode":"    if (ref.schema === namespace) continue;\n    if (ref.schema === \"public\") {\n      assertAllowedPublicRead(ref, allowedCoreReadTables);\n      continue;\n    }\n    throw new Error(`ctx.db.query cannot read schema \"${ref.schema}\"`);\n  }\n}\n\nexport function validatePluginRuntimeExecute(query: string, namespace: string): void {\n  const statements = splitSqlStatements(query);\n  if (statements.length !== 1) {\n    throw new Error(\"Plugin runtime SQL must contain exactly one statement\");\n  }\n  const statement = statements[0]!;\n  assertNoBannedSql(statement);\n  const normalized = normaliseSql(statement);\n  if (!/^(insert\\s+into|update|delete\\s+from)\\b/.test(normalized)) {\n    throw new Error(\"ctx.db.execute only allows INSERT, UPDATE, or DELETE\");\n  }\n  if (/\\b(alter|create|drop|truncate)\\b/.test(normalized)) {\n    throw new Error(\"ctx.db.execute cannot contain DDL keywords\");\n  }\n\n  const refs = extractQualifiedRefs(statement);\n  const target = refs.find((ref) => [\"into\", \"update\", \"from\"].includes(ref.keyword));\n  if (!target || target.schema !== namespace) {\n    throw new Error(`ctx.db.execute target must be inside plugin namespace \"${namespace}\"`);\n  }\n  for (const ref of refs) {\n    if (ref.schema !== namespace) {\n      throw new Error(\"ctx.db.execute cannot reference public or other non-plugin schemas\");\n    }\n  }\n}\n\nfunction bindSql(statement: string, params: readonly unknown[] = []): SQL {","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/paperclipai/paperclip/blob/120ae5428fa29bee300bcf806491cd4d965fbb7c/server/src/services/plugin-database.ts#L267-L303","documentation":"Mutation guard in validatePluginRuntimeExecute: the statement does not start with INSERT INTO, UPDATE, or DELETE FROM. ctx.db.execute is the plugin write API restricted to those three DML forms; the disallowed statement is at fault.","triggerScenarios":"Thrown at server/src/services/plugin-database.ts:285 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use ctx.db.query for SELECT; ctx.db.execute only allows INSERT, UPDATE, or DELETE."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"120ae5428fa29bee300bcf806491cd4d965fbb7c","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}