Ticket #5817: mythburnutf8.diff

File mythburnutf8.diff, 4.3 KB (added by Bjorn Gustafsson <bjorne-g@…>, 17 years ago)

Patch to mythburn to make sure all data is read from database using utf8

  • mythplugins/mytharchive/mythburn/scripts/mythburn.py

     
    349349
    350350def getDatabaseConnection():
    351351    """Returns a mySQL connection to mythconverg database."""
    352     return MySQLdb.connect(host=mysql_host, user=mysql_user, passwd=mysql_passwd, db=mysql_db)
     352    return MySQLdb.connect(host=mysql_host, user=mysql_user, passwd=mysql_passwd, db=mysql_db, init_command='SET CHARACTER SET utf8')
    353353
    354354#############################################################
     355# Sets mySQL parameters for getting data in utf8
     356
     357def setCursorUtf8( cursor ):
     358    """Sets mySQL parameters for getting data in utf8."""
     359    cursor.execute('SET NAMES utf8;')
     360    cursor.execute('SET CHARACTER SET utf8;')
     361    cursor.execute('SET character_set_connection=utf8;')
     362
     363#############################################################
    355364# Returns true/false if a given file or path exists.
    356365
    357366def doesFileExist(file):
     
    846855    db = getDatabaseConnection()
    847856    # create a cursor
    848857    cursor = db.cursor()
     858    setCursorUtf8( cursor )
    849859    # execute SQL statement
    850860    cursor.execute(sqlstatement)
    851861    # get the resultset as a tuple
     
    870880def saveSetting(name, data):
    871881    db = getDatabaseConnection()
    872882    cursor = db.cursor()
     883    setCursorUtf8( cursor )
    873884
    874885    query =  "DELETE from settings "
    875886    query += "WHERE value = '" + name + "' AND hostname = '" + configHostname + "'"
     
    893904
    894905    db = getDatabaseConnection()
    895906    cursor = db.cursor()
     907    setCursorUtf8( cursor )
    896908
    897909    cursor.execute("DELETE from archiveitems;")
    898910
     
    14091421
    14101422            db = getDatabaseConnection()
    14111423            cursor = db.cursor()
     1424            setCursorUtf8( cursor )
    14121425            cursor.execute(sqlstatement)
    14131426            result = cursor.fetchall()
    14141427            numrows = int(cursor.rowcount)
     
    14371450                                WHERE chanid = '%s' AND starttime = '%s'
    14381451                                AND type IN (0,1) ORDER BY mark""" % (chanid, starttime)
    14391452                cursor = db.cursor()
     1453                setCursorUtf8( cursor )
    14401454                # execute SQL statement
    14411455                cursor.execute(sqlstatement)
    14421456                if cursor.rowcount > 0:
     
    14541468                                    WHERE chanid = '%s' AND starttime = '%s'
    14551469                                    AND type = 0 ORDER BY mark""" % (chanid, starttime)
    14561470                    cursor = db.cursor()
     1471                    setCursorUtf8( cursor )
    14571472                    # execute SQL statement
    14581473                    cursor.execute(sqlstatement)
    14591474                    # get the resultset as a tuple
     
    14811496
    14821497        # connect
    14831498        db = getDatabaseConnection()
    1484         # create a cursor
     1499        # create a cursor
    14851500        cursor = db.cursor()
     1501        setCursorUtf8( cursor )
    14861502        # execute SQL statement
    14871503        cursor.execute(sqlstatement)
    14881504        # get the resultset as a tuple
     
    15561572                               WHERE chanid = '%s' AND starttime = '%s'
    15571573                               AND type IN (0,1) ORDER BY mark""" % (chanid, starttime)
    15581574            cursor = db.cursor()
     1575            setCursorUtf8( cursor )
    15591576            # execute SQL statement
    15601577            cursor.execute(sqlstatement)
    15611578            if cursor.rowcount > 0:
     
    15731590                                    WHERE chanid = '%s' AND starttime = '%s'
    15741591                                    AND type = 0 ORDER BY mark""" % (chanid, starttime)
    15751592                cursor = db.cursor()
     1593                setCursorUtf8( cursor )
    15761594                # execute SQL statement
    15771595                cursor.execute(sqlstatement)
    15781596                # get the resultset as a tuple
     
    16021620        db = getDatabaseConnection()
    16031621        # create a cursor
    16041622        cursor = db.cursor()
     1623        setCursorUtf8( cursor )
    16051624        # execute SQL statement
    16061625        cursor.execute(sqlstatement)
    16071626        # get the resultset as a tuple
     
    20022021
    20032022    db = getDatabaseConnection()
    20042023    cursor = db.cursor()
     2024    setCursorUtf8( cursor )
    20052025    cursor.execute(sqlstatement)
    20062026    result = cursor.fetchall()
    20072027    numrows = int(cursor.rowcount)