User/Alvonruff/2to3

From ISFDB
Revision as of 13:46, 25 April 2023 by Alvonruff (talk | contribs)
Jump to navigation Jump to search
  • Use 2to3 in a manner the same as futurize. This produces results suitable for python3.
  • Update to the official MySQL User:Alvonruff/mysql.connector. There is no python3 support for MySQLdb, which is our current connector. Moving to a new connector is a prerequisite.
  • Probably the most significant issue found so far is that the mysql.connector does not support datetime values where either the month or day are zero. As stated in the MySQL documentation:
   “Zero” date or time values used through Connector/ODBC are converted automatically to NULL because ODBC cannot handle such values.

This means that many dates in the ISFDB are returned as NULL by mysql.connector, which is converted to None in Python, which are then displayed as 'unknown' by the ISFDB. The least invasive workaround would be to use DATE_FORMAT to convert the datetime field before it ever leaves MySQL:

    select *, DATE_FORMAT(title_copyright, '%Y-%m-%d') as title_date  from titles where title_id=92392;

This has the side effect of adding the stringified date as a new field appended to the end of the record. There would then need to be code to patch up the NULL title_copyright field.

  • Use of md5 needs to be replaced with hashlib
  • Records that return DATETIME fields cannot simply be indexed - they must use built-in datetime methods:
    • year = field.year
    • month = field.month
    • day = field.day
  • String operator usage:
    • string.replace() must be changed to str.replace()
    • string.strip() must be changed to str.strip()
  • The new connector has no support for db.escape_string(). Since mysql.connector is DB API v2.0 compliant, you the API should automatically perform the escape without asking.
  • The following code generates the integer 110 on python2, and the float 112.0 on python3. Under python3. the division operator in always returns a float. This obviously breaks the ISBN checksum calculator:
   checksum = 112
   remainder = (checksum/10)*10

Corrected code would be:

   checksum = 112
   remainder = int(checksum/10)*10