diff options
| author | David Sommerseth <davids@redhat.com> | 2009-08-05 14:14:30 +0200 |
|---|---|---|
| committer | David Sommerseth <davids@redhat.com> | 2009-08-05 14:14:30 +0200 |
| commit | d598e71ec231bf9c6d94ced992ff2c38b92b0cfa (patch) | |
| tree | de0f82727f659ee86f89c6d86ad3a72ef1086329 /server | |
| parent | 91eb1a18a1c0718d6948529b77caf11db09147c4 (diff) | |
Improved error message on SQL SELECT queries
Diffstat (limited to 'server')
| -rw-r--r-- | server/database.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/server/database.py b/server/database.py index 36eebcc..617798b 100644 --- a/server/database.py +++ b/server/database.py @@ -122,13 +122,16 @@ class Database(object): curs = self.conn.cursor() # Query - sql = "SELECT %s FROM %s %s %s" % ( - ",".join(fields), - table, - joins and "%s" % joins or "", - where and "WHERE %s" % " AND ".join(["%s = %%(%s)s" % (k,k) for (k,v) in where.items()] or "") - ) - curs.execute(sql, where) + try: + sql = "SELECT %s FROM %s %s %s" % ( + ",".join(fields), + table, + joins and "%s" % joins or "", + where and "WHERE %s" % " AND ".join(["%s = %%(%s)s" % (k,k) for (k,v) in where.items()] or "") + ) + curs.execute(sql, where) + except Exception, err: + raise Exception, "** SQL ERROR *** %s\n** SQL ERROR ** Message: %s" % ((sql % where), str(err)) # Extract field names fields = [] |
