1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 12:20:44 +02:00

Guard type errors in e_db::insert() implementations

This commit is contained in:
Nick Liu
2020-01-17 17:24:06 +01:00
parent b2bd6763de
commit 98911f0b8e
2 changed files with 14 additions and 6 deletions

View File

@@ -774,7 +774,8 @@ class e_db_pdo implements e_db
// See if we need to auto-add field types array // See if we need to auto-add field types array
if(!isset($arg['_FIELD_TYPES'])) if(!isset($arg['_FIELD_TYPES']))
{ {
$arg = array_merge($arg, $this->getFieldDefs($tableName)); $fieldDefs = $this->getFieldDefs($tableName);
if (is_array($fieldDefs)) $arg = array_merge($arg, $fieldDefs);
} }
$argUpdate = $arg; // used when DUPLICATE_KEY_UPDATE is active; $argUpdate = $arg; // used when DUPLICATE_KEY_UPDATE is active;
@@ -801,7 +802,8 @@ class e_db_pdo implements e_db
foreach($arg['data'] as $fk => $fv) foreach($arg['data'] as $fk => $fv)
{ {
$tmp[] = ':'.$fk; $tmp[] = ':'.$fk;
$bind[$fk] = array('value'=>$this->_getPDOValue($fieldTypes[$fk],$fv), 'type'=> $this->_getPDOType($fieldTypes[$fk],$this->_getPDOValue($fieldTypes[$fk],$fv))); $fieldType = isset($fieldTypes[$fk]) ? $fieldTypes[$fk] : null;
$bind[$fk] = array('value'=>$this->_getPDOValue($fieldType,$fv), 'type'=> $this->_getPDOType($fieldType,$this->_getPDOValue($fieldType,$fv)));
} }
$valList= implode(', ', $tmp); $valList= implode(', ', $tmp);
@@ -983,7 +985,8 @@ class e_db_pdo implements e_db
// See if we need to auto-add field types array // See if we need to auto-add field types array
if(!isset($arg['_FIELD_TYPES'])) if(!isset($arg['_FIELD_TYPES']))
{ {
$arg = array_merge($arg, $this->getFieldDefs($tableName)); $fieldDefs = $this->getFieldDefs($tableName);
if (is_array($fieldDefs)) $arg = array_merge($arg, $fieldDefs);
} }
$fieldTypes = $this->_getTypes($arg); $fieldTypes = $this->_getTypes($arg);
@@ -2715,6 +2718,7 @@ class e_db_pdo implements e_db
$baseStruct = $dbAdm->get_current_table($tableName); $baseStruct = $dbAdm->get_current_table($tableName);
$fieldDefs = $dbAdm->parse_field_defs($baseStruct[0][2]); // Required definitions $fieldDefs = $dbAdm->parse_field_defs($baseStruct[0][2]); // Required definitions
if (!$fieldDefs) return false;
$outDefs = array(); $outDefs = array();

View File

@@ -921,7 +921,8 @@ class e_db_mysql implements e_db
// See if we need to auto-add field types array // See if we need to auto-add field types array
if(!isset($arg['_FIELD_TYPES'])) if(!isset($arg['_FIELD_TYPES']))
{ {
$arg = array_merge($arg, $this->getFieldDefs($tableName)); $fieldDefs = $this->getFieldDefs($tableName);
if (is_array($fieldDefs)) $arg = array_merge($arg, $fieldDefs);
} }
$argUpdate = $arg; // used when DUPLICATE_KEY_UPDATE is active; $argUpdate = $arg; // used when DUPLICATE_KEY_UPDATE is active;
@@ -948,7 +949,8 @@ class e_db_mysql implements e_db
foreach($arg['data'] as $fk => $fv) foreach($arg['data'] as $fk => $fv)
{ {
$tmp[] = ($this->pdo == true) ? ':'.$fk : $this->_getFieldValue($fk, $fv, $fieldTypes); $tmp[] = ($this->pdo == true) ? ':'.$fk : $this->_getFieldValue($fk, $fv, $fieldTypes);
$bind[$fk] = array('value'=>$this->_getPDOValue($fieldTypes[$fk],$fv), 'type'=> $this->_getPDOType($fieldTypes[$fk],$this->_getPDOValue($fieldTypes[$fk],$fv))); $fieldType = isset($fieldTypes[$fk]) ? $fieldTypes[$fk] : null;
$bind[$fk] = array('value'=>$this->_getPDOValue($fieldType,$fv), 'type'=> $this->_getPDOType($fieldType,$this->_getPDOValue($fieldType,$fv)));
} }
$valList= implode(', ', $tmp); $valList= implode(', ', $tmp);
@@ -1155,7 +1157,8 @@ class e_db_mysql implements e_db
// See if we need to auto-add field types array // See if we need to auto-add field types array
if(!isset($arg['_FIELD_TYPES'])) if(!isset($arg['_FIELD_TYPES']))
{ {
$arg = array_merge($arg, $this->getFieldDefs($tableName)); $fieldDefs = $this->getFieldDefs($tableName);
if (is_array($fieldDefs)) $arg = array_merge($arg, $fieldDefs);
} }
$fieldTypes = $this->_getTypes($arg); $fieldTypes = $this->_getTypes($arg);
@@ -3155,6 +3158,7 @@ class e_db_mysql implements e_db
$baseStruct = $dbAdm->get_current_table($tableName); $baseStruct = $dbAdm->get_current_table($tableName);
$fieldDefs = $dbAdm->parse_field_defs($baseStruct[0][2]); // Required definitions $fieldDefs = $dbAdm->parse_field_defs($baseStruct[0][2]); // Required definitions
if (!$fieldDefs) return false;
$outDefs = array(); $outDefs = array();