diff -u -r adodb-new-tmp/adodb-datadict.inc.php adodb/adodb-datadict.inc.php --- adodb-new-tmp/adodb-datadict.inc.php 2006-06-07 23:20:16.000000000 -0700 +++ adodb/adodb-datadict.inc.php 2006-07-25 12:29:59.000000000 -0700 @@ -180,6 +180,7 @@ var $invalidResizeTypes4 = array('CLOB','BLOB','TEXT','DATE','TIME'); // for changetablesql var $blobSize = 100; /// any varchar/char field this size or greater is treated as a blob /// in other words, we use a text area for editting. + var $charSet; // Added 2004-06-20 by Kevin Jamieson (http://pkp.sfu.ca/) function GetCommentSQL($table,$col) { @@ -392,6 +393,8 @@ list($lines,$pkey) = $this->_GenFields($flds); list(,$first) = each($lines); list(,$column_def) = split("[\t ]+",$first,2); + } else { + $column_def = ''; } return array(sprintf($this->renameColumn,$tabname,$this->NameQuote($oldcolumn),$this->NameQuote($newcolumn),$column_def)); } @@ -730,6 +733,9 @@ return $this->CreateTableSQL($tablename, $flds, $tableoptions); } + $tableflds = $flds; + +/* #2343: Null / Not Null column flag changes not respected by this code. if (is_array($flds)) { // Cycle through the update fields, comparing // existing fields to fields to update. @@ -756,29 +762,65 @@ } } $flds = $holdflds; - } + } */ - // already exists, alter table instead list($lines,$pkey) = $this->_GenFields($flds); - $alter = 'ALTER TABLE ' . $this->TableName($tablename); $sql = array(); + $addSql = array(); + $recreate = false; + // FIXME 2005-08-01 KJ - Warning, horrible kludge ahead for DBMSs that can't alter column types foreach ( $lines as $id => $v ) { if ( isset($cols[$id]) && is_object($cols[$id]) ) { $flds = Lens_ParseArgs($v,','); // We are trying to change the size of the field, if not allowed, simply ignore the request. - if ($flds && in_array(strtoupper(substr($flds[0][1],0,4)),$this->invalidResizeTypes4)) continue; + +/* #2343: Null / Not Null column flag changes not respected by this code. + if ($flds && in_array(strtoupper(substr($flds[0][1],0,4)),$this->invalidResizeTypes4)) continue; +*/ - $sql[] = $alter . $this->alterCol . ' ' . $v; + $alter = $this->AlterColumnSQL($tablename, array($id => $tableflds[$id])); + if (empty($alter)) { + $recreate = true; + } else { + $sql[] = $alter; + } } else { - $sql[] = $alter . $this->addCol . ' ' . $v; + $add = $this->AddColumnSQL($tablename, array($id => $tableflds[$id]));; + unset($tableflds[$id]); + $sql[] = $add; + $addSql[] = $add; } } + if ($recreate) { + $sql = $this->AlterColumnSQL($tablename, false, $tableflds, $tableoptions); + $sql[] = $addSql; + } + return $sql; } + + // Functions for managing the database character encoding + // (for CREATE DATABASE, CREATE TABLE, etc.) + // Added 2004-06-20 by Kevin Jamieson (http://pkp.sfu.ca/) + function GetCharSet() + { + if (!$this->charSet) { + return false; + } else { + return $this->charSet; + } + } + + // SetCharSet - switch the client encoding + function SetCharSet($charset_name) + { + $this->charSet = $charset_name; + } + } // class