Revision 1909
Added by Aaron Marcuse-Kubitza almost 13 years ago
lib/sql.py | ||
---|---|---|
5 | 5 |
import warnings |
6 | 6 |
|
7 | 7 |
import exc |
8 |
import dicts |
|
8 | 9 |
import iters |
9 | 10 |
from Proxy import Proxy |
10 | 11 |
import rand |
... | ... | |
74 | 75 |
def db_config_str(db_config): |
75 | 76 |
return db_config['engine']+' database '+db_config['database'] |
76 | 77 |
|
77 |
def _query_lookup(query, params): return (query, util.cast(tuple, params))
|
|
78 |
def _query_lookup(query, params): return (query, dicts.make_hashable(params))
|
|
78 | 79 |
|
79 | 80 |
log_debug_none = lambda msg: None |
80 | 81 |
|
... | ... | |
86 | 87 |
|
87 | 88 |
self.__db = None |
88 | 89 |
self.pkeys = {} |
89 |
self.index_cols = {} |
|
90 | 90 |
self.query_results = {} |
91 | 91 |
|
92 | 92 |
def __getattr__(self, name): |
... | ... | |
330 | 330 |
constraint or a UNIQUE index, use this function.''' |
331 | 331 |
check_name(table) |
332 | 332 |
check_name(index) |
333 |
lookup = (table, index) |
|
334 |
if lookup not in db.index_cols: |
|
335 |
module = util.root_module(db.db) |
|
336 |
if module == 'psycopg2': |
|
337 |
db.index_cols[lookup] = list(values(run_query(db, '''\ |
|
333 |
module = util.root_module(db.db) |
|
334 |
if module == 'psycopg2': |
|
335 |
return list(values(run_query(db, '''\ |
|
338 | 336 |
SELECT attname |
339 | 337 |
FROM |
340 | 338 |
( |
... | ... | |
365 | 363 |
) s |
366 | 364 |
ORDER BY attnum |
367 | 365 |
''', |
368 |
{'table': table, 'index': index}))) |
|
369 |
else: raise NotImplementedError("Can't list index columns for "+module+ |
|
370 |
' database') |
|
371 |
return db.index_cols[lookup] |
|
366 |
{'table': table, 'index': index}, cacheable=True))) |
|
367 |
else: raise NotImplementedError("Can't list index columns for "+module+ |
|
368 |
' database') |
|
372 | 369 |
|
373 | 370 |
def constraint_cols(db, table, constraint): |
374 | 371 |
check_name(table) |
Also available in: Unified diff
sql.py: _query_lookup(): Fixed bug where params was cast to a tuple, even though it could also be a dict. index_cols(): Changed to use the connection-wide caching mechanism rather than its own custom cache.