mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-133390: Support SQL keyword completion for sqlite3 CLI (GH-133393) (GH-135292)
Some checks are pending
Tests / Windows MSI (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
Some checks are pending
Tests / Windows MSI (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
Co-authored-by: Tan Long <tanloong@foxmail.com>
This commit is contained in:
parent
e6c3039cb3
commit
e7a3c20b92
7 changed files with 206 additions and 6 deletions
|
@ -32,6 +32,7 @@
|
|||
#include "microprotocols.h"
|
||||
#include "row.h"
|
||||
#include "blob.h"
|
||||
#include "util.h"
|
||||
|
||||
#if SQLITE_VERSION_NUMBER < 3015002
|
||||
#error "SQLite 3.15.2 or higher required"
|
||||
|
@ -404,6 +405,40 @@ pysqlite_error_name(int rc)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
add_keyword_tuple(PyObject *module)
|
||||
{
|
||||
#if SQLITE_VERSION_NUMBER >= 3024000
|
||||
int count = sqlite3_keyword_count();
|
||||
PyObject *keywords = PyTuple_New(count);
|
||||
if (keywords == NULL) {
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < count; i++) {
|
||||
const char *keyword;
|
||||
int size;
|
||||
int result = sqlite3_keyword_name(i, &keyword, &size);
|
||||
if (result != SQLITE_OK) {
|
||||
pysqlite_state *state = pysqlite_get_state(module);
|
||||
set_error_from_code(state, result);
|
||||
goto error;
|
||||
}
|
||||
PyObject *kwd = PyUnicode_FromStringAndSize(keyword, size);
|
||||
if (!kwd) {
|
||||
goto error;
|
||||
}
|
||||
PyTuple_SET_ITEM(keywords, i, kwd);
|
||||
}
|
||||
return PyModule_Add(module, "SQLITE_KEYWORDS", keywords);
|
||||
|
||||
error:
|
||||
Py_DECREF(keywords);
|
||||
return -1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
add_integer_constants(PyObject *module) {
|
||||
#define ADD_INT(ival) \
|
||||
|
@ -702,6 +737,10 @@ module_exec(PyObject *module)
|
|||
goto error;
|
||||
}
|
||||
|
||||
if (add_keyword_tuple(module) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (PyModule_AddStringConstant(module, "sqlite_version", sqlite3_libversion())) {
|
||||
goto error;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue