Permalink
Browse files

Added support for the new Firebird driver (fdb) but will fall back to…

… kinterbasdb if it's not present. Added code to properly return a sequence value from an insert, also added a NULL query to prevent a segmentation fault with fdb 0.9.9
  • Loading branch information...
1 parent 0fbe0da commit 206f799ab9afe670ac6bab55ce053d44b0c88050 Ben Hanna committed Jan 14, 2013
Showing with 16 additions and 5 deletions.
  1. +16 −5 web/db.py
View
21 web/db.py 100644 → 100755
@@ -1037,11 +1037,8 @@ class FirebirdDB(DB):
"""Firebird Database.
"""
def __init__(self, **keywords):
- try:
- import kinterbasdb as db
- except Exception:
- db = None
- pass
+ db = import_driver(["fdb", "kinterbasdb"], preferred=keywords.pop('driver', None))
+
if 'pw' in keywords:
keywords['password'] = keywords.pop('pw')
keywords['database'] = keywords.pop('db')
@@ -1066,6 +1063,20 @@ def sql_clauses(self, what, tables, where, group, order, limit, offset):
('GROUP BY', group),
('ORDER BY', order)
)
+
+ def _process_insert_query(self, query, tablename, seqname):
+ # Firebird doesn't have an accurate way to know what a
+ # table's sequence is as autoincrementing fields are
+ # implemented using generators and triggers
+
+ # If we know the sequence then return the value
+ if seqname:
+ query.append(' RETURNING %s' % seqname)
+ return query
+
+ # 'fdb' currently causes a segmentation fault when calling fetchone()
+ # immediately after an insert. This NULL query fixes the problem.
+ return query, SQLQuery("SELECT NULL FROM RDB$DATABASE;")
class MSSQLDB(DB):
def __init__(self, **keywords):

0 comments on commit 206f799

Please sign in to comment.