server/sqlutils.py
changeset 4322 f65743cc53e4
parent 4314 e12ee4a009bc
child 4342 b4e186da08f2
equal deleted inserted replaced
4321:80b455066c9a 4322:f65743cc53e4
   312     cnx.create_function("TEXT_LIMIT_SIZE", 2, limit_size2)
   312     cnx.create_function("TEXT_LIMIT_SIZE", 2, limit_size2)
   313     import yams.constraints
   313     import yams.constraints
   314     if hasattr(yams.constraints, 'patch_sqlite_decimal'):
   314     if hasattr(yams.constraints, 'patch_sqlite_decimal'):
   315         yams.constraints.patch_sqlite_decimal()
   315         yams.constraints.patch_sqlite_decimal()
   316 
   316 
       
   317     def fspath(eid, etype, attr):
       
   318         try:
       
   319             cu = cnx.cursor()
       
   320             cu.execute('SELECT X.cw_%s FROM cw_%s as X '
       
   321                        'WHERE X.cw_eid=%%(eid)s' % (attr, etype),
       
   322                        {'eid': eid})
       
   323             return cu.fetchone()[0]
       
   324         except:
       
   325             import traceback
       
   326             traceback.print_exc()
       
   327             raise
       
   328     cnx.create_function('fspath', 3, fspath)
       
   329 
       
   330     def _fsopen(fspath):
       
   331         if fspath:
       
   332             try:
       
   333                 return buffer(file(fspath).read())
       
   334             except:
       
   335                 import traceback
       
   336                 traceback.print_exc()
       
   337                 raise
       
   338     cnx.create_function('_fsopen', 1, _fsopen)
       
   339 
   317 
   340 
   318 sqlite_hooks = SQL_CONNECT_HOOKS.setdefault('sqlite', [])
   341 sqlite_hooks = SQL_CONNECT_HOOKS.setdefault('sqlite', [])
   319 sqlite_hooks.append(init_sqlite_connexion)
   342 sqlite_hooks.append(init_sqlite_connexion)
   320 
   343 
   321 def init_cnx(driver, cnx):
   344 def init_cnx(driver, cnx):