Commits

Mike Bayer  committed 21e64c1

exceptions added
postgres last_inserted_ids will raise an error unless OID's are turned on
(INSERT with PK defaults + no OIDs wont fail unless this method is called)

  • Participants
  • Parent commits daa14da

Comments (0)

Files changed (3)

File lib/sqlalchemy/databases/information_schema.py

 import sqlalchemy.schema as schema
 import sqlalchemy.ansisql as ansisql
 import sqlalchemy.types as sqltypes
+from sqlalchemy.exceptions import *
 from sqlalchemy import *
 from sqlalchemy.ansisql import *
 
             try:
                 gen_tbl = globals()['gen_'+name]
             except KeyError:
-                raise AttributeError('information_schema table %s not found' % name)
+                raise ArgumentError('information_schema table %s not found' % name)
             self.cache[name] = gen_tbl.toengine(self.engine)
         return self.cache[name]
 

File lib/sqlalchemy/databases/postgres.py

 import sqlalchemy.schema as schema
 import sqlalchemy.ansisql as ansisql
 import sqlalchemy.types as sqltypes
+from sqlalchemy.exceptions import *
 from sqlalchemy import *
-import sqlalchemy.databases.information_schema as ischema
+import information_schema as ischema
 
 try:
     import psycopg2 as psycopg
         self.use_oids = use_oids
         if module is None:
             if psycopg is None:
-                raise "Couldnt locate psycopg1 or psycopg2: specify postgres module argument"
+                raise ArgumentError("Couldnt locate psycopg1 or psycopg2: specify postgres module argument")
             self.module = psycopg
         else:
             self.module = module
         else:
             return sqltypes.adapt_type(typeobj, pg1_colspecs)
 
-    def last_inserted_ids(self):
-        return self.context.last_inserted_ids
-
     def compiler(self, statement, bindparams, **kwargs):
         return PGCompiler(self, statement, bindparams, **kwargs)
 
         return self._default_schema_name
         
     def last_inserted_ids(self):
-        return self.context.last_inserted_ids
+        if self.context.last_inserted_ids is None:
+            raise InvalidRequestError("no INSERT executed, or cant use cursor.lastrowid without Postgres OIDs enabled")
+        else:
+            return self.context.last_inserted_ids
 
     def oid_column_name(self):
         if self.use_oids:
     def post_exec(self, proxy, compiled, parameters, **kwargs):
         if getattr(compiled, "isinsert", False) and self.context.last_inserted_ids is None:
             if not self.use_oids:
-                raise "cant use cursor.lastrowid without OIDs enabled"
+                pass
+                # will raise invalid error when they go to get them
             else:
                 table = compiled.statement.table
                 cursor = proxy()

File lib/sqlalchemy/databases/sqlite.py

 import sqlalchemy.schema as schema
 import sqlalchemy.ansisql as ansisql
 import sqlalchemy.types as sqltypes
+from sqlalchemy.exceptions import *
 from sqlalchemy.ansisql import *
 import datetime,time
 
 class SQLiteSQLEngine(ansisql.ANSISQLEngine):
     def __init__(self, opts, **params):
         if sqlite is None:
-            raise "Couldn't import pysqlite2"
+            raise ArgumentError("Couldn't import sqlite or pysqlite2")
         self.filename = opts.pop('filename', ':memory:')
         self.opts = opts or {}
         params['poolclass'] = sqlalchemy.pool.SingletonThreadPool