163 db.transaction() |
163 db.transaction() |
164 try: |
164 try: |
165 query = QSqlQuery(db) |
165 query = QSqlQuery(db) |
166 query.prepare(self.file_loaded_stmt) |
166 query.prepare(self.file_loaded_stmt) |
167 query.bindValue(":file", apiFile) |
167 query.bindValue(":file", apiFile) |
168 query.exec_() |
168 query.exec() |
169 if query.next() and query.isValid(): # __IGNORE_WARNING_M513__ |
169 if query.next() and query.isValid(): # __IGNORE_WARNING_M513__ |
170 loadTime = QDateTime.fromString(query.value(0), Qt.ISODate) |
170 loadTime = QDateTime.fromString(query.value(0), Qt.ISODate) |
171 else: |
171 else: |
172 loadTime = QDateTime(1970, 1, 1, 0, 0) |
172 loadTime = QDateTime(1970, 1, 1, 0, 0) |
173 query.finish() |
173 query.finish() |
286 try: |
286 try: |
287 query = QSqlQuery(db) |
287 query = QSqlQuery(db) |
288 # step 1: create entry in file table |
288 # step 1: create entry in file table |
289 query.prepare(self.populate_file_stmt) |
289 query.prepare(self.populate_file_stmt) |
290 query.bindValue(":file", apiFile) |
290 query.bindValue(":file", apiFile) |
291 query.exec_() |
291 query.exec() |
292 |
292 |
293 # step 2: update the file entry |
293 # step 2: update the file entry |
294 query.prepare(self.update_file_stmt) |
294 query.prepare(self.update_file_stmt) |
295 query.bindValue(":lastRead", QDateTime.currentDateTime()) |
295 query.bindValue(":lastRead", QDateTime.currentDateTime()) |
296 query.bindValue(":file", apiFile) |
296 query.bindValue(":file", apiFile) |
297 query.exec_() |
297 query.exec() |
298 finally: |
298 finally: |
299 query.finish() |
299 query.finish() |
300 del query |
300 del query |
301 if self.__aborted: |
301 if self.__aborted: |
302 db.rollback() |
302 db.rollback() |
321 try: |
321 try: |
322 query = QSqlQuery(db) |
322 query = QSqlQuery(db) |
323 # step 1: create entry in file table and get the ID |
323 # step 1: create entry in file table and get the ID |
324 query.prepare(self.populate_file_stmt) |
324 query.prepare(self.populate_file_stmt) |
325 query.bindValue(":file", apiFile) |
325 query.bindValue(":file", apiFile) |
326 if not query.exec_(): |
326 if not query.exec(): |
327 return |
327 return |
328 query.prepare(self.file_id_stmt) |
328 query.prepare(self.file_id_stmt) |
329 query.bindValue(":file", apiFile) |
329 query.bindValue(":file", apiFile) |
330 if not query.exec_(): |
330 if not query.exec(): |
331 return |
331 return |
332 if not query.next(): # __IGNORE_WARNING_M513__ |
332 if not query.next(): # __IGNORE_WARNING_M513__ |
333 return |
333 return |
334 fileId = int(query.value(0)) |
334 fileId = int(query.value(0)) |
335 |
335 |
336 # step 2: delete all entries belonging to this file |
336 # step 2: delete all entries belonging to this file |
337 query.prepare(self.populate_del_api_stmt) |
337 query.prepare(self.populate_del_api_stmt) |
338 query.bindValue(":fileId", fileId) |
338 query.bindValue(":fileId", fileId) |
339 query.exec_() |
339 query.exec() |
340 |
340 |
341 query.prepare(self.populate_del_bases_stmt) |
341 query.prepare(self.populate_del_bases_stmt) |
342 query.bindValue(":fileId", fileId) |
342 query.bindValue(":fileId", fileId) |
343 query.exec_() |
343 query.exec() |
344 |
344 |
345 # step 3: load the given API info |
345 # step 3: load the given API info |
346 query.prepare(self.populate_api_stmt) |
346 query.prepare(self.populate_api_stmt) |
347 for api in apis: |
347 for api in apis: |
348 if self.__aborted: |
348 if self.__aborted: |
399 query.bindValue(":context", context) |
399 query.bindValue(":context", context) |
400 query.bindValue(":fullContext", fullContext) |
400 query.bindValue(":fullContext", fullContext) |
401 query.bindValue(":signature", sig) |
401 query.bindValue(":signature", sig) |
402 query.bindValue(":fileId", fileId) |
402 query.bindValue(":fileId", fileId) |
403 query.bindValue(":pictureId", pictureId) |
403 query.bindValue(":pictureId", pictureId) |
404 query.exec_() |
404 query.exec() |
405 |
405 |
406 sig = "" |
406 sig = "" |
407 |
407 |
408 # step 4: load the given base classes info |
408 # step 4: load the given base classes info |
409 query.prepare(self.populate_bases_stmt) |
409 query.prepare(self.populate_bases_stmt) |
417 |
417 |
418 class_, baseClasses = base.split(" ", 1) |
418 class_, baseClasses = base.split(" ", 1) |
419 query.bindValue(":class", class_) |
419 query.bindValue(":class", class_) |
420 query.bindValue(":baseClasses", baseClasses) |
420 query.bindValue(":baseClasses", baseClasses) |
421 query.bindValue(":fileId", fileId) |
421 query.bindValue(":fileId", fileId) |
422 query.exec_() |
422 query.exec() |
423 |
423 |
424 if not self.__aborted: |
424 if not self.__aborted: |
425 # step 5: update the file entry |
425 # step 5: update the file entry |
426 query.prepare(self.update_file_stmt) |
426 query.prepare(self.update_file_stmt) |
427 query.bindValue(":lastRead", QDateTime.currentDateTime()) |
427 query.bindValue(":lastRead", QDateTime.currentDateTime()) |
428 query.bindValue(":file", apiFile) |
428 query.bindValue(":file", apiFile) |
429 query.exec_() |
429 query.exec() |
430 finally: |
430 finally: |
431 query.finish() |
431 query.finish() |
432 del query |
432 del query |
433 if self.__aborted: |
433 if self.__aborted: |
434 db.rollback() |
434 db.rollback() |
447 query = QSqlQuery(db) |
447 query = QSqlQuery(db) |
448 |
448 |
449 # step 1: get the ID belonging to the api file |
449 # step 1: get the ID belonging to the api file |
450 query.prepare(self.file_id_stmt) |
450 query.prepare(self.file_id_stmt) |
451 query.bindValue(":file", apiFile) |
451 query.bindValue(":file", apiFile) |
452 query.exec_() |
452 query.exec() |
453 query.next() # __IGNORE_WARNING_M513__ |
453 query.next() # __IGNORE_WARNING_M513__ |
454 fileId = int(query.value(0)) |
454 fileId = int(query.value(0)) |
455 |
455 |
456 # step 2: delete all API entries belonging to this file |
456 # step 2: delete all API entries belonging to this file |
457 query.prepare(self.populate_del_api_stmt) |
457 query.prepare(self.populate_del_api_stmt) |
458 query.bindValue(":fileId", fileId) |
458 query.bindValue(":fileId", fileId) |
459 query.exec_() |
459 query.exec() |
460 |
460 |
461 # step 3: delete all base classes entries belonging to this file |
461 # step 3: delete all base classes entries belonging to this file |
462 query.prepare(self.populate_del_bases_stmt) |
462 query.prepare(self.populate_del_bases_stmt) |
463 query.bindValue(":fileId", fileId) |
463 query.bindValue(":fileId", fileId) |
464 query.exec_() |
464 query.exec() |
465 |
465 |
466 # step 4: delete the file entry |
466 # step 4: delete the file entry |
467 query.prepare(self.file_delete_id_stmt) |
467 query.prepare(self.file_delete_id_stmt) |
468 query.bindValue(":id", fileId) |
468 query.bindValue(":id", fileId) |
469 query.exec_() |
469 query.exec() |
470 finally: |
470 finally: |
471 query.finish() |
471 query.finish() |
472 del query |
472 del query |
473 db.commit() |
473 db.commit() |
474 |
474 |
784 db = QSqlDatabase.database(self.__connectionName) |
784 db = QSqlDatabase.database(self.__connectionName) |
785 db.transaction() |
785 db.transaction() |
786 try: |
786 try: |
787 query = QSqlQuery(db) |
787 query = QSqlQuery(db) |
788 # step 1: drop old tables |
788 # step 1: drop old tables |
789 query.exec_(self.drop_mgmt_stmt) |
789 query.exec(self.drop_mgmt_stmt) |
790 query.exec_(self.drop_api_stmt) |
790 query.exec(self.drop_api_stmt) |
791 query.exec_(self.drop_bases_stmt) |
791 query.exec(self.drop_bases_stmt) |
792 query.exec_(self.drop_file_stmt) |
792 query.exec(self.drop_file_stmt) |
793 # step 2: drop old indices |
793 # step 2: drop old indices |
794 query.exec_(self.drop_acWord_idx) |
794 query.exec(self.drop_acWord_idx) |
795 query.exec_(self.drop_context_idx) |
795 query.exec(self.drop_context_idx) |
796 query.exec_(self.drop_fullContext_idx) |
796 query.exec(self.drop_fullContext_idx) |
797 query.exec_(self.drop_bases_idx) |
797 query.exec(self.drop_bases_idx) |
798 query.exec_(self.drop_file_idx) |
798 query.exec(self.drop_file_idx) |
799 # step 3: create tables |
799 # step 3: create tables |
800 query.exec_(self.create_api_stmt) |
800 query.exec(self.create_api_stmt) |
801 query.exec_(self.create_bases_stmt) |
801 query.exec(self.create_bases_stmt) |
802 query.exec_(self.create_file_stmt) |
802 query.exec(self.create_file_stmt) |
803 query.exec_(self.create_mgmt_stmt) |
803 query.exec(self.create_mgmt_stmt) |
804 query.exec_(self.mgmt_insert_stmt) |
804 query.exec(self.mgmt_insert_stmt) |
805 # step 4: create indices |
805 # step 4: create indices |
806 query.exec_(self.create_acWord_idx) |
806 query.exec(self.create_acWord_idx) |
807 query.exec_(self.create_context_idx) |
807 query.exec(self.create_context_idx) |
808 query.exec_(self.create_fullContext_idx) |
808 query.exec(self.create_fullContext_idx) |
809 query.exec_(self.create_bases_idx) |
809 query.exec(self.create_bases_idx) |
810 query.exec_(self.create_file_idx) |
810 query.exec(self.create_file_idx) |
811 finally: |
811 finally: |
812 query.finish() |
812 query.finish() |
813 del query |
813 del query |
814 db.commit() |
814 db.commit() |
815 |
815 |
896 query = QSqlQuery(db) |
896 query = QSqlQuery(db) |
897 query.prepare(self.ac_context_stmt) |
897 query.prepare(self.ac_context_stmt) |
898 query.bindValue(":context", context) |
898 query.bindValue(":context", context) |
899 |
899 |
900 if query is not None: |
900 if query is not None: |
901 query.exec_() |
901 query.exec() |
902 while query.next(): # __IGNORE_WARNING_M513__ |
902 while query.next(): # __IGNORE_WARNING_M513__ |
903 completions.append({"completion": query.value(0), |
903 completions.append({"completion": query.value(0), |
904 "context": query.value(1), |
904 "context": query.value(1), |
905 "pictureId": query.value(2)}) |
905 "pictureId": query.value(2)}) |
906 query.finish() |
906 query.finish() |
910 |
910 |
911 if followHierarchy: |
911 if followHierarchy: |
912 query = QSqlQuery(db) |
912 query = QSqlQuery(db) |
913 query.prepare(self.bases_stmt) |
913 query.prepare(self.bases_stmt) |
914 query.bindValue(":class", context) |
914 query.bindValue(":class", context) |
915 query.exec_() |
915 query.exec() |
916 if query.next(): # __IGNORE_WARNING_M513__ |
916 if query.next(): # __IGNORE_WARNING_M513__ |
917 bases = query.value(0).split() |
917 bases = query.value(0).split() |
918 else: |
918 else: |
919 bases = [] |
919 bases = [] |
920 for base in bases: |
920 for base in bases: |
959 query.prepare(self.ct_context_stmt) |
959 query.prepare(self.ct_context_stmt) |
960 query.bindValue(":context", context) |
960 query.bindValue(":context", context) |
961 else: |
961 else: |
962 query.prepare(self.ct_stmt) |
962 query.prepare(self.ct_stmt) |
963 query.bindValue(":acWord", acWord) |
963 query.bindValue(":acWord", acWord) |
964 query.exec_() |
964 query.exec() |
965 while query.next(): # __IGNORE_WARNING_M513__ |
965 while query.next(): # __IGNORE_WARNING_M513__ |
966 word = query.value(0) |
966 word = query.value(0) |
967 sig = query.value(1) |
967 sig = query.value(1) |
968 fullCtx = query.value(2) |
968 fullCtx = query.value(2) |
969 if sig: |
969 if sig: |
987 |
987 |
988 if followHierarchy: |
988 if followHierarchy: |
989 query = QSqlQuery(db) |
989 query = QSqlQuery(db) |
990 query.prepare(self.bases_stmt) |
990 query.prepare(self.bases_stmt) |
991 query.bindValue(":class", context) |
991 query.bindValue(":class", context) |
992 query.exec_() |
992 query.exec() |
993 if query.next(): # __IGNORE_WARNING_M513__ |
993 if query.next(): # __IGNORE_WARNING_M513__ |
994 bases = query.value(0).split() |
994 bases = query.value(0).split() |
995 else: |
995 else: |
996 bases = [] |
996 bases = [] |
997 for base in bases: |
997 for base in bases: |