MAXdev

MDPro - Fix for AutoTheme/render and UTF-8 (MDLite & MDP 1.07x)

Wiseman - Aug 23, 2007 - 11:27 PM
Post subject: Fix for AutoTheme/render and UTF-8 (MDLite & MDP 1.07x)
This is a fix a condition where AutoTheme wouldn't detect the blocks (e.g. md_blocks) table has been properly updated when the MySQL table used the UTF-8 character set/encoding. This happened because MySQL reports 3*255 as $field->max_length, not 255.

For MDPro 1.07x: Replace this function in modules/AutoTheme/includes/md-pro/atAdmin.php
For MDLite: Replace this function in modules/Autorender/includes/atExtended.php

Code:
function AutoThemeCheckTable()
{
   list($dbconn) = pnDBGetConn();
   $pntable =& pnDBGetTables();
   $column = &$pntable['blocks_column'];

   $sql = "SELECT $column[position] FROM $pntable[blocks]";
   $result = $dbconn->SelectLimit($sql,1);

   $field = $result->FetchField(0);
//BEGIN AUTOTHEME-BLOCKS TABLE DETECTION-FIX
   if ($field->max_length >= 255) {
//END AUTOTHEME-BLOCKS TABLE DETECTION-FIX
      return true;
   }
   else {
      return false;
   }
}


Rationale: The function was checking for $field->max_length == 255, a sign that the table has been updated to hold the allowable values for block positions (now strings). MySQL (possibly wrongly) returns this size in octets, not characters. Since MySQL supports just UCS-2, its longest UTF-8 character spans over 3 octets, and the maximum octet count for a 255 character UTF-8 string is 255 * 3 = 765 octets. This patch changes this line to check whether the field maximum length is equal or greater than 255, which fits AutoTheme's purpose and works with MySQL in both UTF-8 and legacy character sets/encodings, as well as other databases.
TiMax - Aug 25, 2007 - 12:20 AM
Post subject:
Thanks man, we will check it to include your contribution with MDPro 1.082
All times are GMT + 13 Hours
Powered by MDForum 2.0.8 © 2003-2007 based on phpBB © 2001, 2002 phpBB Team
and by MDRebel which uses Theme Graphics by Daz
and by Attachment-Mod 2.4.3