User:Alvonruff/MySQLdb Conversion

From ISFDB
Jump to navigation Jump to search

Step 1

Create a MYSQL_CONNECTOR class to hide the details between the two connector methods:

   class MYSQL_CONNECTOR():
       def __init__(self):
               if db_connector == db_python3:
                       self.cursor = db.cursor(buffered=True)
               else:
                       self.cursor = 0
       def DB_QUERY(self, query):
               if db_connector == db_python2:
                       db.query(query)
                       self.result = db.store_result()
               elif db_connector == db_python3:
                       self.cursor.execute(query)
               else:
                       print("Unsupported Connector")
       def DB_FETCHONE(self):
               # Note that fetchone() places the result in a single array,
               # not a double nested array like fetch_row()
               if db_connector == db_python2:
                       record = self.result.fetch_row()
               elif db_connector == db_python3:
                       record = [self.cursor.fetchone()]
               else:
                       print("Unsupported Connector")
                       record = 0
               return record
       def DB_FETCHMANY(self):
               if db_connector == db_python2:
                       record = self.result.fetch_row()
               elif db_connector == db_python3:
                       record = self.cursor.fetchmany()
               else:
                       print("Unsupported Connector")
                       record = 0
               return record
       def DB_NUMROWS(self):
               if db_connector == db_python2:
                       return self.result.num_rows()
               elif db_connector == db_python3:
                       return self.cursor.rowcount
               else:
                       print("Unsupported Connector")
                       return 0
       def DB_INSERT_ID(self):
               if db_connector == db_python2:
                       return db.insert_id()
               elif db_connector == db_python3:
                       return db.insert_id()
               else:
                       print("Unsupported Connector")
                       return 0
       def DB_ESCAPE_STRING(self, target):
               if db_connector == db_python2:
                       return db.escape_string(target)
               elif db_connector == db_python3:
                       return target
               else:
                       print("Unsupported Connector")
                       return 0

Step 2

Convert common/SQLparsing.py to use the new class. This has already been done, and tested by hand on Python2 and Python3.

Step 3

Create a formal test suite to test the methods in SQLparsing.py. This is long overdue, with testing being done informally by manual observation. This will take some time.

Step 4

There are numerous files in the ISFDB that directly use the connector. Obviously, these database methods are difficult to test formally, since they are implemented inline with other functionality. At any rate, they either need to move in SQLparsing.py, or they need to be converted to use the MYSQL_CONNECTOR connector class:

common

  • common/library.py - DONE, via conversion
  • common/pubClass.py - DONE, via conversion
  • common/publisherClass.py - DONE, via conversion
  • common/pubseriesClass.py
    • delete() - There is nothing here that can't be moved to SQLparsing
  • common/sfe3.py
  • common/titleClass.py
    • delete() - There is nothing here that can't be moved to SQLparsing

biblio

  • biblio/adv_search_results.py
  • biblio/author_history.py
  • biblio/authors_by_debut_year.py
  • biblio/award_category_history.py
  • biblio/award_history.py
  • biblio/awardtype_history.py
  • biblio/cancelsubmission.py
  • biblio/changed_verified_pubs.py
  • biblio/common.py
  • biblio/directory.py
  • biblio/external_id_search_results.py
  • biblio/most_popular.py
  • biblio/most_reviewed.py
  • biblio/myrecent.py
  • biblio/my_removed_secondary_verifications.py
  • biblio/my_secondary_verifications.py
  • biblio/myverificationsClass.py
  • biblio/myvotes.py
  • biblio/mywebsites.py
  • biblio/note_search_results.py
  • biblio/popular_authors.py
  • biblio/pub_history.py
  • biblio/publisher_history.py
  • biblio/pubseries_history.py
  • biblio/recent_primary_ver.py
  • biblio/recent.py
  • biblio/recentver.py
  • biblio/removed_secondary_verifications.py
  • biblio/series_history.py
  • biblio/stats.py
  • biblio/submitlogin.py
  • biblio/submitmylanguages.py
  • biblio/submitmywebsites.py
  • biblio/submitpreferences.py
  • biblio/title_history.py
  • biblio/topcontrib.py
  • biblio/usertag.py
  • biblio/webpages_search_results.py

edit

  • edit/cleanup.py
  • edit/cleanup_report.py
  • edit/edittags.py
  • edit/empty_containers.py
  • edit/incomplete_contents.py
  • edit/isfdblib.py
  • edit/keygen.py
  • edit/numeric_external_id_ranges.py
  • edit/publisher_exceptions.py
  • edit/submit_primary_verification.py
  • edit/submittags.py
  • edit/submitver.py
  • edit/submitvote.py
  • edit/vote.py

mod

  • mod/aa_merge.py
  • mod/aa_update.py
  • mod/award_cat_delete_file.py
  • mod/award_cat_new_file.py
  • mod/award_cat_update_file.py
  • mod/award_link_file.py
  • mod/award_type_delete_file.py
  • mod/award_type_new_file.py
  • mod/award_type_update_file.py
  • mod/bad_images.py
  • mod/ca_new.py
  • mod/change_tag_status.py
  • mod/common.py
  • mod/cpanel.py
  • mod/hardreject.py
  • mod/hold.py
  • mod/isfdblib.py
  • mod/ka_new.py
  • mod/marque.py
  • mod/new_language_file.py
  • mod/pa_delete.py
  • mod/pa_new.py
  • mod/pa_update.py
  • mod/ra_link.py
  • mod/recent.py
  • mod/reject.py
  • mod/remove_secondary_verification.py
  • mod/resolve_bad_url.py
  • mod/resolve_cleanup.py
  • mod/resolve_empty_containers.py
  • mod/resolve_sfe3_url.py
  • mod/sa_delete.py
  • mod/sa_update.py
  • mod/self_approver_file.py
  • mod/submission_search_results.py
  • mod/submitcpanel.py
  • mod/submitref.py
  • mod/ta_merge.py
  • mod/ta_remove.py
  • mod/ta_unmerge.py
  • mod/ta_update.py
  • mod/template_add_file.py
  • mod/template_update_file.py
  • mod/ua_merge.py
  • mod/unhold.py
  • mod/unreject.py
  • mod/va_new.py
  • mod/verification_source_add_file.py
  • mod/verification_source_file.py
  • mod/wa_delete.py
  • mod/wa_new.py
  • mod/wa_update.py
  • mod/xa_update.py
  • mod/ya_new.py
  • mod/ya_remove.py
  • mod/za_update.py

rest

  • rest/submission.py