4 usage: %(progname)s [args] 8 import os, sys, string, time, getopt
18 return self.cursor.lastrowid
23 return self.cursor.execute(sql)
27 odb.Connection.__init__(self)
29 self.
_conn = apply(sqlite.connect, args, kwargs)
36 return Cursor(self._conn.cursor())
41 elif type(str) == type(
""):
42 return string.replace(str,
"'",
"''")
43 elif type(str) == type(1):
46 raise "unknown column data type: %s" % type(str)
50 cursor.execute(
"select name from sqlite_master where type='table'")
51 rows = cursor.fetchall()
53 for row
in rows: tables.append(row[0])
58 def listTriggers(self, cursor):
59 cursor.execute(
"select name from sqlite_master where type='trigger'")
60 rows = cursor.fetchall()
62 for row
in rows: tables.append(row[0])
66 cursor.execute(
"select name from sqlite_master where type='index'")
67 rows = cursor.fetchall()
69 for row
in rows: tables.append(row[0])
73 sql =
"pragma table_info(%s)" % table_name
75 rows = cursor.fetchall()
80 columns[colname] = row
84 sql =
"select sql from sqlite_master where type='table' and name='%s'" % table_name
87 row = cursor.fetchone()
93 tableName = table.getTableName()
94 tmpTableName = tableName +
"_" + str(os.getpid())
96 invalidAppCols, invalidDBCols = table.checkTable(warnflag=0)
103 if not invalidAppCols
and not invalidDBCols:
107 oldcols = self.listFieldsDict(tableName, cursor)
111 newcols = table.getAppColumnList()
112 for colname, coltype, options
in newcols:
113 if oldcols.has_key(colname): tmpcols.append(colname)
115 tmpcolnames = string.join(tmpcols,
",")
122 sql =
"create temporary table %s (%s)" % (tmpTableName, tmpcolnames)
123 statements.append(sql)
125 sql =
"insert into %s select %s from %s" % (tmpTableName, tmpcolnames, tableName)
126 statements.append(sql)
128 sql =
"drop table %s" % tableName
129 statements.append(sql)
131 sql = table._createTableSQL()
132 statements.append(sql)
134 sql =
"insert into %s(%s) select %s from %s" % (tableName, tmpcolnames, tmpcolnames, tmpTableName)
135 statements.append(sql)
137 sql =
"drop table %s" % tmpTableName
138 statements.append(sql)
143 for statement
in statements:
145 cursor.execute(statement)
152 print __doc__ % vars()
154 def main(argv, stdout, environ):
156 optlist, args = getopt.getopt(argv[1:],
"", [
"help",
"test",
"debug"])
162 for (field, val)
in optlist:
163 if field ==
"--help":
166 elif field ==
"--debug":
168 elif field ==
"--test":
176 if __name__ ==
"__main__":
177 main(sys.argv, sys.stdout, os.environ)
def supportsTriggers(self)
def alterTableToMatch(self, table, cursor)
def insert_id(self, tablename, colname)
def main(argv, stdout, environ)
def listIndices(self, tableName, cursor)
if sql[:6] != "select": warn(repr(sql))
def _tableCreateStatement(self, table_name, cursor)
def listFieldsDict(self, table_name, cursor)
def listTables(self, cursor)
def __init__(self, args, kwargs)