#-*- coding: ISO-8859-1 -*-
# 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.
#
# pysqlite2/test/userfunctions.py: tests for user-defined functions and
# 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.
#
/* 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.
*
/* 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.
*
PyObject* descriptor;
PyObject* second_argument = NULL;
long rowcount = 0;
+ int allow_8bit_chars;
if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {
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);
self->next_row = NULL;
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()) {
goto error;
}
/* 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.
*
/* 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.
*
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;
long longval;
Py_ssize_t buflen;
PyObject* stringval;
parameter_type paramtype;
+ char* c;
if (parameter == Py_None) {
rc = sqlite3_bind_null(self->st, pos);
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) {
case TYPE_INT:
longval = PyInt_AsLong(parameter);
}
}
-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* adapted;
}
}
- rc = pysqlite_statement_bind_parameter(self, i + 1, adapted);
+ rc = pysqlite_statement_bind_parameter(self, i + 1, adapted, allow_8bit_chars);
Py_DECREF(adapted);
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;
}
}
}
}
- rc = pysqlite_statement_bind_parameter(self, i, adapted);
+ rc = pysqlite_statement_bind_parameter(self, i, adapted, allow_8bit_chars);
Py_DECREF(adapted);
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;
}
}
/* 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.
*
int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* connection, PyObject* sql);
void pysqlite_statement_dealloc(pysqlite_Statement* self);
-int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter);
-void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters);
+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, int allow_8bit_chars);
int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* parameters);
int pysqlite_statement_finalize(pysqlite_Statement* self);
/* 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.
*