[Python-checkins] r62011 - in python/trunk: Lib/sqlite3/test/factory.py Lib/sqlite3/test/userfunctions.py Modules/_sqlite/cache.c Modules/_sqlite/cache.h Modules/_sqlite/cursor.c Modules/_sqlite/prepare_protocol.h Modules/_sqlite/row.h Modules/_sqlite/statement.c Modules/_sqlite/statement.h Modules/_sqlite/util.h

gerhard.haering python-checkins at python.org
Fri Mar 28 21:08:46 CET 2008


Author: gerhard.haering
Date: Fri Mar 28 21:08:36 2008
New Revision: 62011

Modified:
   python/trunk/Lib/sqlite3/test/factory.py
   python/trunk/Lib/sqlite3/test/userfunctions.py
   python/trunk/Modules/_sqlite/cache.c
   python/trunk/Modules/_sqlite/cache.h
   python/trunk/Modules/_sqlite/cursor.c
   python/trunk/Modules/_sqlite/prepare_protocol.h
   python/trunk/Modules/_sqlite/row.h
   python/trunk/Modules/_sqlite/statement.c
   python/trunk/Modules/_sqlite/statement.h
   python/trunk/Modules/_sqlite/util.h
Log:
Update sqlite3 module to match current version of pysqlite.


Modified: python/trunk/Lib/sqlite3/test/factory.py
==============================================================================
--- python/trunk/Lib/sqlite3/test/factory.py	(original)
+++ python/trunk/Lib/sqlite3/test/factory.py	Fri Mar 28 21:08:36 2008
@@ -1,7 +1,7 @@
 #-*- coding: ISO-8859-1 -*-
 # pysqlite2/test/factory.py: tests for the various factories in pysqlite
 #
-# Copyright (C) 2005 Gerhard Häring <gh at ghaering.de>
+# Copyright (C) 2005-2007 Gerhard Häring <gh at ghaering.de>
 #
 # This file is part of pysqlite.
 #

Modified: python/trunk/Lib/sqlite3/test/userfunctions.py
==============================================================================
--- python/trunk/Lib/sqlite3/test/userfunctions.py	(original)
+++ python/trunk/Lib/sqlite3/test/userfunctions.py	Fri Mar 28 21:08:36 2008
@@ -2,7 +2,7 @@
 # pysqlite2/test/userfunctions.py: tests for user-defined functions and
 #                                  aggregates.
 #
-# Copyright (C) 2005 Gerhard Häring <gh at ghaering.de>
+# Copyright (C) 2005-2007 Gerhard Häring <gh at ghaering.de>
 #
 # This file is part of pysqlite.
 #

Modified: python/trunk/Modules/_sqlite/cache.c
==============================================================================
--- python/trunk/Modules/_sqlite/cache.c	(original)
+++ python/trunk/Modules/_sqlite/cache.c	Fri Mar 28 21:08:36 2008
@@ -1,6 +1,6 @@
 /* cache .c - a LRU cache
  *
- * Copyright (C) 2004-2006 Gerhard Häring <gh at ghaering.de>
+ * Copyright (C) 2004-2007 Gerhard Häring <gh at ghaering.de>
  *
  * This file is part of pysqlite.
  *

Modified: python/trunk/Modules/_sqlite/cache.h
==============================================================================
--- python/trunk/Modules/_sqlite/cache.h	(original)
+++ python/trunk/Modules/_sqlite/cache.h	Fri Mar 28 21:08:36 2008
@@ -1,6 +1,6 @@
 /* cache.h - definitions for the LRU cache
  *
- * Copyright (C) 2004-2006 Gerhard Häring <gh at ghaering.de>
+ * Copyright (C) 2004-2007 Gerhard Häring <gh at ghaering.de>
  *
  * This file is part of pysqlite.
  *

Modified: python/trunk/Modules/_sqlite/cursor.c
==============================================================================
--- python/trunk/Modules/_sqlite/cursor.c	(original)
+++ python/trunk/Modules/_sqlite/cursor.c	Fri Mar 28 21:08:36 2008
@@ -424,10 +424,14 @@
     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;
@@ -592,7 +596,7 @@
 
         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;
         }

Modified: python/trunk/Modules/_sqlite/prepare_protocol.h
==============================================================================
--- python/trunk/Modules/_sqlite/prepare_protocol.h	(original)
+++ python/trunk/Modules/_sqlite/prepare_protocol.h	Fri Mar 28 21:08:36 2008
@@ -1,6 +1,6 @@
 /* prepare_protocol.h - the protocol for preparing values for SQLite
  *
- * Copyright (C) 2005 Gerhard Häring <gh at ghaering.de>
+ * Copyright (C) 2005-2007 Gerhard Häring <gh at ghaering.de>
  *
  * This file is part of pysqlite.
  *

Modified: python/trunk/Modules/_sqlite/row.h
==============================================================================
--- python/trunk/Modules/_sqlite/row.h	(original)
+++ python/trunk/Modules/_sqlite/row.h	Fri Mar 28 21:08:36 2008
@@ -1,6 +1,6 @@
 /* row.h - an enhanced tuple for database rows
  *
- * Copyright (C) 2005 Gerhard Häring <gh at ghaering.de>
+ * Copyright (C) 2005-2007 Gerhard Häring <gh at ghaering.de>
  *
  * This file is part of pysqlite.
  *

Modified: python/trunk/Modules/_sqlite/statement.c
==============================================================================
--- python/trunk/Modules/_sqlite/statement.c	(original)
+++ python/trunk/Modules/_sqlite/statement.c	Fri Mar 28 21:08:36 2008
@@ -96,7 +96,7 @@
     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;
@@ -108,6 +108,7 @@
     Py_ssize_t buflen;
     PyObject* stringval;
     parameter_type paramtype;
+    char* c;
 
     if (parameter == Py_None) {
         rc = sqlite3_bind_null(self->st, pos);
@@ -140,6 +141,17 @@
         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);
@@ -197,7 +209,7 @@
     }
 }
 
-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;
@@ -251,11 +263,13 @@
                 }
             }
 
-            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;
             }
         }
@@ -294,11 +308,13 @@
                 }
             }
 
-            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;
            }
         }

Modified: python/trunk/Modules/_sqlite/statement.h
==============================================================================
--- python/trunk/Modules/_sqlite/statement.h	(original)
+++ python/trunk/Modules/_sqlite/statement.h	Fri Mar 28 21:08:36 2008
@@ -1,6 +1,6 @@
 /* statement.h - definitions for the statement type
  *
- * Copyright (C) 2005 Gerhard Häring <gh at ghaering.de>
+ * Copyright (C) 2005-2007 Gerhard Häring <gh at ghaering.de>
  *
  * This file is part of pysqlite.
  *
@@ -46,8 +46,8 @@
 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);

Modified: python/trunk/Modules/_sqlite/util.h
==============================================================================
--- python/trunk/Modules/_sqlite/util.h	(original)
+++ python/trunk/Modules/_sqlite/util.h	Fri Mar 28 21:08:36 2008
@@ -1,6 +1,6 @@
 /* util.h - various utility functions
  *
- * Copyright (C) 2005-2006 Gerhard Häring <gh at ghaering.de>
+ * Copyright (C) 2005-2007 Gerhard Häring <gh at ghaering.de>
  *
  * This file is part of pysqlite.
  *


More information about the Python-checkins mailing list