[pypy-svn] r73029 - pypy/pysqlite2

arigo at codespeak.net arigo at codespeak.net
Sun Mar 28 17:27:54 CEST 2010


Author: arigo
Date: Sun Mar 28 17:27:52 2010
New Revision: 73029

Modified:
   pypy/pysqlite2/dbapi2.py
Log:
* Never return None from _get_exception(), because that cannot be
  raised.  Instead, raise ValueError directly if we get SQLITE_OK.
* Pass the exception return code to _get_exception() in all cases.


Modified: pypy/pysqlite2/dbapi2.py
==============================================================================
--- pypy/pysqlite2/dbapi2.py	(original)
+++ pypy/pysqlite2/dbapi2.py	Sun Mar 28 17:27:52 2010
@@ -284,7 +284,7 @@
         error_message = sqlite.sqlite3_errmsg(self.db)
 
         if error_code == SQLITE_OK:
-            return None
+            raise ValueError("error signalled but got SQLITE_OK")
         elif error_code in (SQLITE_INTERNAL, SQLITE_NOTFOUND):
             exc = InternalError
         elif error_code == SQLITE_NOMEM:
@@ -371,10 +371,10 @@
                 next_char = c_char_p()
                 ret = sqlite.sqlite3_prepare_v2(self.db, sql, -1, byref(statement), next_char)
                 if ret != SQLITE_OK:
-                    raise self._get_exception()
+                    raise self._get_exception(ret)
                 ret = sqlite.sqlite3_step(statement)
                 if ret != SQLITE_DONE:
-                    raise self._get_exception()
+                    raise self._get_exception(ret)
             finally:
                 sqlite.sqlite3_finalize(statement)
 
@@ -389,10 +389,10 @@
             next_char = c_char_p()
             ret = sqlite.sqlite3_prepare_v2(self.db, sql, -1, byref(statement), next_char)
             if ret != SQLITE_OK:
-                raise self._get_exception()
+                raise self._get_exception(ret)
             ret = sqlite.sqlite3_step(statement)
             if ret != SQLITE_DONE:
-                raise self._get_exception()
+                raise self._get_exception(ret)
         finally:
             sqlite.sqlite3_finalize(statement)
 
@@ -407,10 +407,10 @@
             next_char = c_char_p()
             ret = sqlite.sqlite3_prepare_v2(self.db, sql, -1, byref(statement), next_char)
             if ret != SQLITE_OK:
-                raise self._get_exception()
+                raise self._get_exception(ret)
             ret = sqlite.sqlite3_step(statement)
             if ret != SQLITE_DONE:
-                raise self._get_exception()
+                raise self._get_exception(ret)
         finally:
             sqlite.sqlite3_finalize(statement)
 
@@ -443,7 +443,7 @@
         self.closed = True
         ret = sqlite.sqlite3_close(self.db)
         if ret != SQLITE_OK:
-            raise self._get_exception()
+            raise self._get_exception(ret)
 
     def create_collation(self, name, callback):
         raise NotImplementedError
@@ -469,7 +469,7 @@
                                              cast(None, STEP),
                                              cast(None, FINAL))
         if ret != SQLITE_OK:
-            raise self._get_exception()
+            raise self._get_exception(ret)
 
     def create_aggregate(self, name, num_args, cls):
         raise NotImplementedError
@@ -529,7 +529,7 @@
             self.statement.set_params(params)
             ret = sqlite.sqlite3_step(self.statement.statement)
             if ret != SQLITE_DONE:
-                raise self.connection._get_exception()
+                raise self.connection._get_exception(ret)
             self.rowcount += sqlite.sqlite3_changes(self.connection.db)
 
         return self
@@ -548,13 +548,13 @@
                 raise ProgrammingError, "Incomplete statement '%s'" % next_char.value
             ret = sqlite.sqlite3_prepare_v2(self.connection.db, next_char, -1, byref(statement), byref(next_char))
             if ret != SQLITE_OK:
-                raise self.connection._get_exception()
+                raise self.connection._get_exception(ret)
             if statement.value is None:
                 break
             ret = sqlite.sqlite3_step(statement)
             sqlite.sqlite3_finalize(statement)
             if ret not in (SQLITE_OK, SQLITE_DONE, SQLITE_ROW):
-                raise self.connection._get_exception()
+                raise self.connection._get_exception(ret)
             if next_char.value is None:
                 break
 
@@ -637,7 +637,7 @@
             self.kind = "DQL"
 
         if ret != SQLITE_OK:
-            raise self.con._get_exception()
+            raise self.con._get_exception(ret)
         self.con._remember_statement(self)
         if _check_remaining_sql(next_char.value):
             raise Warning, "One and only one statement required"
@@ -701,7 +701,7 @@
     def set_params(self, params):
         ret = sqlite.sqlite3_reset(self.statement)
         if ret != SQLITE_OK:
-            raise self.con._get_exception()
+            raise self.con._get_exception(ret)
 
         if params is None:
             if sqlite.sqlite3_bind_parameter_count(self.statement) != 0:
@@ -754,7 +754,7 @@
             return
         elif ret == SQLITE_ERROR:
             sqlite.sqlite3_reset(self.statement)
-            exc = self.con._get_exception()
+            exc = self.con._get_exception(ret)
             raise exc
         else:
             assert ret == SQLITE_ROW



More information about the Pypy-commit mailing list