57 from cubicweb.utils import QueryCache |
57 from cubicweb.utils import QueryCache |
58 from cubicweb.schema import VIRTUAL_RTYPES |
58 from cubicweb.schema import VIRTUAL_RTYPES |
59 from cubicweb.cwconfig import CubicWebNoAppConfiguration |
59 from cubicweb.cwconfig import CubicWebNoAppConfiguration |
60 from cubicweb.server import hook |
60 from cubicweb.server import hook |
61 from cubicweb.server.utils import crypt_password, eschema_eid, verify_and_update |
61 from cubicweb.server.utils import crypt_password, eschema_eid, verify_and_update |
62 from cubicweb.server.sqlutils import SQL_PREFIX, SQLAdapterMixIn |
62 from cubicweb.server.sqlutils import SQL_PREFIX, SQLAdapterMixIn, SqliteCnxLoggingWrapper |
63 from cubicweb.server.rqlannotation import set_qdata |
63 from cubicweb.server.rqlannotation import set_qdata |
64 from cubicweb.server.hook import CleanupDeletedEidsCacheOp |
64 from cubicweb.server.hook import CleanupDeletedEidsCacheOp |
65 from cubicweb.server.edition import EditedEntity |
65 from cubicweb.server.edition import EditedEntity |
66 from cubicweb.server.sources import AbstractSource, dbg_st_search, dbg_results |
66 from cubicweb.server.sources import AbstractSource, dbg_st_search, dbg_results |
67 from cubicweb.server.sources.rql2sql import SQLGenerator |
67 from cubicweb.server.sources.rql2sql import SQLGenerator |
303 self.multisources_etypes = set(repo.config['multi-sources-etypes']) |
303 self.multisources_etypes = set(repo.config['multi-sources-etypes']) |
304 # XXX no_sqlite_wrap trick since we've a sqlite locking pb when |
304 # XXX no_sqlite_wrap trick since we've a sqlite locking pb when |
305 # running unittest_multisources with the wrapping below |
305 # running unittest_multisources with the wrapping below |
306 if self.dbdriver == 'sqlite' and \ |
306 if self.dbdriver == 'sqlite' and \ |
307 not getattr(repo.config, 'no_sqlite_wrap', False): |
307 not getattr(repo.config, 'no_sqlite_wrap', False): |
308 from cubicweb.server.sources.extlite import ConnectionWrapper |
|
309 self.dbhelper.dbname = abspath(self.dbhelper.dbname) |
308 self.dbhelper.dbname = abspath(self.dbhelper.dbname) |
310 self.get_connection = lambda: ConnectionWrapper(self) |
309 self.get_connection = lambda: SqliteCnxLoggingWrapper(self) |
311 self.check_connection = lambda cnx: cnx |
310 self.check_connection = lambda cnx: cnx |
312 def cnxset_freed(cnx): |
311 def cnxset_freed(cnx): |
313 cnx.close() |
312 cnx.close() |
314 self.cnxset_freed = cnxset_freed |
313 self.cnxset_freed = cnxset_freed |
315 if self.dbdriver == 'sqlite': |
314 if self.dbdriver == 'sqlite': |
316 self._create_eid = None |
315 self._create_eid = None |
317 self.create_eid = self._create_eid_sqlite |
316 self.create_eid = self._create_eid_sqlite |
318 self.binary_to_str = self.dbhelper.dbapi_module.binary_to_str |
317 self.binary_to_str = self.dbhelper.dbapi_module.binary_to_str |
319 |
|
320 |
|
321 @property |
|
322 def _sqlcnx(self): |
|
323 # XXX: sqlite connections can only be used in the same thread, so |
|
324 # create a new one each time necessary. If it appears to be time |
|
325 # consuming, find another way |
|
326 return SQLAdapterMixIn.get_connection(self) |
|
327 |
318 |
328 def check_config(self, source_entity): |
319 def check_config(self, source_entity): |
329 """check configuration of source entity""" |
320 """check configuration of source entity""" |
330 if source_entity.host_config: |
321 if source_entity.host_config: |
331 msg = source_entity._cw._('the system source has its configuration ' |
322 msg = source_entity._cw._('the system source has its configuration ' |
733 it's a function just so that it shows up in profiling |
724 it's a function just so that it shows up in profiling |
734 """ |
725 """ |
735 cursor = session.cnxset[self.uri] |
726 cursor = session.cnxset[self.uri] |
736 if server.DEBUG & server.DBG_SQL: |
727 if server.DEBUG & server.DBG_SQL: |
737 cnx = session.cnxset.connection(self.uri) |
728 cnx = session.cnxset.connection(self.uri) |
738 # getattr to get the actual connection if cnx is a ConnectionWrapper |
729 # getattr to get the actual connection if cnx is a CnxLoggingWrapper |
739 # instance |
730 # instance |
740 print 'exec', query, args, getattr(cnx, '_cnx', cnx) |
731 print 'exec', query, args, getattr(cnx, '_cnx', cnx) |
741 try: |
732 try: |
742 # str(query) to avoid error if it's an unicode string |
733 # str(query) to avoid error if it's an unicode string |
743 cursor.execute(str(query), args) |
734 cursor.execute(str(query), args) |