Revision 464
Added by Aaron Marcuse-Kubitza almost 13 years ago
lib/sql.py | ||
---|---|---|
103 | 103 |
elif module == 'MySQLdb': return db.insert_id() |
104 | 104 |
else: return None |
105 | 105 |
|
106 |
def constraint_cols(db, table, constraint): |
|
107 |
check_name(table) |
|
108 |
check_name(constraint) |
|
109 |
module = util.root_module(db) |
|
110 |
if module == 'psycopg2': |
|
111 |
return list(values(run_query(db, '''\ |
|
112 |
SELECT attname |
|
113 |
FROM pg_constraint |
|
114 |
JOIN pg_class ON pg_class.oid = conrelid |
|
115 |
JOIN pg_attribute ON attrelid = conrelid AND attnum = ANY (conkey) |
|
116 |
WHERE |
|
117 |
relname = %(table)s |
|
118 |
AND conname = %(constraint)s |
|
119 |
ORDER BY attnum |
|
120 |
''', |
|
121 |
{'table': table, 'constraint': constraint}))) |
|
122 |
else: raise NotImplementedError("Can't list constraint columns for "+module+ |
|
123 |
' database') |
|
124 |
|
|
106 | 125 |
def try_insert(db, table, row): |
107 | 126 |
try: return with_savepoint(db, lambda: insert(db, table, row)) |
108 | 127 |
except Exception, e: |
Also available in: Unified diff
sql.py: Added constraint_cols() to get columns of a constraint for use in determining the columns for a DuplicateKeyException