4 usage: %(progname)s [args] 8 import os, sys, string, time, getopt
12 from pyPgSQL
import PgSQL
16 self.
execute(
"select last_value from %s_%s_seq" % (tablename, colname))
22 odb.Connection.__init__(self)
24 self.
_conn = apply(PgSQL.connect, args, kwargs)
30 return Cursor(self._conn.cursor())
35 elif type(str) == type(
""):
36 return string.replace(str,
"'",
"''")
37 elif type(str) == type(1):
40 raise "unknown column data type: %s" % type(str)
43 cursor.execute(
"select tablename from pg_catalog.pg_tables")
44 rows = cursor.fetchall()
51 sql =
"select indexname from pg_catalog.pg_indexes where tablename='%s'" % tableName
53 rows = cursor.fetchall()
54 tables = map(
lambda row: row[0], rows)
58 sql =
"SELECT c.oid, n.nspname, c.relname FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE pg_catalog.pg_table_is_visible(c.oid) AND c.relname = '%s' ORDER BY 2, 3;" % table_name
60 row = cursor.fetchone()
63 sql =
"SELECT a.attname, pg_catalog.format_type(a.atttypid, a.atttypmod), (SELECT substring(d.adsrc for 128) FROM pg_catalog.pg_attrdef d WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef), a.attnotnull, a.attnum FROM pg_catalog.pg_attribute a WHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum" % oid
65 rows = cursor.fetchall()
70 columns[colname] = row
75 invalidAppCols, invalidDBCols = table.checkTable()
76 if not invalidAppCols:
return 79 for colname
in invalidAppCols.keys():
80 col = table.getColumnDef(colname)
84 defs.append(table._colTypeToSQLType(colname, coltype, options))
86 defs = string.join(defs,
", ")
88 sql =
"alter table %s add column " % table.getTableName()
89 sql = sql +
"(" + defs +
")"
def __init__(self, args, kwargs)
def supportsTriggers(self)
def listFieldsDict(self, table_name, cursor)
def auto_increment(self, coltype)
def listIndices(self, tableName, cursor)
def listTables(self, cursor)
def alterTableToMatch(self, table, cursor)
def insert_id(self, tablename, colname)