Revision 92
Added by Aaron Marcuse-Kubitza over 12 years ago
sql.py | ||
---|---|---|
55 | 55 |
run_query(db, 'RELEASE SAVEPOINT '+savepoint) |
56 | 56 |
return return_val |
57 | 57 |
|
58 |
def select(db, table, fields, conds): |
|
58 |
def select(db, table, fields, conds, limit=None): |
|
59 |
assert type(limit) == int |
|
59 | 60 |
check_name(table) |
60 | 61 |
map(check_name, fields) |
61 | 62 |
map(check_name, conds.keys()) |
... | ... | |
69 | 70 |
query = 'SELECT '+', '.join(fields)+' FROM '+table |
70 | 71 |
if conds != {}: |
71 | 72 |
query += ' WHERE '+' AND '.join(map(cond, conds.iteritems())) |
73 |
if limit != None: query += ' LIMIT '+str(limit) |
|
72 | 74 |
return run_query(db, query, conds.values()) |
73 | 75 |
|
74 | 76 |
def insert(db, table, row): |
... | ... | |
100 | 102 |
return col(run_query(db, 'SELECT * FROM '+table+' LIMIT 0'), 0) |
101 | 103 |
|
102 | 104 |
def get(db, table, row, pkey, create=False, row_ct_ref=None): |
103 |
if row == []: raise EmptyRowException(table) # nothing to insert/filter by |
|
104 |
try: return value(select(db, table, [pkey], row)) |
|
105 |
try: return value(select(db, table, [pkey], row, 1)) |
|
105 | 106 |
except StopIteration: |
106 | 107 |
if not create: raise |
107 | 108 |
# Insert new row |
Also available in: Unified diff
Now allow empty rows. Added support for select statement limit.