Update of /cvsroot/pybot/pybot/pybot
In directory sc8-pr-cvs1:/tmp/cvs-serv22819/pybot
Modified Files:
sqlitedb.py
Log Message:
Introduced support for triggers, constraints, beforecreate,
and aftercreate in SQLiteDB.table().
Index: sqlitedb.py
===================================================================
RCS file: /cvsroot/pybot/pybot/pybot/sqlitedb.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** sqlitedb.py 24 Aug 2003 23:23:16 -0000 1.4
--- sqlitedb.py 25 Aug 2003 14:10:33 -0000 1.5
***************
*** 40,44 ****
self._conn.autocommit = enable
! def table(self, name, fields, oncreate=[]):
"""\
Besides creating tables when they don't exist, this function
--- 40,45 ----
self._conn.autocommit = enable
! def table(self, name, fields, constraints="",
! triggers=[], beforecreate=[], aftercreate=[]):
"""\
Besides creating tables when they don't exist, this function
***************
*** 47,59 ****
"""
cursor = self.cursor()
! # Check that the table exist.
cursor.execute("select * from sqlite_master "
"where type='table' and name=%s", name)
row = cursor.fetchone()
if not row:
# No, it doesn't exist yet.
! cursor.execute("create table %s (%s)" % (name, fields))
! for sql in oncreate: cursor.execute(sql)
! elif getxform(fields) != getfields(name, row.sql):
# It exist, but is invalid. We'll have to fix it.
self.autocommit(0)
--- 48,70 ----
"""
cursor = self.cursor()
! # First, drop old triggers, if existent
! cursor.execute("select name from sqlite_master where "
! "type='trigger' and tbl_name=%s",
! (name,))
! for row in cursor.fetchall():
! cursor.execute("drop trigger %s" % row.name)
! # Now check that the table exist.
cursor.execute("select * from sqlite_master "
"where type='table' and name=%s", name)
row = cursor.fetchone()
+ if constraints:
+ constraints = ","+constraints
if not row:
# No, it doesn't exist yet.
! for sql in beforecreate: cursor.execute(sql)
! cursor.execute("create table %s (%s%s)" %
! (name, fields, constraints))
! for sql in aftercreate: cursor.execute(sql)
! elif getxform(fields+constraints) != getfields(name, row.sql):
# It exist, but is invalid. We'll have to fix it.
self.autocommit(0)
***************
*** 68,78 ****
% (copyfields, copyfields, name))
cursor.execute("drop table %s" % name)
! cursor.execute("create table %s (%s)" % (name, fields))
cursor.execute("insert into %s select %s from temp_table"
% (name, ",".join(newfieldnames)))
cursor.execute("drop table temp_table")
! for sql in oncreate: cursor.execute(sql)
self.commit()
self.autocommit(1)
def __getitem__(self, name):
--- 79,96 ----
% (copyfields, copyfields, name))
cursor.execute("drop table %s" % name)
! for sql in beforecreate: cursor.execute(sql)
! createargs = fields
! if constraints:
! createargs += constraints
! cursor.execute("create table %s (%s)" % (name, createargs))
cursor.execute("insert into %s select %s from temp_table"
% (name, ",".join(newfieldnames)))
cursor.execute("drop table temp_table")
! for sql in aftercreate: cursor.execute(sql)
self.commit()
self.autocommit(1)
+ # Rebuild the triggers
+ for sql in triggers:
+ cursor.execute(sql)
def __getitem__(self, name):
|