2006-04-21 07:40:58 -03:00
|
|
|
/* statement.c - the statement type
|
|
|
|
*
|
2010-09-03 20:47:32 -03:00
|
|
|
* Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>
|
2006-04-21 07:40:58 -03:00
|
|
|
*
|
|
|
|
* This file is part of pysqlite.
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty. In no event will the authors be held liable for any damages
|
|
|
|
* arising from the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any purpose,
|
|
|
|
* including commercial applications, and to alter it and redistribute it
|
|
|
|
* freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
* claim that you wrote the original software. If you use this software
|
|
|
|
* in a product, an acknowledgment in the product documentation would be
|
|
|
|
* appreciated but is not required.
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
* misrepresented as being the original software.
|
|
|
|
* 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "statement.h"
|
|
|
|
#include "cursor.h"
|
|
|
|
#include "connection.h"
|
|
|
|
#include "microprotocols.h"
|
|
|
|
#include "prepare_protocol.h"
|
2013-02-07 11:01:47 -04:00
|
|
|
#include "util.h"
|
2006-04-21 07:40:58 -03:00
|
|
|
|
|
|
|
/* prototypes */
|
Merged revisions 53304-53433,53435-53450 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r53304 | vinay.sajip | 2007-01-09 15:50:28 +0100 (Tue, 09 Jan 2007) | 1 line
Bug #1627575: Added _open() method to FileHandler which can be used to reopen files. The FileHandler instance now saves the encoding (which can be None) in an attribute called "encoding".
........
r53305 | vinay.sajip | 2007-01-09 15:51:36 +0100 (Tue, 09 Jan 2007) | 1 line
Added entry about addition of _open() method to logging.FileHandler.
........
r53306 | vinay.sajip | 2007-01-09 15:54:56 +0100 (Tue, 09 Jan 2007) | 1 line
Added a docstring
........
r53316 | thomas.heller | 2007-01-09 20:19:33 +0100 (Tue, 09 Jan 2007) | 4 lines
Verify the sizes of the basic ctypes data types against the struct
module.
Will backport to release25-maint.
........
r53340 | gustavo.niemeyer | 2007-01-10 17:13:40 +0100 (Wed, 10 Jan 2007) | 3 lines
Mention in the int() docstring that a base zero has meaning, as
stated in http://docs.python.org/lib/built-in-funcs.html as well.
........
r53341 | gustavo.niemeyer | 2007-01-10 17:15:48 +0100 (Wed, 10 Jan 2007) | 2 lines
Minor change in int() docstring for proper spacing.
........
r53358 | thomas.heller | 2007-01-10 21:12:13 +0100 (Wed, 10 Jan 2007) | 1 line
Change the ctypes version number to "1.1.0".
........
r53361 | thomas.heller | 2007-01-10 21:51:19 +0100 (Wed, 10 Jan 2007) | 1 line
Must change the version number in the _ctypes extension as well.
........
r53362 | guido.van.rossum | 2007-01-11 00:12:56 +0100 (Thu, 11 Jan 2007) | 3 lines
Fix the signature of log_error(). (A subclass that did the right thing
was getting complaints from pychecker.)
........
r53370 | matthias.klose | 2007-01-11 11:26:31 +0100 (Thu, 11 Jan 2007) | 2 lines
- Make the documentation match the code and the docstring
........
r53375 | matthias.klose | 2007-01-11 12:44:04 +0100 (Thu, 11 Jan 2007) | 2 lines
- idle: Honor the "Cancel" action in the save dialog (Debian bug #299092).
........
r53381 | raymond.hettinger | 2007-01-11 19:22:55 +0100 (Thu, 11 Jan 2007) | 1 line
SF #1486663 -- Allow keyword args in subclasses of set() and frozenset().
........
r53388 | thomas.heller | 2007-01-11 22:18:56 +0100 (Thu, 11 Jan 2007) | 4 lines
Fixes for 64-bit Windows: In ctypes.wintypes, correct the definitions
of HANDLE, WPARAM, LPARAM data types. Make parameterless foreign
function calls work.
........
r53390 | thomas.heller | 2007-01-11 22:23:12 +0100 (Thu, 11 Jan 2007) | 2 lines
Correct the comments: the code is right.
........
r53393 | brett.cannon | 2007-01-12 08:27:52 +0100 (Fri, 12 Jan 2007) | 3 lines
Fix error where the end of a funcdesc environment was accidentally moved too
far down.
........
r53397 | anthony.baxter | 2007-01-12 10:35:56 +0100 (Fri, 12 Jan 2007) | 3 lines
add parsetok.h as a dependency - previously, changing this file doesn't
cause the right files to be rebuilt.
........
r53401 | thomas.heller | 2007-01-12 21:08:19 +0100 (Fri, 12 Jan 2007) | 3 lines
Avoid warnings in the test suite because ctypes.wintypes cannot be
imported on non-windows systems.
........
r53402 | thomas.heller | 2007-01-12 21:17:34 +0100 (Fri, 12 Jan 2007) | 6 lines
patch #1610795: BSD version of ctypes.util.find_library, by Martin
Kammerhofer.
release25-maint backport candidate, but the release manager has to
decide.
........
r53403 | thomas.heller | 2007-01-12 21:21:53 +0100 (Fri, 12 Jan 2007) | 3 lines
patch #1610795: BSD version of ctypes.util.find_library, by Martin
Kammerhofer.
........
r53406 | brett.cannon | 2007-01-13 01:29:49 +0100 (Sat, 13 Jan 2007) | 2 lines
Deprecate the sets module.
........
r53407 | georg.brandl | 2007-01-13 13:31:51 +0100 (Sat, 13 Jan 2007) | 3 lines
Fix typo.
........
r53409 | marc-andre.lemburg | 2007-01-13 22:00:08 +0100 (Sat, 13 Jan 2007) | 16 lines
Bump version number and change copyright year.
Add new API linux_distribution() which supports reading the full distribution
name and also knows how to parse LSB-style release files.
Redirect the old dist() API to the new API (using the short distribution name
taken from the release file filename).
Add branch and revision to _sys_version().
Add work-around for Cygwin to libc_ver().
Add support for IronPython (thanks for Anthony Baxter) and make
Jython support more robust.
........
r53410 | neal.norwitz | 2007-01-13 22:22:37 +0100 (Sat, 13 Jan 2007) | 1 line
Fix grammar in docstrings
........
r53411 | marc-andre.lemburg | 2007-01-13 23:32:21 +0100 (Sat, 13 Jan 2007) | 9 lines
Add parameter sys_version to _sys_version().
Change the cache for _sys_version() to take the parameter into account.
Add support for parsing the IronPython 1.0.1 sys.version value - even
though it still returns '1.0.0'; the version string no longer includes
the patch level.
........
r53412 | peter.astrand | 2007-01-13 23:35:35 +0100 (Sat, 13 Jan 2007) | 1 line
Fix for bug #1634343: allow specifying empty arguments on Windows
........
r53414 | marc-andre.lemburg | 2007-01-13 23:59:36 +0100 (Sat, 13 Jan 2007) | 14 lines
Add Python implementation to the machine details.
Pretty-print the Python version used for running PyBench.
Let the user know when calibration has finished.
[ 1563844 ] pybench support for IronPython:
Simplify Unicode version detection.
Make garbage collection and check interval settings optional if
the Python implementation doesn't support thess (e.g. IronPython).
........
r53415 | marc-andre.lemburg | 2007-01-14 00:13:54 +0100 (Sun, 14 Jan 2007) | 5 lines
Use defaults if sys.executable isn't set (e.g. on Jython).
This change allows running PyBench under Jython.
........
r53416 | marc-andre.lemburg | 2007-01-14 00:15:33 +0100 (Sun, 14 Jan 2007) | 3 lines
Jython doesn't have sys.setcheckinterval() - ignore it in that case.
........
r53420 | gerhard.haering | 2007-01-14 02:43:50 +0100 (Sun, 14 Jan 2007) | 29 lines
Merged changes from standalone version 2.3.3. This should probably all be
merged into the 2.5 maintenance branch:
- self->statement was not checked while fetching data, which could
lead to crashes if you used the pysqlite API in unusual ways.
Closing the cursor and continuing to fetch data was enough.
- Converters are stored in a converters dictionary. The converter name
is uppercased first. The old upper-casing algorithm was wrong and
was replaced by a simple call to the Python string's upper() method
instead.
-Applied patch by Glyph Lefkowitz that fixes the problem with
subsequent SQLITE_SCHEMA errors.
- Improvement to the row type: rows can now be iterated over and have a keys()
method. This improves compatibility with both tuple and dict a lot.
- A bugfix for the subsecond resolution in timestamps.
- Corrected the way the flags PARSE_DECLTYPES and PARSE_COLNAMES are
checked for. Now they work as documented.
- gcc on Linux sucks. It exports all symbols by default in shared
libraries, so if symbols are not unique it can lead to problems with
symbol lookup. pysqlite used to crash under Apache when mod_cache
was enabled because both modules had the symbol cache_init. I fixed
this by applying the prefix pysqlite_ almost everywhere. Sigh.
........
r53423 | guido.van.rossum | 2007-01-14 04:46:33 +0100 (Sun, 14 Jan 2007) | 2 lines
Remove a dependency of this test on $COLUMNS.
........
r53425 | ka-ping.yee | 2007-01-14 05:25:15 +0100 (Sun, 14 Jan 2007) | 3 lines
Handle old-style instances more gracefully (display documentation on
the relevant class instead of documentation on <type 'instance'>).
........
r53440 | vinay.sajip | 2007-01-14 22:49:59 +0100 (Sun, 14 Jan 2007) | 1 line
Added WatchedFileHandler (based on SF patch #1598415)
........
r53441 | vinay.sajip | 2007-01-14 22:50:50 +0100 (Sun, 14 Jan 2007) | 1 line
Added documentation for WatchedFileHandler (based on SF patch #1598415)
........
r53442 | guido.van.rossum | 2007-01-15 01:02:35 +0100 (Mon, 15 Jan 2007) | 2 lines
Doc patch matching r53434 (htonl etc. now always take/return positive ints).
........
2007-01-15 11:49:28 -04:00
|
|
|
static int pysqlite_check_remaining_sql(const char* tail);
|
2006-04-21 07:40:58 -03:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
LINECOMMENT_1,
|
|
|
|
IN_LINECOMMENT,
|
|
|
|
COMMENTSTART_1,
|
|
|
|
IN_COMMENT,
|
|
|
|
COMMENTEND_1,
|
|
|
|
NORMAL
|
|
|
|
} parse_remaining_sql_state;
|
|
|
|
|
2008-03-28 21:45:29 -03:00
|
|
|
typedef enum {
|
|
|
|
TYPE_LONG,
|
|
|
|
TYPE_FLOAT,
|
|
|
|
TYPE_UNICODE,
|
|
|
|
TYPE_BUFFER,
|
|
|
|
TYPE_UNKNOWN
|
|
|
|
} parameter_type;
|
|
|
|
|
2021-06-01 07:47:37 -03:00
|
|
|
pysqlite_Statement *
|
|
|
|
pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql)
|
2006-04-21 07:40:58 -03:00
|
|
|
{
|
2021-07-29 06:21:45 -03:00
|
|
|
pysqlite_state *state = connection->state;
|
2019-06-25 22:16:24 -03:00
|
|
|
assert(PyUnicode_Check(sql));
|
2021-06-08 12:00:56 -03:00
|
|
|
Py_ssize_t size;
|
|
|
|
const char *sql_cstr = PyUnicode_AsUTF8AndSize(sql, &size);
|
2007-08-29 00:34:29 -03:00
|
|
|
if (sql_cstr == NULL) {
|
2021-06-01 07:47:37 -03:00
|
|
|
return NULL;
|
2006-04-21 07:40:58 -03:00
|
|
|
}
|
2021-06-02 09:26:06 -03:00
|
|
|
|
2021-06-08 12:00:56 -03:00
|
|
|
sqlite3 *db = connection->db;
|
2021-11-10 14:46:11 -04:00
|
|
|
int max_length = sqlite3_limit(db, SQLITE_LIMIT_SQL_LENGTH, -1);
|
|
|
|
if (size > max_length) {
|
2021-07-14 08:26:44 -03:00
|
|
|
PyErr_SetString(connection->DataError,
|
|
|
|
"query string is too large");
|
2021-06-02 10:22:15 -03:00
|
|
|
return NULL;
|
2021-06-02 09:26:06 -03:00
|
|
|
}
|
2021-06-08 12:00:56 -03:00
|
|
|
if (strlen(sql_cstr) != (size_t)size) {
|
2021-06-01 07:47:37 -03:00
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"the query contains a null character");
|
|
|
|
return NULL;
|
2014-09-11 07:29:05 -03:00
|
|
|
}
|
2006-04-21 07:40:58 -03:00
|
|
|
|
2021-06-08 12:00:56 -03:00
|
|
|
sqlite3_stmt *stmt;
|
|
|
|
const char *tail;
|
|
|
|
int rc;
|
|
|
|
Py_BEGIN_ALLOW_THREADS
|
|
|
|
rc = sqlite3_prepare_v2(db, sql_cstr, (int)size + 1, &stmt, &tail);
|
|
|
|
Py_END_ALLOW_THREADS
|
|
|
|
|
|
|
|
if (rc != SQLITE_OK) {
|
2021-07-29 06:21:45 -03:00
|
|
|
_pysqlite_seterror(state, db);
|
2021-06-01 07:47:37 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-06-08 12:00:56 -03:00
|
|
|
if (pysqlite_check_remaining_sql(tail)) {
|
2021-07-14 08:26:44 -03:00
|
|
|
PyErr_SetString(connection->Warning,
|
|
|
|
"You can only execute one statement at a time.");
|
2021-06-08 12:00:56 -03:00
|
|
|
goto error;
|
|
|
|
}
|
2006-04-21 07:40:58 -03:00
|
|
|
|
2017-02-26 11:22:38 -04:00
|
|
|
/* Determine if the statement is a DML statement.
|
|
|
|
SELECT is the only exception. See #9924. */
|
2021-06-08 12:00:56 -03:00
|
|
|
int is_dml = 0;
|
|
|
|
for (const char *p = sql_cstr; *p != 0; p++) {
|
2016-09-11 06:57:15 -03:00
|
|
|
switch (*p) {
|
|
|
|
case ' ':
|
|
|
|
case '\r':
|
|
|
|
case '\n':
|
|
|
|
case '\t':
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-06-08 12:00:56 -03:00
|
|
|
is_dml = (PyOS_strnicmp(p, "insert", 6) == 0)
|
|
|
|
|| (PyOS_strnicmp(p, "update", 6) == 0)
|
|
|
|
|| (PyOS_strnicmp(p, "delete", 6) == 0)
|
|
|
|
|| (PyOS_strnicmp(p, "replace", 7) == 0);
|
2016-09-11 06:57:15 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-06-08 12:00:56 -03:00
|
|
|
pysqlite_Statement *self = PyObject_GC_New(pysqlite_Statement,
|
2021-06-15 09:47:34 -03:00
|
|
|
state->StatementType);
|
2021-06-08 12:00:56 -03:00
|
|
|
if (self == NULL) {
|
2021-06-01 07:47:37 -03:00
|
|
|
goto error;
|
|
|
|
}
|
2006-04-21 07:40:58 -03:00
|
|
|
|
2021-06-08 12:00:56 -03:00
|
|
|
self->st = stmt;
|
|
|
|
self->in_use = 0;
|
|
|
|
self->is_dml = is_dml;
|
2006-04-21 07:40:58 -03:00
|
|
|
|
2021-06-08 12:00:56 -03:00
|
|
|
PyObject_GC_Track(self);
|
2021-06-01 07:47:37 -03:00
|
|
|
return self;
|
|
|
|
|
|
|
|
error:
|
2021-06-08 12:00:56 -03:00
|
|
|
(void)sqlite3_finalize(stmt);
|
2021-06-01 07:47:37 -03:00
|
|
|
return NULL;
|
2006-04-21 07:40:58 -03:00
|
|
|
}
|
|
|
|
|
2012-02-09 15:09:03 -04:00
|
|
|
int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter)
|
2006-04-21 07:40:58 -03:00
|
|
|
{
|
|
|
|
int rc = SQLITE_OK;
|
2016-11-20 04:16:47 -04:00
|
|
|
const char *string;
|
2006-04-21 07:40:58 -03:00
|
|
|
Py_ssize_t buflen;
|
2008-03-28 21:45:29 -03:00
|
|
|
parameter_type paramtype;
|
2006-04-21 07:40:58 -03:00
|
|
|
|
|
|
|
if (parameter == Py_None) {
|
|
|
|
rc = sqlite3_bind_null(self->st, pos);
|
2008-03-28 21:45:29 -03:00
|
|
|
goto final;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PyLong_CheckExact(parameter)) {
|
|
|
|
paramtype = TYPE_LONG;
|
|
|
|
} else if (PyFloat_CheckExact(parameter)) {
|
|
|
|
paramtype = TYPE_FLOAT;
|
|
|
|
} else if (PyUnicode_CheckExact(parameter)) {
|
|
|
|
paramtype = TYPE_UNICODE;
|
2007-10-23 16:24:22 -03:00
|
|
|
} else if (PyLong_Check(parameter)) {
|
2008-03-28 21:45:29 -03:00
|
|
|
paramtype = TYPE_LONG;
|
2006-04-21 07:40:58 -03:00
|
|
|
} else if (PyFloat_Check(parameter)) {
|
2008-03-28 21:45:29 -03:00
|
|
|
paramtype = TYPE_FLOAT;
|
|
|
|
} else if (PyUnicode_Check(parameter)) {
|
2008-09-22 03:04:51 -03:00
|
|
|
paramtype = TYPE_UNICODE;
|
2007-10-07 23:46:15 -03:00
|
|
|
} else if (PyObject_CheckBuffer(parameter)) {
|
2008-03-28 21:45:29 -03:00
|
|
|
paramtype = TYPE_BUFFER;
|
2006-04-21 07:40:58 -03:00
|
|
|
} else {
|
2008-03-28 21:45:29 -03:00
|
|
|
paramtype = TYPE_UNKNOWN;
|
2006-04-21 07:40:58 -03:00
|
|
|
}
|
|
|
|
|
2008-03-28 21:45:29 -03:00
|
|
|
switch (paramtype) {
|
2013-02-07 11:01:47 -04:00
|
|
|
case TYPE_LONG: {
|
|
|
|
sqlite_int64 value = _pysqlite_long_as_int64(parameter);
|
|
|
|
if (value == -1 && PyErr_Occurred())
|
|
|
|
rc = -1;
|
|
|
|
else
|
|
|
|
rc = sqlite3_bind_int64(self->st, pos, value);
|
2008-03-28 21:45:29 -03:00
|
|
|
break;
|
2013-02-07 11:01:47 -04:00
|
|
|
}
|
2008-03-28 21:45:29 -03:00
|
|
|
case TYPE_FLOAT:
|
|
|
|
rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
|
|
|
|
break;
|
|
|
|
case TYPE_UNICODE:
|
2016-11-20 03:13:07 -04:00
|
|
|
string = PyUnicode_AsUTF8AndSize(parameter, &buflen);
|
2013-11-17 20:36:29 -04:00
|
|
|
if (string == NULL)
|
|
|
|
return -1;
|
|
|
|
if (buflen > INT_MAX) {
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
"string longer than INT_MAX bytes");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
rc = sqlite3_bind_text(self->st, pos, string, (int)buflen, SQLITE_TRANSIENT);
|
2008-03-28 21:45:29 -03:00
|
|
|
break;
|
2015-02-02 19:21:08 -04:00
|
|
|
case TYPE_BUFFER: {
|
|
|
|
Py_buffer view;
|
|
|
|
if (PyObject_GetBuffer(parameter, &view, PyBUF_SIMPLE) != 0) {
|
2008-03-28 21:45:29 -03:00
|
|
|
PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer");
|
2013-11-17 20:36:29 -04:00
|
|
|
return -1;
|
|
|
|
}
|
2015-02-02 19:21:08 -04:00
|
|
|
if (view.len > INT_MAX) {
|
2013-11-17 20:36:29 -04:00
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
"BLOB longer than INT_MAX bytes");
|
2015-02-02 19:21:08 -04:00
|
|
|
PyBuffer_Release(&view);
|
2013-11-17 20:36:29 -04:00
|
|
|
return -1;
|
2008-03-28 21:45:29 -03:00
|
|
|
}
|
2015-02-02 19:21:08 -04:00
|
|
|
rc = sqlite3_bind_blob(self->st, pos, view.buf, (int)view.len, SQLITE_TRANSIENT);
|
|
|
|
PyBuffer_Release(&view);
|
2008-03-28 21:45:29 -03:00
|
|
|
break;
|
2015-02-02 19:21:08 -04:00
|
|
|
}
|
2008-03-28 21:45:29 -03:00
|
|
|
case TYPE_UNKNOWN:
|
|
|
|
rc = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
final:
|
2006-04-21 07:40:58 -03:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-03-28 21:45:29 -03:00
|
|
|
/* returns 0 if the object is one of Python's internal ones that don't need to be adapted */
|
2021-07-29 06:21:45 -03:00
|
|
|
static int
|
|
|
|
_need_adapt(pysqlite_state *state, PyObject *obj)
|
2008-03-28 21:45:29 -03:00
|
|
|
{
|
2021-07-20 07:59:18 -03:00
|
|
|
if (state->BaseTypeAdapted) {
|
2008-03-28 21:45:29 -03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PyLong_CheckExact(obj) || PyFloat_CheckExact(obj)
|
2008-05-26 10:22:05 -03:00
|
|
|
|| PyUnicode_CheckExact(obj) || PyByteArray_CheckExact(obj)) {
|
2008-03-28 21:45:29 -03:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-29 06:21:45 -03:00
|
|
|
void
|
|
|
|
pysqlite_statement_bind_parameters(pysqlite_state *state,
|
|
|
|
pysqlite_Statement *self,
|
|
|
|
PyObject *parameters)
|
2006-04-21 07:40:58 -03:00
|
|
|
{
|
|
|
|
PyObject* current_param;
|
|
|
|
PyObject* adapted;
|
|
|
|
const char* binding_name;
|
|
|
|
int i;
|
|
|
|
int rc;
|
|
|
|
int num_params_needed;
|
2013-11-17 21:07:29 -04:00
|
|
|
Py_ssize_t num_params;
|
2006-04-21 07:40:58 -03:00
|
|
|
|
|
|
|
Py_BEGIN_ALLOW_THREADS
|
|
|
|
num_params_needed = sqlite3_bind_parameter_count(self->st);
|
|
|
|
Py_END_ALLOW_THREADS
|
|
|
|
|
2008-03-28 21:45:29 -03:00
|
|
|
if (PyTuple_CheckExact(parameters) || PyList_CheckExact(parameters) || (!PyDict_Check(parameters) && PySequence_Check(parameters))) {
|
|
|
|
/* parameters passed as sequence */
|
|
|
|
if (PyTuple_CheckExact(parameters)) {
|
|
|
|
num_params = PyTuple_GET_SIZE(parameters);
|
|
|
|
} else if (PyList_CheckExact(parameters)) {
|
|
|
|
num_params = PyList_GET_SIZE(parameters);
|
|
|
|
} else {
|
|
|
|
num_params = PySequence_Size(parameters);
|
2020-09-17 04:35:44 -03:00
|
|
|
if (num_params == -1) {
|
|
|
|
return;
|
|
|
|
}
|
2008-03-28 21:45:29 -03:00
|
|
|
}
|
|
|
|
if (num_params != num_params_needed) {
|
2021-07-14 08:26:44 -03:00
|
|
|
PyErr_Format(state->ProgrammingError,
|
2013-11-17 21:07:29 -04:00
|
|
|
"Incorrect number of bindings supplied. The current "
|
|
|
|
"statement uses %d, and there are %zd supplied.",
|
2008-03-28 21:45:29 -03:00
|
|
|
num_params_needed, num_params);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 0; i < num_params; i++) {
|
|
|
|
if (PyTuple_CheckExact(parameters)) {
|
2020-12-27 07:05:33 -04:00
|
|
|
PyObject *item = PyTuple_GET_ITEM(parameters, i);
|
|
|
|
current_param = Py_NewRef(item);
|
2008-03-28 21:45:29 -03:00
|
|
|
} else if (PyList_CheckExact(parameters)) {
|
2020-12-27 07:05:33 -04:00
|
|
|
PyObject *item = PyList_GetItem(parameters, i);
|
|
|
|
current_param = Py_XNewRef(item);
|
2008-03-28 21:45:29 -03:00
|
|
|
} else {
|
|
|
|
current_param = PySequence_GetItem(parameters, i);
|
|
|
|
}
|
|
|
|
if (!current_param) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-29 06:21:45 -03:00
|
|
|
if (!_need_adapt(state, current_param)) {
|
2008-03-28 21:45:29 -03:00
|
|
|
adapted = current_param;
|
|
|
|
} else {
|
2021-06-15 09:47:34 -03:00
|
|
|
PyObject *protocol = (PyObject *)state->PrepareProtocolType;
|
2021-07-29 06:21:45 -03:00
|
|
|
adapted = pysqlite_microprotocols_adapt(state, current_param,
|
2021-06-15 09:47:34 -03:00
|
|
|
protocol,
|
|
|
|
current_param);
|
2018-12-10 10:06:08 -04:00
|
|
|
Py_DECREF(current_param);
|
|
|
|
if (!adapted) {
|
|
|
|
return;
|
2008-03-28 21:45:29 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-09 15:09:03 -04:00
|
|
|
rc = pysqlite_statement_bind_parameter(self, i + 1, adapted);
|
2008-03-28 21:45:29 -03:00
|
|
|
Py_DECREF(adapted);
|
|
|
|
|
|
|
|
if (rc != SQLITE_OK) {
|
|
|
|
if (!PyErr_Occurred()) {
|
2021-06-23 09:56:40 -03:00
|
|
|
PyErr_Format(state->InterfaceError,
|
|
|
|
"Error binding parameter %d - "
|
|
|
|
"probably unsupported type.", i);
|
2008-03-28 21:45:29 -03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (PyDict_Check(parameters)) {
|
2006-04-21 07:40:58 -03:00
|
|
|
/* parameters passed as dictionary */
|
|
|
|
for (i = 1; i <= num_params_needed; i++) {
|
2018-12-10 10:06:08 -04:00
|
|
|
PyObject *binding_name_obj;
|
2006-04-21 07:40:58 -03:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
|
|
|
binding_name = sqlite3_bind_parameter_name(self->st, i);
|
|
|
|
Py_END_ALLOW_THREADS
|
|
|
|
if (!binding_name) {
|
2021-07-14 08:26:44 -03:00
|
|
|
PyErr_Format(state->ProgrammingError,
|
|
|
|
"Binding %d has no name, but you supplied a "
|
|
|
|
"dictionary (which has only names).", i);
|
2006-04-21 07:40:58 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
binding_name++; /* skip first char (the colon) */
|
2018-12-10 10:06:08 -04:00
|
|
|
binding_name_obj = PyUnicode_FromString(binding_name);
|
|
|
|
if (!binding_name_obj) {
|
|
|
|
return;
|
|
|
|
}
|
2008-03-28 21:45:29 -03:00
|
|
|
if (PyDict_CheckExact(parameters)) {
|
2020-12-27 07:05:33 -04:00
|
|
|
PyObject *item = PyDict_GetItemWithError(parameters, binding_name_obj);
|
|
|
|
current_param = Py_XNewRef(item);
|
2008-03-28 21:45:29 -03:00
|
|
|
} else {
|
2018-12-10 10:06:08 -04:00
|
|
|
current_param = PyObject_GetItem(parameters, binding_name_obj);
|
2008-03-28 21:45:29 -03:00
|
|
|
}
|
2018-12-10 10:06:08 -04:00
|
|
|
Py_DECREF(binding_name_obj);
|
2006-04-21 07:40:58 -03:00
|
|
|
if (!current_param) {
|
2018-12-10 10:06:08 -04:00
|
|
|
if (!PyErr_Occurred() || PyErr_ExceptionMatches(PyExc_LookupError)) {
|
2021-07-14 08:26:44 -03:00
|
|
|
PyErr_Format(state->ProgrammingError,
|
|
|
|
"You did not supply a value for binding "
|
|
|
|
"parameter :%s.", binding_name);
|
2018-12-10 10:06:08 -04:00
|
|
|
}
|
2006-04-21 07:40:58 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-29 06:21:45 -03:00
|
|
|
if (!_need_adapt(state, current_param)) {
|
2006-04-21 07:40:58 -03:00
|
|
|
adapted = current_param;
|
2008-03-28 21:45:29 -03:00
|
|
|
} else {
|
2021-06-15 09:47:34 -03:00
|
|
|
PyObject *protocol = (PyObject *)state->PrepareProtocolType;
|
2021-07-29 06:21:45 -03:00
|
|
|
adapted = pysqlite_microprotocols_adapt(state, current_param,
|
2021-06-15 09:47:34 -03:00
|
|
|
protocol,
|
|
|
|
current_param);
|
2018-12-10 10:06:08 -04:00
|
|
|
Py_DECREF(current_param);
|
|
|
|
if (!adapted) {
|
|
|
|
return;
|
2008-03-28 21:45:29 -03:00
|
|
|
}
|
2006-04-21 07:40:58 -03:00
|
|
|
}
|
|
|
|
|
2012-02-09 15:09:03 -04:00
|
|
|
rc = pysqlite_statement_bind_parameter(self, i, adapted);
|
2006-04-21 07:40:58 -03:00
|
|
|
Py_DECREF(adapted);
|
|
|
|
|
|
|
|
if (rc != SQLITE_OK) {
|
2008-03-28 21:45:29 -03:00
|
|
|
if (!PyErr_Occurred()) {
|
2021-06-23 09:56:40 -03:00
|
|
|
PyErr_Format(state->InterfaceError,
|
|
|
|
"Error binding parameter :%s - "
|
|
|
|
"probably unsupported type.", binding_name);
|
2008-03-28 21:45:29 -03:00
|
|
|
}
|
2006-04-21 07:40:58 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2008-03-28 21:45:29 -03:00
|
|
|
PyErr_SetString(PyExc_ValueError, "parameters are of unsupported type");
|
2006-04-21 07:40:58 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-26 18:24:19 -03:00
|
|
|
int pysqlite_statement_reset(pysqlite_Statement* self)
|
2006-04-21 07:40:58 -03:00
|
|
|
{
|
2021-09-26 18:24:19 -03:00
|
|
|
int rc;
|
2006-04-21 07:40:58 -03:00
|
|
|
|
2021-09-26 18:24:19 -03:00
|
|
|
rc = SQLITE_OK;
|
2006-04-21 07:40:58 -03:00
|
|
|
|
2021-09-26 18:24:19 -03:00
|
|
|
if (self->in_use && self->st) {
|
|
|
|
Py_BEGIN_ALLOW_THREADS
|
|
|
|
rc = sqlite3_reset(self->st);
|
|
|
|
Py_END_ALLOW_THREADS
|
2006-04-21 07:40:58 -03:00
|
|
|
|
2021-09-26 18:24:19 -03:00
|
|
|
if (rc == SQLITE_OK) {
|
|
|
|
self->in_use = 0;
|
|
|
|
}
|
2006-04-21 07:40:58 -03:00
|
|
|
}
|
2021-09-26 18:24:19 -03:00
|
|
|
|
|
|
|
return rc;
|
2006-04-21 07:40:58 -03:00
|
|
|
}
|
|
|
|
|
Merged revisions 53304-53433,53435-53450 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r53304 | vinay.sajip | 2007-01-09 15:50:28 +0100 (Tue, 09 Jan 2007) | 1 line
Bug #1627575: Added _open() method to FileHandler which can be used to reopen files. The FileHandler instance now saves the encoding (which can be None) in an attribute called "encoding".
........
r53305 | vinay.sajip | 2007-01-09 15:51:36 +0100 (Tue, 09 Jan 2007) | 1 line
Added entry about addition of _open() method to logging.FileHandler.
........
r53306 | vinay.sajip | 2007-01-09 15:54:56 +0100 (Tue, 09 Jan 2007) | 1 line
Added a docstring
........
r53316 | thomas.heller | 2007-01-09 20:19:33 +0100 (Tue, 09 Jan 2007) | 4 lines
Verify the sizes of the basic ctypes data types against the struct
module.
Will backport to release25-maint.
........
r53340 | gustavo.niemeyer | 2007-01-10 17:13:40 +0100 (Wed, 10 Jan 2007) | 3 lines
Mention in the int() docstring that a base zero has meaning, as
stated in http://docs.python.org/lib/built-in-funcs.html as well.
........
r53341 | gustavo.niemeyer | 2007-01-10 17:15:48 +0100 (Wed, 10 Jan 2007) | 2 lines
Minor change in int() docstring for proper spacing.
........
r53358 | thomas.heller | 2007-01-10 21:12:13 +0100 (Wed, 10 Jan 2007) | 1 line
Change the ctypes version number to "1.1.0".
........
r53361 | thomas.heller | 2007-01-10 21:51:19 +0100 (Wed, 10 Jan 2007) | 1 line
Must change the version number in the _ctypes extension as well.
........
r53362 | guido.van.rossum | 2007-01-11 00:12:56 +0100 (Thu, 11 Jan 2007) | 3 lines
Fix the signature of log_error(). (A subclass that did the right thing
was getting complaints from pychecker.)
........
r53370 | matthias.klose | 2007-01-11 11:26:31 +0100 (Thu, 11 Jan 2007) | 2 lines
- Make the documentation match the code and the docstring
........
r53375 | matthias.klose | 2007-01-11 12:44:04 +0100 (Thu, 11 Jan 2007) | 2 lines
- idle: Honor the "Cancel" action in the save dialog (Debian bug #299092).
........
r53381 | raymond.hettinger | 2007-01-11 19:22:55 +0100 (Thu, 11 Jan 2007) | 1 line
SF #1486663 -- Allow keyword args in subclasses of set() and frozenset().
........
r53388 | thomas.heller | 2007-01-11 22:18:56 +0100 (Thu, 11 Jan 2007) | 4 lines
Fixes for 64-bit Windows: In ctypes.wintypes, correct the definitions
of HANDLE, WPARAM, LPARAM data types. Make parameterless foreign
function calls work.
........
r53390 | thomas.heller | 2007-01-11 22:23:12 +0100 (Thu, 11 Jan 2007) | 2 lines
Correct the comments: the code is right.
........
r53393 | brett.cannon | 2007-01-12 08:27:52 +0100 (Fri, 12 Jan 2007) | 3 lines
Fix error where the end of a funcdesc environment was accidentally moved too
far down.
........
r53397 | anthony.baxter | 2007-01-12 10:35:56 +0100 (Fri, 12 Jan 2007) | 3 lines
add parsetok.h as a dependency - previously, changing this file doesn't
cause the right files to be rebuilt.
........
r53401 | thomas.heller | 2007-01-12 21:08:19 +0100 (Fri, 12 Jan 2007) | 3 lines
Avoid warnings in the test suite because ctypes.wintypes cannot be
imported on non-windows systems.
........
r53402 | thomas.heller | 2007-01-12 21:17:34 +0100 (Fri, 12 Jan 2007) | 6 lines
patch #1610795: BSD version of ctypes.util.find_library, by Martin
Kammerhofer.
release25-maint backport candidate, but the release manager has to
decide.
........
r53403 | thomas.heller | 2007-01-12 21:21:53 +0100 (Fri, 12 Jan 2007) | 3 lines
patch #1610795: BSD version of ctypes.util.find_library, by Martin
Kammerhofer.
........
r53406 | brett.cannon | 2007-01-13 01:29:49 +0100 (Sat, 13 Jan 2007) | 2 lines
Deprecate the sets module.
........
r53407 | georg.brandl | 2007-01-13 13:31:51 +0100 (Sat, 13 Jan 2007) | 3 lines
Fix typo.
........
r53409 | marc-andre.lemburg | 2007-01-13 22:00:08 +0100 (Sat, 13 Jan 2007) | 16 lines
Bump version number and change copyright year.
Add new API linux_distribution() which supports reading the full distribution
name and also knows how to parse LSB-style release files.
Redirect the old dist() API to the new API (using the short distribution name
taken from the release file filename).
Add branch and revision to _sys_version().
Add work-around for Cygwin to libc_ver().
Add support for IronPython (thanks for Anthony Baxter) and make
Jython support more robust.
........
r53410 | neal.norwitz | 2007-01-13 22:22:37 +0100 (Sat, 13 Jan 2007) | 1 line
Fix grammar in docstrings
........
r53411 | marc-andre.lemburg | 2007-01-13 23:32:21 +0100 (Sat, 13 Jan 2007) | 9 lines
Add parameter sys_version to _sys_version().
Change the cache for _sys_version() to take the parameter into account.
Add support for parsing the IronPython 1.0.1 sys.version value - even
though it still returns '1.0.0'; the version string no longer includes
the patch level.
........
r53412 | peter.astrand | 2007-01-13 23:35:35 +0100 (Sat, 13 Jan 2007) | 1 line
Fix for bug #1634343: allow specifying empty arguments on Windows
........
r53414 | marc-andre.lemburg | 2007-01-13 23:59:36 +0100 (Sat, 13 Jan 2007) | 14 lines
Add Python implementation to the machine details.
Pretty-print the Python version used for running PyBench.
Let the user know when calibration has finished.
[ 1563844 ] pybench support for IronPython:
Simplify Unicode version detection.
Make garbage collection and check interval settings optional if
the Python implementation doesn't support thess (e.g. IronPython).
........
r53415 | marc-andre.lemburg | 2007-01-14 00:13:54 +0100 (Sun, 14 Jan 2007) | 5 lines
Use defaults if sys.executable isn't set (e.g. on Jython).
This change allows running PyBench under Jython.
........
r53416 | marc-andre.lemburg | 2007-01-14 00:15:33 +0100 (Sun, 14 Jan 2007) | 3 lines
Jython doesn't have sys.setcheckinterval() - ignore it in that case.
........
r53420 | gerhard.haering | 2007-01-14 02:43:50 +0100 (Sun, 14 Jan 2007) | 29 lines
Merged changes from standalone version 2.3.3. This should probably all be
merged into the 2.5 maintenance branch:
- self->statement was not checked while fetching data, which could
lead to crashes if you used the pysqlite API in unusual ways.
Closing the cursor and continuing to fetch data was enough.
- Converters are stored in a converters dictionary. The converter name
is uppercased first. The old upper-casing algorithm was wrong and
was replaced by a simple call to the Python string's upper() method
instead.
-Applied patch by Glyph Lefkowitz that fixes the problem with
subsequent SQLITE_SCHEMA errors.
- Improvement to the row type: rows can now be iterated over and have a keys()
method. This improves compatibility with both tuple and dict a lot.
- A bugfix for the subsecond resolution in timestamps.
- Corrected the way the flags PARSE_DECLTYPES and PARSE_COLNAMES are
checked for. Now they work as documented.
- gcc on Linux sucks. It exports all symbols by default in shared
libraries, so if symbols are not unique it can lead to problems with
symbol lookup. pysqlite used to crash under Apache when mod_cache
was enabled because both modules had the symbol cache_init. I fixed
this by applying the prefix pysqlite_ almost everywhere. Sigh.
........
r53423 | guido.van.rossum | 2007-01-14 04:46:33 +0100 (Sun, 14 Jan 2007) | 2 lines
Remove a dependency of this test on $COLUMNS.
........
r53425 | ka-ping.yee | 2007-01-14 05:25:15 +0100 (Sun, 14 Jan 2007) | 3 lines
Handle old-style instances more gracefully (display documentation on
the relevant class instead of documentation on <type 'instance'>).
........
r53440 | vinay.sajip | 2007-01-14 22:49:59 +0100 (Sun, 14 Jan 2007) | 1 line
Added WatchedFileHandler (based on SF patch #1598415)
........
r53441 | vinay.sajip | 2007-01-14 22:50:50 +0100 (Sun, 14 Jan 2007) | 1 line
Added documentation for WatchedFileHandler (based on SF patch #1598415)
........
r53442 | guido.van.rossum | 2007-01-15 01:02:35 +0100 (Mon, 15 Jan 2007) | 2 lines
Doc patch matching r53434 (htonl etc. now always take/return positive ints).
........
2007-01-15 11:49:28 -04:00
|
|
|
void pysqlite_statement_mark_dirty(pysqlite_Statement* self)
|
2006-04-21 07:40:58 -03:00
|
|
|
{
|
|
|
|
self->in_use = 1;
|
|
|
|
}
|
|
|
|
|
2021-02-20 20:29:19 -04:00
|
|
|
static void
|
2021-05-25 14:43:56 -03:00
|
|
|
stmt_dealloc(pysqlite_Statement *self)
|
2006-04-21 07:40:58 -03:00
|
|
|
{
|
2020-10-01 10:24:31 -03:00
|
|
|
PyTypeObject *tp = Py_TYPE(self);
|
2021-05-25 14:43:56 -03:00
|
|
|
PyObject_GC_UnTrack(self);
|
2021-06-04 23:50:39 -03:00
|
|
|
if (self->st) {
|
2021-06-05 19:41:11 -03:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
2021-06-04 23:50:39 -03:00
|
|
|
sqlite3_finalize(self->st);
|
2021-06-05 19:41:11 -03:00
|
|
|
Py_END_ALLOW_THREADS
|
2021-06-04 23:50:39 -03:00
|
|
|
self->st = 0;
|
|
|
|
}
|
2021-05-25 14:43:56 -03:00
|
|
|
tp->tp_free(self);
|
|
|
|
Py_DECREF(tp);
|
|
|
|
}
|
2020-10-01 10:24:31 -03:00
|
|
|
|
2021-05-25 14:43:56 -03:00
|
|
|
static int
|
|
|
|
stmt_traverse(pysqlite_Statement *self, visitproc visit, void *arg)
|
|
|
|
{
|
|
|
|
Py_VISIT(Py_TYPE(self));
|
|
|
|
return 0;
|
2006-04-21 07:40:58 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Checks if there is anything left in an SQL string after SQLite compiled it.
|
|
|
|
* This is used to check if somebody tried to execute more than one SQL command
|
|
|
|
* with one execute()/executemany() command, which the DB-API and we don't
|
|
|
|
* allow.
|
|
|
|
*
|
|
|
|
* Returns 1 if there is more left than should be. 0 if ok.
|
|
|
|
*/
|
Merged revisions 53304-53433,53435-53450 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r53304 | vinay.sajip | 2007-01-09 15:50:28 +0100 (Tue, 09 Jan 2007) | 1 line
Bug #1627575: Added _open() method to FileHandler which can be used to reopen files. The FileHandler instance now saves the encoding (which can be None) in an attribute called "encoding".
........
r53305 | vinay.sajip | 2007-01-09 15:51:36 +0100 (Tue, 09 Jan 2007) | 1 line
Added entry about addition of _open() method to logging.FileHandler.
........
r53306 | vinay.sajip | 2007-01-09 15:54:56 +0100 (Tue, 09 Jan 2007) | 1 line
Added a docstring
........
r53316 | thomas.heller | 2007-01-09 20:19:33 +0100 (Tue, 09 Jan 2007) | 4 lines
Verify the sizes of the basic ctypes data types against the struct
module.
Will backport to release25-maint.
........
r53340 | gustavo.niemeyer | 2007-01-10 17:13:40 +0100 (Wed, 10 Jan 2007) | 3 lines
Mention in the int() docstring that a base zero has meaning, as
stated in http://docs.python.org/lib/built-in-funcs.html as well.
........
r53341 | gustavo.niemeyer | 2007-01-10 17:15:48 +0100 (Wed, 10 Jan 2007) | 2 lines
Minor change in int() docstring for proper spacing.
........
r53358 | thomas.heller | 2007-01-10 21:12:13 +0100 (Wed, 10 Jan 2007) | 1 line
Change the ctypes version number to "1.1.0".
........
r53361 | thomas.heller | 2007-01-10 21:51:19 +0100 (Wed, 10 Jan 2007) | 1 line
Must change the version number in the _ctypes extension as well.
........
r53362 | guido.van.rossum | 2007-01-11 00:12:56 +0100 (Thu, 11 Jan 2007) | 3 lines
Fix the signature of log_error(). (A subclass that did the right thing
was getting complaints from pychecker.)
........
r53370 | matthias.klose | 2007-01-11 11:26:31 +0100 (Thu, 11 Jan 2007) | 2 lines
- Make the documentation match the code and the docstring
........
r53375 | matthias.klose | 2007-01-11 12:44:04 +0100 (Thu, 11 Jan 2007) | 2 lines
- idle: Honor the "Cancel" action in the save dialog (Debian bug #299092).
........
r53381 | raymond.hettinger | 2007-01-11 19:22:55 +0100 (Thu, 11 Jan 2007) | 1 line
SF #1486663 -- Allow keyword args in subclasses of set() and frozenset().
........
r53388 | thomas.heller | 2007-01-11 22:18:56 +0100 (Thu, 11 Jan 2007) | 4 lines
Fixes for 64-bit Windows: In ctypes.wintypes, correct the definitions
of HANDLE, WPARAM, LPARAM data types. Make parameterless foreign
function calls work.
........
r53390 | thomas.heller | 2007-01-11 22:23:12 +0100 (Thu, 11 Jan 2007) | 2 lines
Correct the comments: the code is right.
........
r53393 | brett.cannon | 2007-01-12 08:27:52 +0100 (Fri, 12 Jan 2007) | 3 lines
Fix error where the end of a funcdesc environment was accidentally moved too
far down.
........
r53397 | anthony.baxter | 2007-01-12 10:35:56 +0100 (Fri, 12 Jan 2007) | 3 lines
add parsetok.h as a dependency - previously, changing this file doesn't
cause the right files to be rebuilt.
........
r53401 | thomas.heller | 2007-01-12 21:08:19 +0100 (Fri, 12 Jan 2007) | 3 lines
Avoid warnings in the test suite because ctypes.wintypes cannot be
imported on non-windows systems.
........
r53402 | thomas.heller | 2007-01-12 21:17:34 +0100 (Fri, 12 Jan 2007) | 6 lines
patch #1610795: BSD version of ctypes.util.find_library, by Martin
Kammerhofer.
release25-maint backport candidate, but the release manager has to
decide.
........
r53403 | thomas.heller | 2007-01-12 21:21:53 +0100 (Fri, 12 Jan 2007) | 3 lines
patch #1610795: BSD version of ctypes.util.find_library, by Martin
Kammerhofer.
........
r53406 | brett.cannon | 2007-01-13 01:29:49 +0100 (Sat, 13 Jan 2007) | 2 lines
Deprecate the sets module.
........
r53407 | georg.brandl | 2007-01-13 13:31:51 +0100 (Sat, 13 Jan 2007) | 3 lines
Fix typo.
........
r53409 | marc-andre.lemburg | 2007-01-13 22:00:08 +0100 (Sat, 13 Jan 2007) | 16 lines
Bump version number and change copyright year.
Add new API linux_distribution() which supports reading the full distribution
name and also knows how to parse LSB-style release files.
Redirect the old dist() API to the new API (using the short distribution name
taken from the release file filename).
Add branch and revision to _sys_version().
Add work-around for Cygwin to libc_ver().
Add support for IronPython (thanks for Anthony Baxter) and make
Jython support more robust.
........
r53410 | neal.norwitz | 2007-01-13 22:22:37 +0100 (Sat, 13 Jan 2007) | 1 line
Fix grammar in docstrings
........
r53411 | marc-andre.lemburg | 2007-01-13 23:32:21 +0100 (Sat, 13 Jan 2007) | 9 lines
Add parameter sys_version to _sys_version().
Change the cache for _sys_version() to take the parameter into account.
Add support for parsing the IronPython 1.0.1 sys.version value - even
though it still returns '1.0.0'; the version string no longer includes
the patch level.
........
r53412 | peter.astrand | 2007-01-13 23:35:35 +0100 (Sat, 13 Jan 2007) | 1 line
Fix for bug #1634343: allow specifying empty arguments on Windows
........
r53414 | marc-andre.lemburg | 2007-01-13 23:59:36 +0100 (Sat, 13 Jan 2007) | 14 lines
Add Python implementation to the machine details.
Pretty-print the Python version used for running PyBench.
Let the user know when calibration has finished.
[ 1563844 ] pybench support for IronPython:
Simplify Unicode version detection.
Make garbage collection and check interval settings optional if
the Python implementation doesn't support thess (e.g. IronPython).
........
r53415 | marc-andre.lemburg | 2007-01-14 00:13:54 +0100 (Sun, 14 Jan 2007) | 5 lines
Use defaults if sys.executable isn't set (e.g. on Jython).
This change allows running PyBench under Jython.
........
r53416 | marc-andre.lemburg | 2007-01-14 00:15:33 +0100 (Sun, 14 Jan 2007) | 3 lines
Jython doesn't have sys.setcheckinterval() - ignore it in that case.
........
r53420 | gerhard.haering | 2007-01-14 02:43:50 +0100 (Sun, 14 Jan 2007) | 29 lines
Merged changes from standalone version 2.3.3. This should probably all be
merged into the 2.5 maintenance branch:
- self->statement was not checked while fetching data, which could
lead to crashes if you used the pysqlite API in unusual ways.
Closing the cursor and continuing to fetch data was enough.
- Converters are stored in a converters dictionary. The converter name
is uppercased first. The old upper-casing algorithm was wrong and
was replaced by a simple call to the Python string's upper() method
instead.
-Applied patch by Glyph Lefkowitz that fixes the problem with
subsequent SQLITE_SCHEMA errors.
- Improvement to the row type: rows can now be iterated over and have a keys()
method. This improves compatibility with both tuple and dict a lot.
- A bugfix for the subsecond resolution in timestamps.
- Corrected the way the flags PARSE_DECLTYPES and PARSE_COLNAMES are
checked for. Now they work as documented.
- gcc on Linux sucks. It exports all symbols by default in shared
libraries, so if symbols are not unique it can lead to problems with
symbol lookup. pysqlite used to crash under Apache when mod_cache
was enabled because both modules had the symbol cache_init. I fixed
this by applying the prefix pysqlite_ almost everywhere. Sigh.
........
r53423 | guido.van.rossum | 2007-01-14 04:46:33 +0100 (Sun, 14 Jan 2007) | 2 lines
Remove a dependency of this test on $COLUMNS.
........
r53425 | ka-ping.yee | 2007-01-14 05:25:15 +0100 (Sun, 14 Jan 2007) | 3 lines
Handle old-style instances more gracefully (display documentation on
the relevant class instead of documentation on <type 'instance'>).
........
r53440 | vinay.sajip | 2007-01-14 22:49:59 +0100 (Sun, 14 Jan 2007) | 1 line
Added WatchedFileHandler (based on SF patch #1598415)
........
r53441 | vinay.sajip | 2007-01-14 22:50:50 +0100 (Sun, 14 Jan 2007) | 1 line
Added documentation for WatchedFileHandler (based on SF patch #1598415)
........
r53442 | guido.van.rossum | 2007-01-15 01:02:35 +0100 (Mon, 15 Jan 2007) | 2 lines
Doc patch matching r53434 (htonl etc. now always take/return positive ints).
........
2007-01-15 11:49:28 -04:00
|
|
|
static int pysqlite_check_remaining_sql(const char* tail)
|
2006-04-21 07:40:58 -03:00
|
|
|
{
|
|
|
|
const char* pos = tail;
|
|
|
|
|
|
|
|
parse_remaining_sql_state state = NORMAL;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
switch (*pos) {
|
|
|
|
case 0:
|
|
|
|
return 0;
|
|
|
|
case '-':
|
|
|
|
if (state == NORMAL) {
|
|
|
|
state = LINECOMMENT_1;
|
|
|
|
} else if (state == LINECOMMENT_1) {
|
|
|
|
state = IN_LINECOMMENT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
case '\t':
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
case 13:
|
|
|
|
if (state == IN_LINECOMMENT) {
|
|
|
|
state = NORMAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '/':
|
|
|
|
if (state == NORMAL) {
|
|
|
|
state = COMMENTSTART_1;
|
|
|
|
} else if (state == COMMENTEND_1) {
|
|
|
|
state = NORMAL;
|
|
|
|
} else if (state == COMMENTSTART_1) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
if (state == NORMAL) {
|
|
|
|
return 1;
|
|
|
|
} else if (state == LINECOMMENT_1) {
|
|
|
|
return 1;
|
|
|
|
} else if (state == COMMENTSTART_1) {
|
|
|
|
state = IN_COMMENT;
|
|
|
|
} else if (state == IN_COMMENT) {
|
|
|
|
state = COMMENTEND_1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (state == COMMENTEND_1) {
|
|
|
|
state = IN_COMMENT;
|
|
|
|
} else if (state == IN_LINECOMMENT) {
|
|
|
|
} else if (state == IN_COMMENT) {
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-01 10:24:31 -03:00
|
|
|
static PyType_Slot stmt_slots[] = {
|
2021-05-25 14:43:56 -03:00
|
|
|
{Py_tp_dealloc, stmt_dealloc},
|
|
|
|
{Py_tp_traverse, stmt_traverse},
|
2020-10-01 10:24:31 -03:00
|
|
|
{0, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
static PyType_Spec stmt_spec = {
|
|
|
|
.name = MODULE_NAME ".Statement",
|
|
|
|
.basicsize = sizeof(pysqlite_Statement),
|
2021-06-17 07:06:09 -03:00
|
|
|
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
|
2021-06-20 16:24:32 -03:00
|
|
|
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
|
2020-10-01 10:24:31 -03:00
|
|
|
.slots = stmt_slots,
|
2006-04-21 07:40:58 -03:00
|
|
|
};
|
|
|
|
|
2021-02-21 06:07:49 -04:00
|
|
|
int
|
|
|
|
pysqlite_statement_setup_types(PyObject *module)
|
2006-04-21 07:40:58 -03:00
|
|
|
{
|
2021-06-15 09:47:34 -03:00
|
|
|
PyObject *type = PyType_FromModuleAndSpec(module, &stmt_spec, NULL);
|
|
|
|
if (type == NULL) {
|
2020-10-01 10:24:31 -03:00
|
|
|
return -1;
|
|
|
|
}
|
2021-06-15 09:47:34 -03:00
|
|
|
pysqlite_state *state = pysqlite_get_state(module);
|
|
|
|
state->StatementType = (PyTypeObject *)type;
|
2020-10-01 10:24:31 -03:00
|
|
|
return 0;
|
2006-04-21 07:40:58 -03:00
|
|
|
}
|