Skip to content

Commit c3f5f92

Browse files
author
gerhard.haering
committed
Update sqlite3 module to match current version of pysqlite.
git-svn-id: http://svn.python.org/projects/python/trunk@62011 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 13049d2 commit c3f5f92

10 files changed

Lines changed: 37 additions & 17 deletions

File tree

Lib/sqlite3/test/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#-*- coding: ISO-8859-1 -*-
22
# pysqlite2/test/factory.py: tests for the various factories in pysqlite
33
#
4-
# Copyright (C) 2005 Gerhard Häring <gh@ghaering.de>
4+
# Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
55
#
66
# This file is part of pysqlite.
77
#

Lib/sqlite3/test/userfunctions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# pysqlite2/test/userfunctions.py: tests for user-defined functions and
33
# aggregates.
44
#
5-
# Copyright (C) 2005 Gerhard Häring <gh@ghaering.de>
5+
# Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
66
#
77
# This file is part of pysqlite.
88
#

Modules/_sqlite/cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* cache .c - a LRU cache
22
*
3-
* Copyright (C) 2004-2006 Gerhard Häring <gh@ghaering.de>
3+
* Copyright (C) 2004-2007 Gerhard Häring <gh@ghaering.de>
44
*
55
* This file is part of pysqlite.
66
*

Modules/_sqlite/cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* cache.h - definitions for the LRU cache
22
*
3-
* Copyright (C) 2004-2006 Gerhard Häring <gh@ghaering.de>
3+
* Copyright (C) 2004-2007 Gerhard Häring <gh@ghaering.de>
44
*
55
* This file is part of pysqlite.
66
*

Modules/_sqlite/cursor.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,14 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
424424
PyObject* descriptor;
425425
PyObject* second_argument = NULL;
426426
long rowcount = 0;
427+
int allow_8bit_chars;
427428

428429
if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {
429430
return NULL;
430431
}
432+
/* Make shooting yourself in the foot with not utf-8 decodable 8-bit-strings harder */
433+
allow_8bit_chars = ((self->connection->text_factory != (PyObject*)&PyUnicode_Type) &&
434+
(self->connection->text_factory != (PyObject*)&PyUnicode_Type && pysqlite_OptimizedUnicode));
431435

432436
Py_XDECREF(self->next_row);
433437
self->next_row = NULL;
@@ -592,7 +596,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
592596

593597
pysqlite_statement_mark_dirty(self->statement);
594598

595-
pysqlite_statement_bind_parameters(self->statement, parameters);
599+
pysqlite_statement_bind_parameters(self->statement, parameters, allow_8bit_chars);
596600
if (PyErr_Occurred()) {
597601
goto error;
598602
}

Modules/_sqlite/prepare_protocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* prepare_protocol.h - the protocol for preparing values for SQLite
22
*
3-
* Copyright (C) 2005 Gerhard Häring <gh@ghaering.de>
3+
* Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
44
*
55
* This file is part of pysqlite.
66
*

Modules/_sqlite/row.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* row.h - an enhanced tuple for database rows
22
*
3-
* Copyright (C) 2005 Gerhard Häring <gh@ghaering.de>
3+
* Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
44
*
55
* This file is part of pysqlite.
66
*

Modules/_sqlite/statement.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
9696
return rc;
9797
}
9898

99-
int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter)
99+
int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter, int allow_8bit_chars)
100100
{
101101
int rc = SQLITE_OK;
102102
long longval;
@@ -108,6 +108,7 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
108108
Py_ssize_t buflen;
109109
PyObject* stringval;
110110
parameter_type paramtype;
111+
char* c;
111112

112113
if (parameter == Py_None) {
113114
rc = sqlite3_bind_null(self->st, pos);
@@ -140,6 +141,17 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
140141
paramtype = TYPE_UNKNOWN;
141142
}
142143

144+
if (paramtype == TYPE_STRING && !allow_8bit_chars) {
145+
string = PyString_AS_STRING(parameter);
146+
for (c = string; *c != 0; c++) {
147+
if (*c & 0x80) {
148+
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.");
149+
rc = -1;
150+
goto final;
151+
}
152+
}
153+
}
154+
143155
switch (paramtype) {
144156
case TYPE_INT:
145157
longval = PyInt_AsLong(parameter);
@@ -197,7 +209,7 @@ static int _need_adapt(PyObject* obj)
197209
}
198210
}
199211

200-
void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters)
212+
void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters, int allow_8bit_chars)
201213
{
202214
PyObject* current_param;
203215
PyObject* adapted;
@@ -251,11 +263,13 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
251263
}
252264
}
253265

254-
rc = pysqlite_statement_bind_parameter(self, i + 1, adapted);
266+
rc = pysqlite_statement_bind_parameter(self, i + 1, adapted, allow_8bit_chars);
255267
Py_DECREF(adapted);
256268

257269
if (rc != SQLITE_OK) {
258-
PyErr_Format(pysqlite_InterfaceError, "Error binding parameter %d - probably unsupported type.", i);
270+
if (!PyErr_Occurred()) {
271+
PyErr_Format(pysqlite_InterfaceError, "Error binding parameter %d - probably unsupported type.", i);
272+
}
259273
return;
260274
}
261275
}
@@ -294,11 +308,13 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
294308
}
295309
}
296310

297-
rc = pysqlite_statement_bind_parameter(self, i, adapted);
311+
rc = pysqlite_statement_bind_parameter(self, i, adapted, allow_8bit_chars);
298312
Py_DECREF(adapted);
299313

300314
if (rc != SQLITE_OK) {
301-
PyErr_Format(pysqlite_InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name);
315+
if (!PyErr_Occurred()) {
316+
PyErr_Format(pysqlite_InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name);
317+
}
302318
return;
303319
}
304320
}

Modules/_sqlite/statement.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* statement.h - definitions for the statement type
22
*
3-
* Copyright (C) 2005 Gerhard Häring <gh@ghaering.de>
3+
* Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
44
*
55
* This file is part of pysqlite.
66
*
@@ -46,8 +46,8 @@ extern PyTypeObject pysqlite_StatementType;
4646
int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* connection, PyObject* sql);
4747
void pysqlite_statement_dealloc(pysqlite_Statement* self);
4848

49-
int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter);
50-
void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters);
49+
int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter, int allow_8bit_chars);
50+
void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters, int allow_8bit_chars);
5151

5252
int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* parameters);
5353
int pysqlite_statement_finalize(pysqlite_Statement* self);

Modules/_sqlite/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* util.h - various utility functions
22
*
3-
* Copyright (C) 2005-2006 Gerhard Häring <gh@ghaering.de>
3+
* Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
44
*
55
* This file is part of pysqlite.
66
*

0 commit comments

Comments
 (0)