Skip to content
This repository
Browse code

Fixing up just a few things

  • Loading branch information...
commit d901d8032ae88c8d8f006384c64b55682a776bf3 1 parent 72e7752
Charles Leifer authored October 01, 2012

Showing 2 changed files with 19 additions and 22 deletions. Show diff stats Hide diff stats

  1. 27  peewee.py
  2. 14  pwiz.py
27  peewee.py
@@ -1097,9 +1097,6 @@ def switch(self, model_class=None):
1097 1097
     def sql(self, compiler):
1098 1098
         raise NotImplementedError()
1099 1099
 
1100  
-    def db_execute(self):
1101  
-        return self.database.execute(se)
1102  
-
1103 1100
     def execute(self):
1104 1101
         raise NotImplementedError
1105 1102
 
@@ -1432,7 +1429,7 @@ def create_foreign_key(self, model_class, field):
1432 1429
 
1433 1430
     def drop_table(self, model_class, fail_silently=False):
1434 1431
         framing = fail_silently and 'DROP TABLE IF EXISTS %s;' or 'DROP TABLE %s;'
1435  
-        self.execute(framing % self.quote_name(model_class._meta.db_table))
  1432
+        self.execute_sql(framing % self.quote(model_class._meta.db_table))
1436 1433
 
1437 1434
     def transaction(self):
1438 1435
         return transaction(self)
@@ -1449,12 +1446,12 @@ def _connect(self, database, **kwargs):
1449 1446
         return sqlite3.connect(database, **kwargs)
1450 1447
 
1451 1448
     def get_indexes_for_table(self, table):
1452  
-        res = self.execute('PRAGMA index_list(%s);' % self.quote_name(table))
  1449
+        res = self.execute_sql('PRAGMA index_list(%s);' % self.quote(table))
1453 1450
         rows = sorted([(r[1], r[2] == 1) for r in res.fetchall()])
1454 1451
         return rows
1455 1452
 
1456 1453
     def get_tables(self):
1457  
-        res = self.execute('select name from sqlite_master where type="table" order by name')
  1454
+        res = self.execute_sql('select name from sqlite_master where type="table" order by name')
1458 1455
         return [r[0] for r in res.fetchall()]
1459 1456
 
1460 1457
 
@@ -1479,15 +1476,15 @@ def _connect(self, database, **kwargs):
1479 1476
     def last_insert_id(self, cursor, model):
1480 1477
         seq = model._meta.primary_key.sequence
1481 1478
         if seq:
1482  
-            cursor.execute("SELECT CURRVAL('\"%s\"')" % (seq))
  1479
+            cursor.execute_sql("SELECT CURRVAL('\"%s\"')" % (seq))
1483 1480
             return cursor.fetchone()[0]
1484 1481
         elif model._meta.auto_increment:
