MCPcopy Create free account
hub / github.com/ElementsProject/lightning / db_sqlite3_query

Function db_sqlite3_query

db/db_sqlite3.c:225–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

223}
224
225static bool db_sqlite3_query(struct db_stmt *stmt)
226{
227 sqlite3_stmt *s;
228 sqlite3 *conn = conn2sql(stmt->db->conn);
229 int err;
230 const char *query = stmt->query->query;
231 char *modified_query = NULL;
232
233 if (stmt->db->developer &&
234 !stmt->db->in_migration &&
235 strncasecmp(query, "CREATE TABLE", 12) == 0 &&
236 !strstr(query, "STRICT")) {
237 modified_query = tal_fmt(stmt, "%s STRICT", query);
238 query = modified_query;
239 }
240
241 err = sqlite3_prepare_v2(conn, query, -1, &s, NULL);
242
243 tal_free(modified_query);
244
245 for (size_t i=0; i<stmt->query->placeholders; i++) {
246 struct db_binding *b = &stmt->bindings[i];
247
248 /* sqlite3 uses printf-like offsets, we don't... */
249 int pos = i+1;
250 switch (b->type) {
251 case DB_BINDING_UNINITIALIZED:
252 db_fatal(stmt->db, "DB binding not initialized: position=%zu, "
253 "query=\"%s\n",
254 i, stmt->query->query);
255 case DB_BINDING_UINT64:
256 sqlite3_bind_int64(s, pos, b->v.u64);
257 break;
258 case DB_BINDING_INT:
259 sqlite3_bind_int(s, pos, b->v.i);
260 break;
261 case DB_BINDING_BLOB:
262 sqlite3_bind_blob(s, pos, b->v.blob, b->len,
263 SQLITE_TRANSIENT);
264 break;
265 case DB_BINDING_TEXT:
266 sqlite3_bind_text(s, pos, b->v.text, b->len,
267 SQLITE_TRANSIENT);
268 break;
269 case DB_BINDING_NULL:
270 sqlite3_bind_null(s, pos);
271 break;
272 }
273 }
274
275 if (err != SQLITE_OK) {
276 tal_free(stmt->error);
277 stmt->error = db_sqlite3_fmt_error(stmt);
278 return false;
279 }
280
281 stmt->inner_stmt = s;
282 return true;

Callers 1

db_sqlite3_execFunction · 0.85

Calls 4

conn2sqlFunction · 0.85
tal_freeFunction · 0.85
db_fatalFunction · 0.85
db_sqlite3_fmt_errorFunction · 0.85

Tested by

no test coverage detected