diff --git a/lib/adodb/adodb-active-record.inc.php b/lib/adodb/adodb-active-record.inc.php index ad40640a3ae..5fbe7b90ae7 100644 --- a/lib/adodb/adodb-active-record.inc.php +++ b/lib/adodb/adodb-active-record.inc.php @@ -501,7 +501,8 @@ class ADODB_Active_Record { } break; default: - foreach($cols as $name => $fldobj) { + foreach($cols as $fldobj) { + $name = $fldobj->name; if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value)) { $this->$name = $fldobj->default_value; diff --git a/lib/adodb/adodb-csvlib.inc.php b/lib/adodb/adodb-csvlib.inc.php index 77e63bfb062..8273a17ac6c 100644 --- a/lib/adodb/adodb-csvlib.inc.php +++ b/lib/adodb/adodb-csvlib.inc.php @@ -76,7 +76,7 @@ $ADODB_INCLUDED_CSV = 1; $savefetch = isset($rs->adodbFetchMode) ? $rs->adodbFetchMode : $rs->fetchMode; $class = $rs->connection->arrayClass; - $rs2 = new $class(-1); // Dummy query Id + $rs2 = new $class(ADORecordSet::DUMMY_QUERY_ID); $rs2->timeCreated = $rs->timeCreated; # memcache fix $rs2->sql = $rs->sql; $rs2->oldProvider = $rs->dataProvider; diff --git a/lib/adodb/adodb-datadict.inc.php b/lib/adodb/adodb-datadict.inc.php index 9dfa07a6fcf..7ec6e886ac0 100644 --- a/lib/adodb/adodb-datadict.inc.php +++ b/lib/adodb/adodb-datadict.inc.php @@ -1007,11 +1007,17 @@ class ADODB_DataDict { } /** - "Florian Buzin [ easywe ]" - - This function changes/adds new fields to your table. You don't - have to know if the col is new or not. It will check on its own. - */ + * This function changes/adds new fields to your table. + * + * You don't have to know if the col is new or not. It will check on its own. + * + * @param string $tablename + * @param string $flds + * @param string[] $tableoptions + * @param bool $dropOldFlds + * + * @return string[] Array of SQL Commands + */ function changeTableSQL($tablename, $flds, $tableoptions = false, $dropOldFlds=false) { global $ADODB_FETCH_MODE; @@ -1070,37 +1076,14 @@ class ADODB_DataDict { $flds = $holdflds; } - - // already exists, alter table instead - list($lines,$pkey,$idxs) = $this->_genFields($flds); - // genfields can return FALSE at times - if ($lines == null) $lines = array(); - $alter = 'ALTER TABLE ' . $this->tableName($tablename); - $sql = array(); - - 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. - // $flds[1] holds the type, $flds[2] holds the size -postnuke addition - if ($flds && in_array(strtoupper(substr($flds[0][1],0,4)),$this->invalidResizeTypes4) - && (isset($flds[0][2]) && is_numeric($flds[0][2]))) { - if ($this->debug) ADOConnection::outp(sprintf("

%s cannot be changed to %s currently

", $flds[0][0], $flds[0][1])); - #echo "

$this->alterCol cannot be changed to $flds currently

"; - continue; - } - $sql[] = $alter . $this->alterCol . ' ' . $v; - } else { - $sql[] = $alter . $this->addCol . ' ' . $v; - } - } + $sql = $this->alterColumnSql($tablename, $flds); if ($dropOldFlds) { - foreach ( $cols as $id => $v ) - if ( !isset($lines[$id]) ) - $sql[] = $alter . $this->dropCol . ' ' . $v->name; + foreach ($cols as $id => $v) { + if (!isset($lines[$id])) { + $sql[] = $this->dropColumnSQL($tablename, $flds); + } + } } return $sql; } diff --git a/lib/adodb/adodb-lib.inc.php b/lib/adodb/adodb-lib.inc.php index ced5e12619a..4c2668b26ac 100644 --- a/lib/adodb/adodb-lib.inc.php +++ b/lib/adodb/adodb-lib.inc.php @@ -27,44 +27,30 @@ if (!defined('ADODB_DIR')) die(); global $ADODB_INCLUDED_LIB; $ADODB_INCLUDED_LIB = 1; +/** + * Strip the ORDER BY clause from the outer SELECT. + * + * @param string $sql + * + * @return string + */ function adodb_strip_order_by($sql) { - $rez = preg_match_all('/(\sORDER\s+BY\s(?:[^)](?!LIMIT))*)/is', $sql, $arr); - if ($arr) - { - $tmp = array_pop($arr); - $arr = [1=>array_pop($tmp)]; - } - if ($arr) - if (strpos($arr[1], '(') !== false) { - $at = strpos($sql, $arr[1]); - $cntin = 0; - for ($i=$at, $max=strlen($sql); $i < $max; $i++) { - $ch = $sql[$i]; - if ($ch == '(') { - $cntin += 1; - } elseif($ch == ')') { - $cntin -= 1; - if ($cntin < 0) { - break; - } - } - } - $sql = substr($sql,0,$at).substr($sql,$i); - } else { - $sql = str_replace($arr[1], '', $sql); - } + $num = preg_match_all('/(\sORDER\s+BY\s(?:[^)](?!LIMIT))*)/is', $sql, $matches, PREG_OFFSET_CAPTURE); + if ($num) { + // Get the last match + list($last_order_by, $offset) = array_pop($matches[1]); + // If we find a ')' after the last order by, then it belongs to a + // sub-query, not the outer SQL statement and should not be stripped + if (strpos($sql, ')', $offset) === false) { + $sql = str_replace($last_order_by, '', $sql); + } + } return $sql; } -if (false) { - $sql = 'select * from (select a from b order by a(b),b(c) desc)'; - $sql = '(select * from abc order by 1)'; - die(adodb_strip_order_by($sql)); -} - -function adodb_probetypes(&$array,&$types,$probe=8) +function adodb_probetypes($array,&$types,$probe=8) { // probe and guess the type $types = array(); @@ -96,7 +82,7 @@ function adodb_probetypes(&$array,&$types,$probe=8) // that it is not an integer if (strlen($v) == 0) $types[$i] = 'C'; if (strpos($v,'.') !== false) $types[$i] = 'N'; - else $types[$i] = 'I'; + else $types[$i] = 'I'; continue; } @@ -107,7 +93,7 @@ function adodb_probetypes(&$array,&$types,$probe=8) } -function adodb_transpose(&$arr, &$newarr, &$hdr, &$fobjs) +function adodb_transpose(&$arr, &$newarr, &$hdr, $fobjs) { $oldX = sizeof(reset($arr)); $oldY = sizeof($arr); @@ -135,7 +121,7 @@ function adodb_transpose(&$arr, &$newarr, &$hdr, &$fobjs) } -function _adodb_replace(&$zthis, $table, $fieldArray, $keyCol, $autoQuote, $has_autoinc) +function _adodb_replace($zthis, $table, $fieldArray, $keyCol, $autoQuote, $has_autoinc) { // Add Quote around table name to support use of spaces / reserved keywords $table=sprintf('%s%s%s', $zthis->nameQuote,$table,$zthis->nameQuote); @@ -209,7 +195,7 @@ function _adodb_replace(&$zthis, $table, $fieldArray, $keyCol, $autoQuote, $has_ return ($rs) ? 2 : 0; } -function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=false, +function _adodb_getmenu($zthis, $name,$defstr='',$blank1stItem=true,$multiple=false, $size=0, $selectAttr='',$compareFields0=true) { global $ADODB_FETCH_MODE; @@ -242,6 +228,7 @@ function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=f $value = 'value="' . htmlspecialchars($zval2) . '"'; } + /** @noinspection PhpUndefinedVariableInspection */ $s .= _adodb_getmenu_option($defstr, $compareFields0 ? $zval : $zval2, $value, $zval); $zthis->MoveNext(); @@ -250,7 +237,7 @@ function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=f return $s ."\n\n"; } -function _adodb_getmenu_gp(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=false, +function _adodb_getmenu_gp($zthis, $name,$defstr='',$blank1stItem=true,$multiple=false, $size=0, $selectAttr='',$compareFields0=true) { global $ADODB_FETCH_MODE; @@ -304,6 +291,7 @@ function _adodb_getmenu_gp(&$zthis, $name,$defstr='',$blank1stItem=true,$multipl $s .="\n"; } + /** @noinspection PhpUndefinedVariableInspection */ $s .= _adodb_getmenu_option($defstr, $compareFields0 ? $zval : $zval2, $value, $zval); $zthis->MoveNext(); @@ -349,7 +337,7 @@ function _adodb_getmenu_select($name, $defstr = '', $blank1stItem = true, $html = '