db工具加op=insert结构化批量插入:免手写SQL/数占位符(批量行是手写VALUES数?重灾区);列名对sqlite_master真实列白名单校验+quoteIdent转义,值全走?绑定过dbValue(boolean→0/1),单事务整体写,各行key必须一致否则点名报错(不静默补NULL掩盖笔误);update/delete不做结构化op(单行SQL本身简单且AND等值where表达力不够),exec保持全能力兜底;错误统一抛出交engine置is_error
This commit is contained in:
@@ -1,4 +1,40 @@
|
||||
[
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "db",
|
||||
"description": "Execute operations on the session's SQLite database (data.db in the session working directory). The database file is isolated per session and auto-created on first use. For inserting rows (especially batches), prefer op=insert which avoids writing SQL by hand; use exec/query for DDL, updates, deletes and complex SQL.\n\nop=exec 需要 sql(params 可选)。\nop=query 需要 sql(params 可选)。\nop=insert 需要 table 和 rows(行对象数组,单行也要包成数组)。\nop=tables 无参数。\nop=schema 需要 table。",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"required": ["op"],
|
||||
"properties": {
|
||||
"op": {
|
||||
"type": "string",
|
||||
"enum": ["exec", "query", "insert", "tables", "schema"],
|
||||
"description": "Operation type:\n- exec: run a write statement (CREATE / INSERT / UPDATE / DELETE / ALTER / DROP), in a transaction\n- query: run a read statement (SELECT), returns an array of rows\n- insert: insert one or more rows from row objects (structured, no SQL needed, one transaction)\n- tables: list all tables with row counts\n- schema: show column definitions for a table"
|
||||
},
|
||||
"sql": {
|
||||
"type": "string",
|
||||
"description": "A single SQL statement. Required when op is exec or query. Use ? placeholders for parameterized queries to avoid SQL injection; multiple statements are rejected."
|
||||
},
|
||||
"params": {
|
||||
"type": "array",
|
||||
"description": "Values bound to the ? placeholders in order. Used by op=exec/query only. Booleans are stored as 0/1.",
|
||||
"items": {}
|
||||
},
|
||||
"table": {
|
||||
"type": "string",
|
||||
"description": "Table name. Required for insert/schema."
|
||||
},
|
||||
"rows": {
|
||||
"type": "array",
|
||||
"description": "Array of row objects for op=insert. Each object maps column names to values; all objects must have the same keys.",
|
||||
"items": { "type": "object" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
|
||||
Reference in New Issue
Block a user