Project

General

Profile

« Previous | Next » 

Revision 92

Now allow empty rows. Added support for select statement limit.

View differences:

scripts/lib/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
scripts/lib/xpath.py
79 79
            if parser.str_('"'):
80 80
                value = parser.re(r'[^"]*')
81 81
                parser.str_('"', required=True)
82
            else: value = parser.re(r'[\w.|]*')
82
            else: value = parser.re(r'[\w.]*')
83 83
            set_value(tree, value)
84 84
        
85 85
        # Expand * abbrs

Also available in: Unified diff