Revision 15
Added by Aaron Marcuse-Kubitza about 13 years ago
db_util.py | ||
---|---|---|
36 | 36 |
raise |
37 | 37 |
return cur |
38 | 38 |
|
39 |
def col(cur, idx): return cur.description[idx][0] |
|
40 |
|
|
39 | 41 |
def row(cur): return iter(lambda: cur.fetchone(), None).next() |
40 | 42 |
|
41 | 43 |
def value(cur): return row(cur)[0] |
... | ... | |
52 | 54 |
return return_val |
53 | 55 |
|
54 | 56 |
def select(db, table, fields, conds): |
55 |
for field in fields: check_name(field) |
|
56 |
for col in conds.keys(): check_name(col) |
|
57 |
check_name(table) |
|
58 |
map(check_name, fields) |
|
59 |
map(check_name, conds.keys()) |
|
57 | 60 |
def cond(entry): |
58 | 61 |
col, value = entry |
59 | 62 |
cond_ = col+' ' |
... | ... | |
67 | 70 |
def insert(db, table, row): |
68 | 71 |
check_name(table) |
69 | 72 |
cols = row.keys() |
70 |
for col in cols: check_name(col)
|
|
73 |
map(check_name, cols)
|
|
71 | 74 |
return run_query(db, 'INSERT INTO '+table+' ('+', '.join(cols) |
72 | 75 |
+') VALUES ('+', '.join(['%s']*len(cols))+')', row.values()) |
73 | 76 |
|
... | ... | |
85 | 88 |
if match: raise NullValueException(match.group(1), ex) |
86 | 89 |
raise # no specific exception raised |
87 | 90 |
|
91 |
def pkey(db, table): # Assumed to be first column in table |
|
92 |
check_name(table) |
|
93 |
return col(run_query(db, 'SELECT * FROM '+table+' LIMIT 0'), 0) |
|
94 |
|
|
88 | 95 |
def insert_or_get(db, table, row, pkey, row_ct_ref=None): |
89 | 96 |
try: return value(select(db, table, [pkey], row)) |
90 | 97 |
except StopIteration: |
Also available in: Unified diff
Changed xml2db to use the first column in a table as its primary key