171 if self._need_sql_create: |
171 if self._need_sql_create: |
172 return [] |
172 return [] |
173 sql, query_args = self.rqlsqlgen.generate(union, args) |
173 sql, query_args = self.rqlsqlgen.generate(union, args) |
174 if server.DEBUG: |
174 if server.DEBUG: |
175 print self.uri, 'SOURCE RQL', union.as_string() |
175 print self.uri, 'SOURCE RQL', union.as_string() |
176 print 'GENERATED SQL', sql |
|
177 args = self.sqladapter.merge_args(args, query_args) |
176 args = self.sqladapter.merge_args(args, query_args) |
178 cursor = session.pool[self.uri] |
177 cursor = session.pool[self.uri] |
179 cursor.execute(sql, args) |
178 self.doexec(cursor, sql, args) |
180 return self.sqladapter.process_result(cursor) |
179 res = self.sqladapter.process_result(cursor) |
|
180 if server.DEBUG: |
|
181 print '------>', res |
|
182 return res |
181 |
183 |
182 def local_add_entity(self, session, entity): |
184 def local_add_entity(self, session, entity): |
183 """insert the entity in the local database. |
185 """insert the entity in the local database. |
184 |
186 |
185 This is not provided as add_entity implementation since usually source |
187 This is not provided as add_entity implementation since usually source |
186 don't want to simply do this, so let raise NotImplementedError and the |
188 don't want to simply do this, so let raise NotImplementedError and the |
187 source implementor may use this method if necessary |
189 source implementor may use this method if necessary |
188 """ |
190 """ |
189 cu = session.pool[self.uri] |
|
190 attrs = self.sqladapter.preprocess_entity(entity) |
191 attrs = self.sqladapter.preprocess_entity(entity) |
191 sql = self.sqladapter.sqlgen.insert(SQL_PREFIX + str(entity.e_schema), attrs) |
192 sql = self.sqladapter.sqlgen.insert(SQL_PREFIX + str(entity.e_schema), attrs) |
192 cu.execute(sql, attrs) |
193 self.doexec(session.pool[self.uri], sql, attrs) |
193 |
194 |
194 def add_entity(self, session, entity): |
195 def add_entity(self, session, entity): |
195 """add a new entity to the source""" |
196 """add a new entity to the source""" |
196 raise NotImplementedError() |
197 raise NotImplementedError() |
197 |
198 |
200 |
201 |
201 This is not provided as update_entity implementation since usually |
202 This is not provided as update_entity implementation since usually |
202 source don't want to simply do this, so let raise NotImplementedError |
203 source don't want to simply do this, so let raise NotImplementedError |
203 and the source implementor may use this method if necessary |
204 and the source implementor may use this method if necessary |
204 """ |
205 """ |
205 cu = session.pool[self.uri] |
|
206 if attrs is None: |
206 if attrs is None: |
207 attrs = self.sqladapter.preprocess_entity(entity) |
207 attrs = self.sqladapter.preprocess_entity(entity) |
208 sql = self.sqladapter.sqlgen.update(SQL_PREFIX + str(entity.e_schema), |
208 sql = self.sqladapter.sqlgen.update(SQL_PREFIX + str(entity.e_schema), |
209 attrs, [SQL_PREFIX + 'eid']) |
209 attrs, [SQL_PREFIX + 'eid']) |
210 cu.execute(sql, attrs) |
210 self.doexec(session.pool[self.uri], sql, attrs) |
211 |
211 |
212 def update_entity(self, session, entity): |
212 def update_entity(self, session, entity): |
213 """update an entity in the source""" |
213 """update an entity in the source""" |
214 raise NotImplementedError() |
214 raise NotImplementedError() |
215 |
215 |
218 |
218 |
219 this is not deleting a file in the svn but deleting entities from the |
219 this is not deleting a file in the svn but deleting entities from the |
220 source. Main usage is to delete repository content when a Repository |
220 source. Main usage is to delete repository content when a Repository |
221 entity is deleted. |
221 entity is deleted. |
222 """ |
222 """ |
223 sqlcursor = session.pool[self.uri] |
|
224 attrs = {SQL_PREFIX + 'eid': eid} |
223 attrs = {SQL_PREFIX + 'eid': eid} |
225 sql = self.sqladapter.sqlgen.delete(SQL_PREFIX + etype, attrs) |
224 sql = self.sqladapter.sqlgen.delete(SQL_PREFIX + etype, attrs) |
226 sqlcursor.execute(sql, attrs) |
225 self.doexec(session.pool[self.uri], sql, attrs) |
227 |
226 |
228 def local_add_relation(self, session, subject, rtype, object): |
227 def local_add_relation(self, session, subject, rtype, object): |
229 """add a relation to the source |
228 """add a relation to the source |
230 |
229 |
231 This is not provided as add_relation implementation since usually |
230 This is not provided as add_relation implementation since usually |
232 source don't want to simply do this, so let raise NotImplementedError |
231 source don't want to simply do this, so let raise NotImplementedError |
233 and the source implementor may use this method if necessary |
232 and the source implementor may use this method if necessary |
234 """ |
233 """ |
235 sqlcursor = session.pool[self.uri] |
|
236 attrs = {'eid_from': subject, 'eid_to': object} |
234 attrs = {'eid_from': subject, 'eid_to': object} |
237 sql = self.sqladapter.sqlgen.insert('%s_relation' % rtype, attrs) |
235 sql = self.sqladapter.sqlgen.insert('%s_relation' % rtype, attrs) |
238 sqlcursor.execute(sql, attrs) |
236 self.doexec(session.pool[self.uri], sql, attrs) |
239 |
237 |
240 def add_relation(self, session, subject, rtype, object): |
238 def add_relation(self, session, subject, rtype, object): |
241 """add a relation to the source""" |
239 """add a relation to the source""" |
242 raise NotImplementedError() |
240 raise NotImplementedError() |
243 |
241 |
252 sql = 'UPDATE %s SET %s=NULL WHERE %seid=%%(eid)s' % (table, column, SQL_PREFIX) |
250 sql = 'UPDATE %s SET %s=NULL WHERE %seid=%%(eid)s' % (table, column, SQL_PREFIX) |
253 attrs = {'eid' : subject} |
251 attrs = {'eid' : subject} |
254 else: |
252 else: |
255 attrs = {'eid_from': subject, 'eid_to': object} |
253 attrs = {'eid_from': subject, 'eid_to': object} |
256 sql = self.sqladapter.sqlgen.delete('%s_relation' % rtype, attrs) |
254 sql = self.sqladapter.sqlgen.delete('%s_relation' % rtype, attrs) |
257 sqlcursor = session.pool[self.uri] |
255 self.doexec(session.pool[self.uri], sql, attrs) |
258 sqlcursor.execute(sql, attrs) |
256 |
|
257 def doexec(self, cursor, query, args=None): |
|
258 """Execute a query. |
|
259 it's a function just so that it shows up in profiling |
|
260 """ |
|
261 #t1 = time() |
|
262 if server.DEBUG: |
|
263 print 'exec', query, args |
|
264 #import sys |
|
265 #sys.stdout.flush() |
|
266 # str(query) to avoid error if it's an unicode string |
|
267 try: |
|
268 cursor.execute(str(query), args) |
|
269 except Exception, ex: |
|
270 self.critical("sql: %r\n args: %s\ndbms message: %r", |
|
271 query, args, ex.args[0]) |
|
272 raise |