Permalink
Browse files

Fixing up just a few things

  • Loading branch information...
1 parent 72e7752 commit d901d8032ae88c8d8f006384c64b55682a776bf3 @coleifer committed Oct 1, 2012
Showing with 19 additions and 22 deletions.
  1. +12 −15 peewee.py
  2. +7 −7 pwiz.py
View
27 peewee.py
@@ -1097,9 +1097,6 @@ def switch(self, model_class=None):
def sql(self, compiler):
raise NotImplementedError()
- def db_execute(self):
- return self.database.execute(se)
-
def execute(self):
raise NotImplementedError
@@ -1432,7 +1429,7 @@ def create_foreign_key(self, model_class, field):
def drop_table(self, model_class, fail_silently=False):
framing = fail_silently and 'DROP TABLE IF EXISTS %s;' or 'DROP TABLE %s;'
- self.execute(framing % self.quote_name(model_class._meta.db_table))
+ self.execute_sql(framing % self.quote(model_class._meta.db_table))
def transaction(self):
return transaction(self)
@@ -1449,12 +1446,12 @@ def _connect(self, database, **kwargs):
return sqlite3.connect(database, **kwargs)
def get_indexes_for_table(self, table):
- res = self.execute('PRAGMA index_list(%s);' % self.quote_name(table))
+ res = self.execute_sql('PRAGMA index_list(%s);' % self.quote(table))
rows = sorted([(r[1], r[2] == 1) for r in res.fetchall()])
return rows
def get_tables(self):
- res = self.execute('select name from sqlite_master where type="table" order by name')
+ res = self.execute_sql('select name from sqlite_master where type="table" order by name')
return [r[0] for r in res.fetchall()]
@@ -1479,23 +1476,23 @@ def _connect(self, database, **kwargs):
def last_insert_id(self, cursor, model):
seq = model._meta.primary_key.sequence
if seq:
- cursor.execute("SELECT CURRVAL('\"%s\"')" % (seq))
+ cursor.execute_sql("SELECT CURRVAL('\"%s\"')" % (seq))
return cursor.fetchone()[0]
elif model._meta.auto_increment:
- cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (
+ cursor.execute_sql("SELECT CURRVAL('\"%s_%s_seq\"')" % (
model._meta.db_table, model._meta.primary_key.db_column))
return cursor.fetchone()[0]
def get_indexes_for_table(self, table):
- res = self.execute("""
+ res = self.execute_sql("""
SELECT c2.relname, i.indisprimary, i.indisunique
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i
WHERE c.relname = %s AND c.oid = i.indrelid AND i.indexrelid = c2.oid
ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname""", (table,))
return sorted([(r[0], r[1]) for r in res.fetchall()])
def get_tables(self):
- res = self.execute("""
+ res = self.execute_sql("""
SELECT c.relname
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
@@ -1506,7 +1503,7 @@ def get_tables(self):
return [row[0] for row in res.fetchall()]
def sequence_exists(self, sequence):
- res = self.execute("""
+ res = self.execute_sql("""
SELECT COUNT(*)
FROM pg_class, pg_namespace
WHERE relkind='S'
@@ -1516,7 +1513,7 @@ def sequence_exists(self, sequence):
def set_search_path(self, *search_path):
path_params = ','.join(['%s'] * len(search_path))
- self.execute('SET search_path TO %s' % path_params, search_path)
+ self.execute_sql('SET search_path TO %s' % path_params, search_path)
class MySQLDatabase(Database):
@@ -1530,7 +1527,7 @@ class MySQLDatabase(Database):
'text': 'LONGTEXT',
}
for_update_support = True
- op_overrides = {LIKE: 'LIKE BINARY'}
+ op_overrides = {OP_LIKE: 'LIKE BINARY'}
quote_char = '`'
subquery_delete_same_table = False
@@ -1569,12 +1566,12 @@ def create_foreign_key(self, model_class, field):
return super(MySQLDatabase, self).create_foreign_key(model_class, field)
def get_indexes_for_table(self, table):
- res = self.execute('SHOW INDEXES IN %s;' % self.quote_name(table))
+ res = self.execute_sql('SHOW INDEXES IN %s;' % self.quote(table))
rows = sorted([(r[2], r[1] == 0) for r in res.fetchall()])
return rows
def get_tables(self):
- res = self.execute('SHOW TABLES;')
+ res = self.execute_sql('SHOW TABLES;')
return [r[0] for r in res.fetchall()]
View
14 pwiz.py
@@ -115,7 +115,7 @@ def get_conn_class(self):
return PostgresqlDatabase
def get_columns(self, table):
- curs = self.conn.execute('select * from %s limit 1' % table)
+ curs = self.conn.execute_sql('select * from %s limit 1' % table)
return dict((c.name, self.reverse_mapping.get(c.type_code, 'UnknownFieldType')) for c in curs.description)
def get_foreign_keys(self, table):
@@ -132,7 +132,7 @@ def get_foreign_keys(self, table):
tc.table_name = %s
'''
fks = []
- for row in self.conn.execute(framing, (table,)):
+ for row in self.conn.execute_sql(framing, (table,)):
fks.append(row)
return fks
@@ -145,7 +145,7 @@ def get_conn_class(self):
return MySQLDatabase
def get_columns(self, table):
- curs = self.conn.execute('select * from %s limit 1' % table)
+ curs = self.conn.execute_sql('select * from %s limit 1' % table)
return dict((r[0], self.reverse_mapping.get(r[1], 'UnknownFieldType')) for r in curs.description)
def get_foreign_keys(self, table):
@@ -157,7 +157,7 @@ def get_foreign_keys(self, table):
AND referenced_table_name IS NOT NULL
AND referenced_column_name IS NOT NULL
'''
- return [row for row in self.conn.execute(framing, (table,))]
+ return [row for row in self.conn.execute_sql(framing, (table,))]
class SqDB(DB):
@@ -194,7 +194,7 @@ def map_col(self, col):
return 'UnknownFieldType'
def get_columns(self, table):
- curs = self.conn.execute('pragma table_info(%s)' % table)
+ curs = self.conn.execute_sql('pragma table_info(%s)' % table)
col_dict = {}
for (_, name, col, not_null, _, is_pk) in curs.fetchall():
# cid, name, type, notnull, dflt_value, pk
@@ -208,7 +208,7 @@ def get_columns(self, table):
def get_foreign_keys(self, table):
fks = []
- curs = self.conn.execute("SELECT sql FROM sqlite_master WHERE tbl_name = ? AND type = ?", [table, "table"])
+ curs = self.conn.execute_sql("SELECT sql FROM sqlite_master WHERE tbl_name = ? AND type = ?", [table, "table"])
table_def = curs.fetchone()[0].strip()
try:
@@ -283,7 +283,7 @@ def introspect(engine, database, **connect):
for column, rel_table, rel_pk in table_fks[table]:
models[table][column] = 'ForeignKeyField'
models[rel_table][rel_pk] = 'PrimaryKeyField'
- col_meta[table][column] = {'to': table_to_model[rel_table]}
+ col_meta[table][column] = {'rel_model': table_to_model[rel_table]}
for column in models[table]:
col_meta[table].setdefault(column, {})

0 comments on commit d901d80

Please sign in to comment.