Project

General

Profile

« Previous | Next » 

Revision 2663

sql.py: DbConn: Added mogrify() and use it in esc_value()

View differences:

lib/sql.py
258 258
                except StopIteration: return None
259 259
    
260 260
    def esc_value(self, value):
261
        module = util.root_module(self.db)
262
        if module == 'psycopg2': str_ = self.db.cursor().mogrify('%s', [value])
263
        elif module == 'MySQLdb':
264
            import _mysql
265
            str_ = _mysql.escape_string(value)
266
        else: raise NotImplementedError("Can't escape value for "+module
267
            +' database')
261
        try: str_ = self.mogrify('%s', [value])
262
        except NotImplementedError, e:
263
            module = util.root_module(self.db)
264
            if module == 'MySQLdb':
265
                import _mysql
266
                str_ = _mysql.escape_string(value)
267
            else: raise e
268 268
        return strings.to_unicode(str_)
269 269
    
270 270
    def esc_name(self, name): return esc_name(self, name) # calls global func
271 271
    
272
    def mogrify(self, query, params=None):
273
        module = util.root_module(self.db)
274
        if module == 'psycopg2': return self.db.cursor().mogrify(query, params)
275
        else: raise NotImplementedError("Can't mogrify query for "+module
276
            +' database')
277
    
272 278
    def run_query(self, query, params=None, cacheable=False, log_level=2,
273 279
        debug_msg_ref=None):
274 280
        '''

Also available in: Unified diff