Project

General

Profile

« Previous | Next » 

Revision 2097

sql.py: db_config: Added schemas param. DbConn: Use any schemas db_config value to set search_path.

View differences:

lib/sql.py
73 73

  
74 74
##### Database connections
75 75

  
76
db_config_names = ['engine', 'host', 'user', 'password', 'database']
76
db_config_names = ['engine', 'host', 'user', 'password', 'database', 'schemas']
77 77

  
78 78
db_engines = {
79 79
    'MySQL': ('MySQLdb', {'password': 'passwd', 'database': 'db'}),
......
121 121
        if self.__db == None:
122 122
            # Process db_config
123 123
            db_config = self.db_config.copy() # don't modify input!
124
            schemas = db_config.pop('schemas', None)
124 125
            module_name, mappings = db_engines[db_config.pop('engine')]
125 126
            module = __import__(module_name)
126 127
            _add_module(module)
......
132 133
            self.__db = module.connect(**db_config)
133 134
            
134 135
            # Configure connection
136
            if schemas != None:
137
                schemas = schemas[:] # don't modify input!
138
                schemas.append('current_setting(search_path)')
139
                run_raw_query(self, 'SET search_path = '+(', '.join(schemas)))
135 140
            if self.serializable: run_raw_query(self,
136 141
                'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE')
137 142
        

Also available in: Unified diff