Update sqlite3 module to match current version of pysqlite.

This commit is contained in:
Gerhard Häring 2008-03-28 20:08:36 +00:00
parent d289ea6df9
commit 2a11c05b9d
10 changed files with 37 additions and 17 deletions

View File

@ -1,7 +1,7 @@
#-*- coding: ISO-8859-1 -*- #-*- coding: ISO-8859-1 -*-
# pysqlite2/test/factory.py: tests for the various factories in pysqlite # pysqlite2/test/factory.py: tests for the various factories in pysqlite
# #
# Copyright (C) 2005 Gerhard Häring <gh@ghaering.de> # Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
# #
# This file is part of pysqlite. # This file is part of pysqlite.
# #

View File

@ -2,7 +2,7 @@
# pysqlite2/test/userfunctions.py: tests for user-defined functions and # pysqlite2/test/userfunctions.py: tests for user-defined functions and
# aggregates. # aggregates.
# #
# Copyright (C) 2005 Gerhard Häring <gh@ghaering.de> # Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
# #
# This file is part of pysqlite. # This file is part of pysqlite.
# #

View File

@ -1,6 +1,6 @@
/* cache .c - a LRU cache /* cache .c - a LRU cache
* *
* Copyright (C) 2004-2006 Gerhard Häring <gh@ghaering.de> * Copyright (C) 2004-2007 Gerhard Häring <gh@ghaering.de>
* *
* This file is part of pysqlite. * This file is part of pysqlite.
* *

View File

@ -1,6 +1,6 @@
/* cache.h - definitions for the LRU cache /* cache.h - definitions for the LRU cache
* *
* Copyright (C) 2004-2006 Gerhard Häring <gh@ghaering.de> * Copyright (C) 2004-2007 Gerhard Häring <gh@ghaering.de>
* *
* This file is part of pysqlite. * This file is part of pysqlite.
* *

View File

@ -424,10 +424,14 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
PyObject* descriptor; PyObject* descriptor;
PyObject* second_argument = NULL; PyObject* second_argument = NULL;
long rowcount = 0; long rowcount = 0;
int allow_8bit_chars;
if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) { if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {
return NULL; return NULL;
} }
/* Make shooting yourself in the foot with not utf-8 decodable 8-bit-strings harder */
allow_8bit_chars = ((self->connection->text_factory != (PyObject*)&PyUnicode_Type) &&
(self->connection->text_factory != (PyObject*)&PyUnicode_Type && pysqlite_OptimizedUnicode));
Py_XDECREF(self->next_row); Py_XDECREF(self->next_row);
self->next_row = NULL; self->next_row = NULL;
@ -592,7 +596,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
pysqlite_statement_mark_dirty(self->statement); pysqlite_statement_mark_dirty(self->statement);
pysqlite_statement_bind_parameters(self->statement, parameters); pysqlite_statement_bind_parameters(self->statement, parameters, allow_8bit_chars);
if (PyErr_Occurred()) { if (PyErr_Occurred()) {
goto error; goto error;
} }

View File

@ -1,6 +1,6 @@
/* prepare_protocol.h - the protocol for preparing values for SQLite /* prepare_protocol.h - the protocol for preparing values for SQLite
* *
* Copyright (C) 2005 Gerhard Häring <gh@ghaering.de> * Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
* *
* This file is part of pysqlite. * This file is part of pysqlite.
* *

View File

@ -1,6 +1,6 @@
/* row.h - an enhanced tuple for database rows /* row.h - an enhanced tuple for database rows
* *
* Copyright (C) 2005 Gerhard Häring <gh@ghaering.de> * Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
* *
* This file is part of pysqlite. * This file is part of pysqlite.
* *

View File

@ -96,7 +96,7 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
return rc; return rc;
} }
int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter) int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter, int allow_8bit_chars)
{ {
int rc = SQLITE_OK; int rc = SQLITE_OK;
long longval; long longval;
@ -108,6 +108,7 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
Py_ssize_t buflen; Py_ssize_t buflen;
PyObject* stringval; PyObject* stringval;
parameter_type paramtype; parameter_type paramtype;
char* c;
if (parameter == Py_None) { if (parameter == Py_None) {
rc = sqlite3_bind_null(self->st, pos); rc = sqlite3_bind_null(self->st, pos);
@ -140,6 +141,17 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
paramtype = TYPE_UNKNOWN; paramtype = TYPE_UNKNOWN;
} }
if (paramtype == TYPE_STRING && !allow_8bit_chars) {
string = PyString_AS_STRING(parameter);
for (c = string; *c != 0; c++) {
if (*c & 0x80) {
PyErr_SetString(pysqlite_ProgrammingError, "You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.");
rc = -1;
goto final;
}
}
}
switch (paramtype) { switch (paramtype) {
case TYPE_INT: case TYPE_INT:
longval = PyInt_AsLong(parameter); longval = PyInt_AsLong(parameter);
@ -197,7 +209,7 @@ static int _need_adapt(PyObject* obj)
} }
} }
void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters) void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters, int allow_8bit_chars)
{ {
PyObject* current_param; PyObject* current_param;
PyObject* adapted; PyObject* adapted;
@ -251,11 +263,13 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
} }
} }
rc = pysqlite_statement_bind_parameter(self, i + 1, adapted); rc = pysqlite_statement_bind_parameter(self, i + 1, adapted, allow_8bit_chars);
Py_DECREF(adapted); Py_DECREF(adapted);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
PyErr_Format(pysqlite_InterfaceError, "Error binding parameter %d - probably unsupported type.", i); if (!PyErr_Occurred()) {
PyErr_Format(pysqlite_InterfaceError, "Error binding parameter %d - probably unsupported type.", i);
}
return; return;
} }
} }
@ -294,11 +308,13 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
} }
} }
rc = pysqlite_statement_bind_parameter(self, i, adapted); rc = pysqlite_statement_bind_parameter(self, i, adapted, allow_8bit_chars);
Py_DECREF(adapted); Py_DECREF(adapted);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
PyErr_Format(pysqlite_InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name); if (!PyErr_Occurred()) {
PyErr_Format(pysqlite_InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name);
}
return; return;
} }
} }

View File

@ -1,6 +1,6 @@
/* statement.h - definitions for the statement type /* statement.h - definitions for the statement type
* *
* Copyright (C) 2005 Gerhard Häring <gh@ghaering.de> * Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
* *
* This file is part of pysqlite. * This file is part of pysqlite.
* *
@ -46,8 +46,8 @@ extern PyTypeObject pysqlite_StatementType;
int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* connection, PyObject* sql); int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* connection, PyObject* sql);
void pysqlite_statement_dealloc(pysqlite_Statement* self); void pysqlite_statement_dealloc(pysqlite_Statement* self);
int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter); int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter, int allow_8bit_chars);
void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters); void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters, int allow_8bit_chars);
int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* parameters); int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* parameters);
int pysqlite_statement_finalize(pysqlite_Statement* self); int pysqlite_statement_finalize(pysqlite_Statement* self);

View File

@ -1,6 +1,6 @@
/* util.h - various utility functions /* util.h - various utility functions
* *
* Copyright (C) 2005-2006 Gerhard Häring <gh@ghaering.de> * Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
* *
* This file is part of pysqlite. * This file is part of pysqlite.
* *