1485  
-            cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (
  1482
+            cursor.execute_sql("SELECT CURRVAL('\"%s_%s_seq\"')" % (
1486 1483
                 model._meta.db_table, model._meta.primary_key.db_column))
1487 1484
             return cursor.fetchone()[0]
1488 1485
 
1489 1486
     def get_indexes_for_table(self, table):
1490  
-        res = self.execute("""
  1487
+        res = self.execute_sql("""
1491 1488
             SELECT c2.relname, i.indisprimary, i.indisunique
1492 1489
             FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i
1493 1490
             WHERE c.relname = %s AND c.oid = i.indrelid AND i.indexrelid = c2.oid
@@ -1495,7 +1492,7 @@ def get_indexes_for_table(self, table):
1495 1492
         return sorted([(r[0], r[1]) for r in res.fetchall()])
1496 1493
 
1497 1494
     def get_tables(self):
1498  
-        res = self.execute("""
  1495
+        res = self.execute_sql("""
1499 1496
             SELECT c.relname
1500 1497
             FROM pg_catalog.pg_class c
1501 1498
             LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
@@ -1506,7 +1503,7 @@ def get_tables(self):
1506 1503
         return [row[0] for row in res.fetchall()]
1507 1504
 
1508 1505
     def sequence_exists(self, sequence):
1509  
-        res = self.execute("""
  1506
+        res = self.execute_sql("""
1510 1507
             SELECT COUNT(*)
1511 1508
             FROM pg_class, pg_namespace
1512 1509
             WHERE relkind='S'
@@ -1516,7 +1513,7 @@ def sequence_exists(self, sequence):
1516 1513
 
1517 1514
     def set_search_path(self, *search_path):
1518 1515
         path_params = ','.join(['%s'] * len(search_path))
1519  
-        self.execute('SET search_path TO %s' % path_params, search_path)
  1516
+        self.execute_sql('SET search_path TO %s' % path_params, search_path)
1520 1517
 
1521 1518
 
1522 1519
 class MySQLDatabase(Database):
@@ -1530,7 +1527,7 @@ class MySQLDatabase(Database):
1530 1527
         'text': 'LONGTEXT',
1531 1528
     }
1532 1529
     for_update_support = True
1533  
-    op_overrides = {LIKE: 'LIKE BINARY'}
  1530
+    op_overrides = {OP_LIKE: 'LIKE BINARY'}
1534 1531
     quote_char = '`'
1535 1532
     subquery_delete_same_table = False
1536 1533
 
@@ -1569,12 +1566,12 @@ def create_foreign_key(self, model_class, field):
1569 1566
         return super(MySQLDatabase, self).create_foreign_key(model_class, field)
1570 1567
 
1571 1568
     def get_indexes_for_table(self, table):
1572  
-        res = self.execute('SHOW INDEXES IN %s;' % self.quote_name(table))
  1569
+        res = self.execute_sql('SHOW INDEXES IN %s;' % self.quote(table))
1573 1570
         rows = sorted([(r[2], r[1] == 0) for r in res.fetchall()])
1574 1571
         return rows
1575 1572
 
1576 1573
     def get_tables(self):
1577  
-        res = self.execute('SHOW TABLES;')
  1574
+        res = self.execute_sql('SHOW TABLES;')
1578 1575
         return [r[0] for r in res.fetchall()]
1579 1576
 
1580 1577
 
14  pwiz.py
@@ -115,7 +115,7 @@ def get_conn_class(self):
115 115
         return PostgresqlDatabase
116 116
 
117 117
     def get_columns(self, table):
118  
-        curs = self.conn.execute('select * from %s limit 1' % table)
  118
+        curs = self.conn.execute_sql('select * from %s limit 1' % table)
119 119
         return dict((c.name, self.reverse_mapping.get(c.type_code, 'UnknownFieldType')) for c in curs.description)
120 120
 
121 121
     def get_foreign_keys(self, table):
@@ -132,7 +132,7 @@ def get_foreign_keys(self, table):
132 132
                 tc.table_name = %s
133 133
         '''
134 134
         fks = []
135  
-        for row in self.conn.execute(framing, (table,)):
  135
+        for row in self.conn.execute_sql(framing, (table,)):
136 136
             fks.append(row)
137 137
         return fks
138 138
 
@@ -145,7 +145,7 @@ def get_conn_class(self):
145 145
         return MySQLDatabase
146 146
 
147 147
     def get_columns(self, table):
148  
-        curs = self.conn.execute('select * from %s limit 1' % table)
  148
+        curs = self.conn.execute_sql('select * from %s limit 1' % table)
149 149
         return dict((r[0], self.reverse_mapping.get(r[1], 'UnknownFieldType')) for r in curs.description)
150 150
 
151 151
     def get_foreign_keys(self, table):
@@ -157,7 +157,7 @@ def get_foreign_keys(self, table):
157 157
                 AND referenced_table_name IS NOT NULL
158 158
                 AND referenced_column_name IS NOT NULL
159 159
         '''
160  
-        return [row for row in self.conn.execute(framing, (table,))]
  160
+        return [row for row in self.conn.execute_sql(framing, (table,))]
161 161
 
162 162
 
163 163
 class SqDB(DB):
@@ -194,7 +194,7 @@ def map_col(self, col):
194 194
             return 'UnknownFieldType'
195 195
 
196 196
     def get_columns(self, table):
197  
-        curs = self.conn.execute('pragma table_info(%s)' % table)
  197
+        curs = self.conn.execute_sql('pragma table_info(%s)' % table)
198 198
         col_dict = {}
199 199
         for (_, name, col, not_null, _, is_pk) in curs.fetchall():
200 200
             # cid, name, type, notnull, dflt_value, pk
@@ -208,7 +208,7 @@ def get_columns(self, table):
208 208
     def get_foreign_keys(self, table):
209 209
         fks = []
210 210
 
211  
-        curs = self.conn.execute("SELECT sql FROM sqlite_master WHERE tbl_name = ? AND type = ?", [table, "table"])
  211
+        curs = self.conn.execute_sql("SELECT sql FROM sqlite_master WHERE tbl_name = ? AND type = ?", [table, "table"])
212 212
         table_def = curs.fetchone()[0].strip()
213 213
 
214 214
         try:
@@ -283,7 +283,7 @@ def introspect(engine, database, **connect):
283 283
         for column, rel_table, rel_pk in table_fks[table]:
284 284
             models[table][column] = 'ForeignKeyField'
285 285
             models[rel_table][rel_pk] = 'PrimaryKeyField'
286  
-            col_meta[table][column] = {'to': table_to_model[rel_table]}
  286
+            col_meta[table][column] = {'rel_model': table_to_model[rel_table]}
287 287
 
288 288
         for column in models[table]:
289 289
             col_meta[table].setdefault(column, {})

0 notes on commit d901d80

Please sign in to comment.
Something went wrong with that request. Please try again.