Project

General

Profile

« Previous | Next » 

Revision 646

bin/map: Print a message when a database is successfully connected to

View differences:

lib/sql.py
196 196
    global DatabaseErrors
197 197
    DatabaseErrors = tuple(DatabaseErrors_set)
198 198

  
199
def connect(db_config):
199
def connect(db_config, serializable=True):
200 200
    db_config = db_config.copy() # don't modify input!
201 201
    module_name, mappings = db_engines[db_config.pop('engine')]
202 202
    module = __import__(module_name)
......
204 204
    for orig, new in mappings.iteritems():
205 205
        try: util.rename_key(db_config, orig, new)
206 206
        except KeyError: pass
207
    return module.connect(**db_config)
207
    db = module.connect(**db_config)
208
    if serializable:
209
        run_query(db, 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE')
210
    return db
211

  
212
def db_config_str(db_config):
213
    return db_config['engine']+' database '+db_config['database']
bin/map
48 48
        if in_is_db or not out_is_db: usage_err()
49 49
        else: map_paths = [None]
50 50
    
51
    def connect_db(db_config):
52
        db = sql.connect(db_config)
53
        sys.stderr.write('Connected to '+sql.db_config_str(db_config)+'\n')
54
        return db
55
    
51 56
    def process_input(root, process_row, map_path):
52 57
        '''Inputs datasource to XML tree, mapping if needed'''
53 58
        # Load map header
......
117 122
                if metadata_value(in_) == None:
118 123
                    mappings[i] = (xpath.path2xml(in_root+'/'+in_), out)
119 124
            
120
            in_db = sql.connect(in_db_config)
125
            in_db = connect_db(in_db_config)
121 126
            in_pkeys = {}
122 127
            def get_value(in_, row):
123 128
                pkey, = row
......
163 168
        from psycopg2.extensions import ISOLATION_LEVEL_SERIALIZABLE
164 169
        import db_xml
165 170
        
166
        out_db = sql.connect(out_db_config)
167
        out_db.set_isolation_level(ISOLATION_LEVEL_SERIALIZABLE)
171
        out_db = connect_db(out_db_config)
168 172
        out_pkeys = {}
169 173
        try:
170 174
            if test: sql.empty_db(out_db)

Also available in: Unified diff