241 return self._cnx |
241 return self._cnx |
242 |
242 |
243 @property |
243 @property |
244 def session(self): |
244 def session(self): |
245 if self.config is not None: |
245 if self.config is not None: |
246 return self.repo._get_session(self.cnx.sessionid) |
246 session = self.repo._get_session(self.cnx.sessionid) |
|
247 if session.pool is None: |
|
248 session.set_read_security(False) |
|
249 session.set_write_security(False) |
|
250 session.set_pool() |
|
251 return session |
247 # no access to session on remote instance |
252 # no access to session on remote instance |
248 return None |
253 return None |
249 |
254 |
250 def commit(self): |
255 def commit(self): |
251 if hasattr(self, '_cnx'): |
256 if hasattr(self, '_cnx'): |
252 self._cnx.commit() |
257 self._cnx.commit() |
|
258 if self.session: |
|
259 self.session.set_pool() |
253 |
260 |
254 def rollback(self): |
261 def rollback(self): |
255 if hasattr(self, '_cnx'): |
262 if hasattr(self, '_cnx'): |
256 self._cnx.rollback() |
263 self._cnx.rollback() |
|
264 if self.session: |
|
265 self.session.set_pool() |
257 |
266 |
258 def rqlexecall(self, rqliter, cachekey=None, ask_confirm=True): |
267 def rqlexecall(self, rqliter, cachekey=None, ask_confirm=True): |
259 for rql, kwargs in rqliter: |
268 for rql, kwargs in rqliter: |
260 self.rqlexec(rql, kwargs, cachekey, ask_confirm) |
269 self.rqlexec(rql, kwargs, cachekey, ask_confirm) |
261 |
270 |
311 self.execscript_confirm = execscript_confirm |
320 self.execscript_confirm = execscript_confirm |
312 if self.config.free_wheel: |
321 if self.config.free_wheel: |
313 self.cmd_reactivate_verification_hooks() |
322 self.cmd_reactivate_verification_hooks() |
314 |
323 |
315 def install_custom_sql_scripts(self, directory, driver): |
324 def install_custom_sql_scripts(self, directory, driver): |
316 self.session.set_pool() # ensure pool is set |
|
317 for fpath in glob(osp.join(directory, '*.sql.%s' % driver)): |
325 for fpath in glob(osp.join(directory, '*.sql.%s' % driver)): |
318 newname = osp.basename(fpath).replace('.sql.%s' % driver, |
326 newname = osp.basename(fpath).replace('.sql.%s' % driver, |
319 '.%s.sql' % driver) |
327 '.%s.sql' % driver) |
320 warn('[3.5.6] rename %s into %s' % (fpath, newname), |
328 warn('[3.5.6] rename %s into %s' % (fpath, newname), |
321 DeprecationWarning) |
329 DeprecationWarning) |
696 eschema = self.fs_schema.eschema(etype) |
704 eschema = self.fs_schema.eschema(etype) |
697 confirm = self.verbosity >= 2 |
705 confirm = self.verbosity >= 2 |
698 groupmap = self.group_mapping() |
706 groupmap = self.group_mapping() |
699 cstrtypemap = self.cstrtype_mapping() |
707 cstrtypemap = self.cstrtype_mapping() |
700 # register the entity into CWEType |
708 # register the entity into CWEType |
701 try: |
709 execute = self._cw.execute |
702 execute = self._cw.unsafe_execute |
|
703 except AttributeError: |
|
704 execute = self._cw.execute |
|
705 ss.execschemarql(execute, eschema, ss.eschema2rql(eschema, groupmap)) |
710 ss.execschemarql(execute, eschema, ss.eschema2rql(eschema, groupmap)) |
706 # add specializes relation if needed |
711 # add specializes relation if needed |
707 self.rqlexecall(ss.eschemaspecialize2rql(eschema), ask_confirm=confirm) |
712 self.rqlexecall(ss.eschemaspecialize2rql(eschema), ask_confirm=confirm) |
708 # register entity's attributes |
713 # register entity's attributes |
709 for rschema, attrschema in eschema.attribute_definitions(): |
714 for rschema, attrschema in eschema.attribute_definitions(): |
840 committing depends on the `commit` argument value). |
845 committing depends on the `commit` argument value). |
841 |
846 |
842 """ |
847 """ |
843 reposchema = self.repo.schema |
848 reposchema = self.repo.schema |
844 rschema = self.fs_schema.rschema(rtype) |
849 rschema = self.fs_schema.rschema(rtype) |
845 try: |
850 execute = self._cw.execute |
846 execute = self._cw.unsafe_execute |
|
847 except AttributeError: |
|
848 execute = self._cw.execute |
|
849 # register the relation into CWRType and insert necessary relation |
851 # register the relation into CWRType and insert necessary relation |
850 # definitions |
852 # definitions |
851 ss.execschemarql(execute, rschema, ss.rschema2rql(rschema, addrdef=False)) |
853 ss.execschemarql(execute, rschema, ss.rschema2rql(rschema, addrdef=False)) |
852 if addrdef: |
854 if addrdef: |
853 self.commit() |
855 self.commit() |
903 schema definition file |
905 schema definition file |
904 """ |
906 """ |
905 rschema = self.fs_schema.rschema(rtype) |
907 rschema = self.fs_schema.rschema(rtype) |
906 if not rtype in self.repo.schema: |
908 if not rtype in self.repo.schema: |
907 self.cmd_add_relation_type(rtype, addrdef=False, commit=True) |
909 self.cmd_add_relation_type(rtype, addrdef=False, commit=True) |
908 try: |
910 execute = self._cw.execute |
909 execute = self._cw.unsafe_execute |
|
910 except AttributeError: |
|
911 execute = self._cw.execute |
|
912 rdef = self._get_rdef(rschema, subjtype, objtype) |
911 rdef = self._get_rdef(rschema, subjtype, objtype) |
913 ss.execschemarql(execute, rdef, |
912 ss.execschemarql(execute, rdef, |
914 ss.rdef2rql(rdef, self.cstrtype_mapping(), |
913 ss.rdef2rql(rdef, self.cstrtype_mapping(), |
915 self.group_mapping())) |
914 self.group_mapping())) |
916 if commit: |
915 if commit: |
1182 |
1181 |
1183 should only be used for low level stuff undoable with existing higher |
1182 should only be used for low level stuff undoable with existing higher |
1184 level actions |
1183 level actions |
1185 """ |
1184 """ |
1186 if not ask_confirm or self.confirm('Execute sql: %s ?' % sql): |
1185 if not ask_confirm or self.confirm('Execute sql: %s ?' % sql): |
1187 self.session.set_pool() # ensure pool is set |
|
1188 try: |
1186 try: |
1189 cu = self.session.system_sql(sql, args) |
1187 cu = self.session.system_sql(sql, args) |
1190 except: |
1188 except: |
1191 ex = sys.exc_info()[1] |
1189 ex = sys.exc_info()[1] |
1192 if self.confirm('Error: %s\nabort?' % ex): |
1190 if self.confirm('Error: %s\nabort?' % ex): |
1201 def rqlexec(self, rql, kwargs=None, cachekey=None, ask_confirm=True): |
1199 def rqlexec(self, rql, kwargs=None, cachekey=None, ask_confirm=True): |
1202 """rql action""" |
1200 """rql action""" |
1203 if not isinstance(rql, (tuple, list)): |
1201 if not isinstance(rql, (tuple, list)): |
1204 rql = ( (rql, kwargs), ) |
1202 rql = ( (rql, kwargs), ) |
1205 res = None |
1203 res = None |
1206 try: |
1204 execute = self._cw.execute |
1207 execute = self._cw.unsafe_execute |
|
1208 except AttributeError: |
|
1209 execute = self._cw.execute |
|
1210 for rql, kwargs in rql: |
1205 for rql, kwargs in rql: |
1211 if kwargs: |
1206 if kwargs: |
1212 msg = '%s (%s)' % (rql, kwargs) |
1207 msg = '%s (%s)' % (rql, kwargs) |
1213 else: |
1208 else: |
1214 msg = rql |
1209 msg = rql |