|
30 | 30 | #include "prepare_protocol.h" |
31 | 31 | #include "util.h" |
32 | 32 |
|
| 33 | +#include <stdbool.h> |
| 34 | + |
33 | 35 | #if SQLITE_VERSION_NUMBER >= 3014000 |
34 | 36 | #define HAVE_TRACE_V2 |
35 | 37 | #endif |
@@ -2343,6 +2345,119 @@ getlimit_impl(pysqlite_Connection *self, int category) |
2343 | 2345 | return setlimit_impl(self, category, -1); |
2344 | 2346 | } |
2345 | 2347 |
|
| 2348 | +static inline bool |
| 2349 | +is_int_config(const int op) |
| 2350 | +{ |
| 2351 | + switch (op) { |
| 2352 | + case SQLITE_DBCONFIG_ENABLE_FKEY: |
| 2353 | + case SQLITE_DBCONFIG_ENABLE_TRIGGER: |
| 2354 | +#if SQLITE_VERSION_NUMBER >= 3012002 |
| 2355 | + case SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER: |
| 2356 | +#endif |
| 2357 | +#if SQLITE_VERSION_NUMBER >= 3013000 |
| 2358 | + case SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION: |
| 2359 | +#endif |
| 2360 | +#if SQLITE_VERSION_NUMBER >= 3016000 |
| 2361 | + case SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE: |
| 2362 | +#endif |
| 2363 | +#if SQLITE_VERSION_NUMBER >= 3020000 |
| 2364 | + case SQLITE_DBCONFIG_ENABLE_QPSG: |
| 2365 | +#endif |
| 2366 | +#if SQLITE_VERSION_NUMBER >= 3022000 |
| 2367 | + case SQLITE_DBCONFIG_TRIGGER_EQP: |
| 2368 | +#endif |
| 2369 | +#if SQLITE_VERSION_NUMBER >= 3024000 |
| 2370 | + case SQLITE_DBCONFIG_RESET_DATABASE: |
| 2371 | +#endif |
| 2372 | +#if SQLITE_VERSION_NUMBER >= 3026000 |
| 2373 | + case SQLITE_DBCONFIG_DEFENSIVE: |
| 2374 | +#endif |
| 2375 | +#if SQLITE_VERSION_NUMBER >= 3028000 |
| 2376 | + case SQLITE_DBCONFIG_WRITABLE_SCHEMA: |
| 2377 | +#endif |
| 2378 | +#if SQLITE_VERSION_NUMBER >= 3029000 |
| 2379 | + case SQLITE_DBCONFIG_DQS_DDL: |
| 2380 | + case SQLITE_DBCONFIG_DQS_DML: |
| 2381 | + case SQLITE_DBCONFIG_LEGACY_ALTER_TABLE: |
| 2382 | +#endif |
| 2383 | +#if SQLITE_VERSION_NUMBER >= 3030000 |
| 2384 | + case SQLITE_DBCONFIG_ENABLE_VIEW: |
| 2385 | +#endif |
| 2386 | +#if SQLITE_VERSION_NUMBER >= 3031000 |
| 2387 | + case SQLITE_DBCONFIG_LEGACY_FILE_FORMAT: |
| 2388 | + case SQLITE_DBCONFIG_TRUSTED_SCHEMA: |
| 2389 | +#endif |
| 2390 | + return true; |
| 2391 | + default: |
| 2392 | + return false; |
| 2393 | + } |
| 2394 | +} |
| 2395 | + |
| 2396 | +/*[clinic input] |
| 2397 | +_sqlite3.Connection.setconfig as setconfig |
| 2398 | +
|
| 2399 | + op: int |
| 2400 | + The configuration verb; one of the sqlite3.SQLITE_DBCONFIG codes. |
| 2401 | + enable: bool = True |
| 2402 | + / |
| 2403 | +
|
| 2404 | +Set a boolean connection configuration option. |
| 2405 | +[clinic start generated code]*/ |
| 2406 | + |
| 2407 | +static PyObject * |
| 2408 | +setconfig_impl(pysqlite_Connection *self, int op, int enable) |
| 2409 | +/*[clinic end generated code: output=c60b13e618aff873 input=a10f1539c2d7da6b]*/ |
| 2410 | +{ |
| 2411 | + if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) { |
| 2412 | + return NULL; |
| 2413 | + } |
| 2414 | + if (!is_int_config(op)) { |
| 2415 | + return PyErr_Format(PyExc_ValueError, "unknown config 'op': %d", op); |
| 2416 | + } |
| 2417 | + |
| 2418 | + int actual; |
| 2419 | + int rc = sqlite3_db_config(self->db, op, enable, &actual); |
| 2420 | + if (rc != SQLITE_OK) { |
| 2421 | + (void)_pysqlite_seterror(self->state, self->db); |
| 2422 | + return NULL; |
| 2423 | + } |
| 2424 | + if (enable != actual) { |
| 2425 | + PyErr_SetString(self->state->OperationalError, "Unable to set config"); |
| 2426 | + return NULL; |
| 2427 | + } |
| 2428 | + Py_RETURN_NONE; |
| 2429 | +} |
| 2430 | + |
| 2431 | +/*[clinic input] |
| 2432 | +_sqlite3.Connection.getconfig as getconfig -> bool |
| 2433 | +
|
| 2434 | + op: int |
| 2435 | + The configuration verb; one of the sqlite3.SQLITE_DBCONFIG codes. |
| 2436 | + / |
| 2437 | +
|
| 2438 | +Query a boolean connection configuration option. |
| 2439 | +[clinic start generated code]*/ |
| 2440 | + |
| 2441 | +static int |
| 2442 | +getconfig_impl(pysqlite_Connection *self, int op) |
| 2443 | +/*[clinic end generated code: output=25ac05044c7b78a3 input=b0526d7e432e3f2f]*/ |
| 2444 | +{ |
| 2445 | + if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) { |
| 2446 | + return -1; |
| 2447 | + } |
| 2448 | + if (!is_int_config(op)) { |
| 2449 | + PyErr_Format(PyExc_ValueError, "unknown config 'op': %d", op); |
| 2450 | + return -1; |
| 2451 | + } |
| 2452 | + |
| 2453 | + int current; |
| 2454 | + int rc = sqlite3_db_config(self->db, op, -1, ¤t); |
| 2455 | + if (rc != SQLITE_OK) { |
| 2456 | + (void)_pysqlite_seterror(self->state, self->db); |
| 2457 | + return -1; |
| 2458 | + } |
| 2459 | + return current; |
| 2460 | +} |
2346 | 2461 |
|
2347 | 2462 | static PyObject * |
2348 | 2463 | get_autocommit(pysqlite_Connection *self, void *Py_UNUSED(ctx)) |
@@ -2424,6 +2539,8 @@ static PyMethodDef connection_methods[] = { |
2424 | 2539 | DESERIALIZE_METHODDEF |
2425 | 2540 | CREATE_WINDOW_FUNCTION_METHODDEF |
2426 | 2541 | BLOBOPEN_METHODDEF |
| 2542 | + SETCONFIG_METHODDEF |
| 2543 | + GETCONFIG_METHODDEF |
2427 | 2544 | {NULL, NULL} |
2428 | 2545 | }; |
2429 | 2546 |
|
|
0 commit comments