Project

General

Profile

« Previous | Next » 

Revision 131

Added support for multiple database engines. Changed SALVIAS_db input to use user-entered password.

View differences:

sql.py
5 5
import sys
6 6

  
7 7
import ex
8
import util
8 9

  
9 10
def _add_cursor_info(e, cur): ex.add_msg(e, 'query: '+cur.query)
10 11

  
......
114 115
            return last_insert_id(db)
115 116
        except DuplicateKeyException, e:
116 117
            return value(select(db, table, [pkey], {e.col: row[e.col]}))
118

  
119
db_engines = {
120
    'MySQL': ('MySQLdb', {'password': 'passwd', 'database': 'db'}),
121
    'PostgreSQL': ('psycopg2', {}),
122
}
123

  
124
def connect(db_config):
125
    db_config = db_config.copy() # don't modify input!
126
    module, mappings = db_engines[db_config.pop('engine')]
127
    for orig, new in mappings.iteritems(): util.rename_key(db_config, orig, new)
128
    return __import__(module).connect(**db_config)

Also available in: Unified diff