/** * Executes all sub-transactions * @param none * @access protected */ function prepareSQL() { tNG_log::log('tNG_multipleDelete', 'prepareSQL', 'begin'); $failed = false; $ret = null; for ($i = 1; true; $i++) { $tmp = KT_getRealValue("POST", $this->pkName . "_" . $i); if (!isset($tmp)) { break; } $this->multTNGs[$i - 1] = new tNG_delete($this->connection); $this->multTNGs[$i - 1]->setDispatcher($this->dispatcher); $this->multTNGs[$i - 1]->multipleIdx = $i; // register triggers $this->multTNGs[$i - 1]->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "VALUE", true); for ($j = 0; $j < sizeof($this->multTriggers); $j++) { call_user_func_array(array(&$this->multTNGs[$i - 1], "registerConditionalTrigger"), $this->multTriggers[$j]); } // add columns $this->multTNGs[$i - 1]->setTable($this->table); foreach ($this->columns as $colName => $colDetails) { $this->multTNGs[$i - 1]->addColumn($colName, $colDetails['type'], $colDetails['method'], $colDetails['reference'] . "_" . $i); } $this->multTNGs[$i - 1]->setPrimaryKey($this->primaryKey, $this->primaryKeyColumn['type'], "POST", $this->pkName . "_" . $i); $this->multTNGs[$i - 1]->executeTransaction(); if ($this->multTNGs[$i - 1]->getError()) { $failed = true; } } if ($failed) { $ret = new tNG_error('MDEL_ERROR', array(), array()); } tNG_log::log('tNG_multipleDelete', 'prepareSQL', 'end'); return $ret; }
/** * Get the local recordset associated to this transaction * @return object resource Recordset resource * @access protected */ function getLocalRecordset() { tNG_log::log('tNG_custom', 'getLocalRecordset'); $fakeArr = array(); $tmpArr = $this->columns; foreach ($tmpArr as $colName => $colDetails) { $tmpVal = KT_escapeForSql($colDetails['default'], $colDetails['type'], true); $fakeArr[$colName] = $tmpVal; } return $this->getFakeRecordset($fakeArr); }
/** * Prepares the delete SQL query to be executed * @access protected */ function prepareSQL() { tNG_log::log('tNG_delete', 'prepareSQL', 'begin'); parent::prepareSQL(); // check if we have a valid primaryKey if (!$this->primaryKey) { $ret = new tNG_error('DEL_NO_PK_SET', array(), array()); } // check the primary key value if (!isset($this->primaryKeyColumn['value'])) { $ret = new tNG_error('DEL_NO_PK_VAL', array(), array()); } $ret = null; $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . KT_escapeFieldName($this->primaryKey) . ' = '; $sql .= KT_escapeForSql($this->primaryKeyColumn['value'], $this->primaryKeyColumn['type']); $this->setSQL($sql); tNG_log::log('tNG_delete', 'prepareSQL', 'end'); return $ret; }
/** * Retrieve and store the saved values from database; * @return string * @access public */ function saveData() { tNG_log::log('tNG' . $this->transactionType, "saveData"); $keyName = $this->getPrimaryKey(); $keyValue = $this->getPrimaryKeyValue(); $keyType = $this->getColumnType($keyName); $escapedKeyValue = KT_escapeForSql($keyValue, $keyType); $sql = 'SELECT * FROM ' . $this->getTable() . ' WHERE ' . KT_escapeFieldName($keyName) . ' = ' . $escapedKeyValue; $rs = $this->connection->Execute($sql); if ($rs === false) { return new tNG_error('FIELDS_SAVEDATA_ERROR', array(), array($sql, $this->connection->ErrorMsg())); } $this->savedData = $rs->fields; return null; }
/** * executing the transaction (triggers, prepare SQL) * @access protected */ function doTransaction() { tNG_log::log('tNG' . $this->transactionType, 'doTransaction', 'begin'); $tmp = $this->getError(); if (is_object($tmp)) { $this->setError($tmp); $this->executeTriggers("ERROR"); tNG_log::log('tNG' . $this->transactionType, 'doTransaction', 'end'); return false; } //calling the before triggers and terminate execution if we had an error $ret = $this->executeTriggers("BEFORE"); if (is_object($ret)) { $this->setError($ret); $this->executeTriggers("ERROR"); tNG_log::log('tNG' . $this->transactionType, 'doTransaction', 'end'); return false; } //process the SQL for eventual auto-generation $ret = $this->prepareSQL(); if (is_object($ret)) { tNG_log::log('KT_ERROR'); $this->setError($ret); $this->executeTriggers("ERROR"); tNG_log::log('tNG' . $this->transactionType, 'doTransaction', 'end'); return false; } $ret = $this->getError(); if (is_object($ret)) { $this->executeTriggers("ERROR"); tNG_log::log('tNG' . $this->transactionType, 'doTransaction', 'end'); return false; } //executing the transaction if ($this->sql != '') { tNG_log::log('tNG' . $this->transactionType, 'executeTransaction', 'execute sql'); if (!is_array($this->sql)) { $this->transactionResult = $this->connection->Execute($this->sql); } else { for ($i = 0; $i < sizeof($this->sql); $i++) { $this->transactionResult = $this->connection->Execute($this->sql[$i], $this->connection); if ($this->transactionResult === false) { break; } } } //check if the transaction has been done OK if (!$this->transactionResult) { $ret = $this->parseSQLError($this->sql, $this->connection->ErrorMsg()); $this->setError($ret); tNG_log::log('KT_ERROR'); $this->executeTriggers("ERROR"); tNG_log::log('tNG' . $this->transactionType, 'doTransaction', 'end'); return false; } } $ret = $this->postExecuteSql(); if (is_object($ret)) { $this->setError($ret); $this->executeTriggers("ERROR"); tNG_log::log('tNG' . $this->transactionType, 'doTransaction', 'end'); return false; } //if the SQL is a SELECT statement if (is_object($this->transactionResult)) { if ($this->transactionResult->RecordCount() == 0) { $this->transactionResult = null; } } //calling the after triggers $ret = $this->executeTriggers("AFTER"); if (is_object($ret)) { $this->setError($ret); $this->executeTriggers("ERROR"); tNG_log::log('tNG' . $this->transactionType, 'doTransaction', 'end'); return false; } $ret = $this->executeTriggers("END"); if (is_object($ret)) { $this->setError($ret); $this->executeTriggers("ERROR"); tNG_log::log('tNG' . $this->transactionType, 'doTransaction', 'end'); return false; } tNG_log::log('tNG' . $this->transactionType, 'doTransaction', 'end'); return true; }
/** * return the error message * @return string transaction type * @access public */ function getErrorMsg() { $ret_warning = ''; $ret_user = ''; $ret_devel = ''; $errorWasFound = false; for ($i = 0; $i < $this->n; $i++) { list($ret_warning, $ret_user, $ret_devel) = $this->tNGs[$i]->getErrorMsg(); if ($ret_warning != '' || $ret_user != '' || $ret_devel != '') { $errorWasFound = true; break; } } $uniq = uniqid(""); $rethead = ''; //$rethead = '<link href="' . $this->relPath . 'includes/tng/styles/default.css" rel="stylesheet" type="text/css" />' . "\r\n"; //$rethead .= '<script src="' . $this->relPath . 'includes/common/js/base.js" type="text/javascript"></script>' . "\r\n"; //$rethead .= '<script src="' . $this->relPath . 'includes/common/js/utility.js" type="text/javascript"></script>' . "\r\n"; $ret = ''; $txtContent = ""; $txtContent .= "Client IP:\r\n " . $_SERVER['REMOTE_ADDR']; $txtContent .= "\r\n\r\nHost:\r\n " . $_SERVER['HTTP_HOST']; $txtContent .= "\r\n\r\nRequested URI:\r\n " . KT_getFullUri(); $txtContent .= "\r\n\r\nDate:\r\n " . date("Y-m-d H:i:s"); if ($errorWasFound) { if ($ret_warning != '') { $ret .= '<div id="KT_tngwarning">' . $ret_warning . "</div>\r\n"; $txtContent .= "\r\n\r\nWarning:\r\n " . $ret_warning; } if ($ret_user != '') { $ret .= '<div id="KT_tngerror"><label>' . KT_getResource('ERROR_LABEL', 'tNG') . '</label><div>' . $ret_user . '</div></div>' . "\r\n"; $txtContent .= "\r\n\r\n" . KT_getResource('ERROR_LABEL', 'tNG') . "\r\n " . $ret_user; } if ('DEVELOPMENT' == $GLOBALS['tNG_debug_mode']) { $js_err = KT_escapeJS($ret_user); $js_devNotes = KT_escapeJS($ret_devel); $js_os = PHP_OS; $js_webserver = @$_SERVER['SERVER_SOFTWARE']; $js_servermodel = (!file_exists($this->relPath . 'adodb/') ? 'PHP MySQL ' : 'PHP ADODB ') . phpversion(); $js_installation = KT_escapeJS(php_sapi_name()); $js_extensions = KT_escapeJS(var_export(get_loaded_extensions(), true)); $ret = $rethead . $ret; if ($ret_devel != '') { $ret .= '<div id="KT_tngdeverror"><label>Developer Details:</label><div>' . $ret_devel . '</div></div>'; } $tmp = tNG_log::getResult('html', '_' . $uniq); $ret .= '<div id="KT_tngtrace"><label>tNG Execution Trace - <a href="#" onclick="document.getElementById(\'KT_tngtrace_details_' . $uniq . '\').style.display=(document.getElementById(\'KT_tngtrace_details_' . $uniq . '\').style.display!=\'block\'?\'block\':\'none\'); return false;">VIEW</a></label>' . $tmp . '</div>'; } if ("" != $GLOBALS['tNG_debug_log_type'] && $ret_devel != '') { $txtContent .= "\r\n\r\nDeveloper Details:\r\n " . $ret_devel; $tmp = tNG_log::getResult('text', '_' . $uniq); $txtContent .= "\r\n\r\ntNG Execution Trace:\r\n" . $tmp; if ($GLOBALS['tNG_debug_log_type'] == 'logfile') { // log file $logFile = dirname(realpath(__FILE__)) . "/logs/" . date("Ym") . ".log"; $f = @fopen($logFile, "a"); if ($f) { if (flock($f, LOCK_EX)) { // do an exclusive lock fwrite($f, "=== BEGIN MESSAGE ===\r\n"); fwrite($f, $txtContent); fwrite($f, "=== END MESSAGE ===\r\n"); flock($f, LOCK_UN); // release the lock } fclose($f); } } else { $email = new KT_Email(); //$email->setPriority("medium"); $email->sendEmail($GLOBALS['tNG_email_host'], $GLOBALS['tNG_email_port'], $GLOBALS['tNG_email_user'], $GLOBALS['tNG_email_password'], $GLOBALS['tNG_debug_email_from'], $GLOBALS['tNG_debug_email_to'], "", "", $GLOBALS['tNG_debug_email_subject'], "ISO-8859-1", $txtContent, ""); } } } return $ret; }
/** * This function is called once the transaction SQL was actually executed * And only if the execution was succesffully. On insert, it sets the primary key value if it is not set. * @access protected */ function postExecuteSql() { tNG_log::log('tNG_insert', 'postExecuteSql'); if (isset($this->columns[$this->primaryKey])) { $this->primaryKeyColumn['value'] = $this->getColumnValue($this->primaryKey); } else { $this->primaryKeyColumn['value'] = $this->connection->Insert_ID($this->table, $this->primaryKey); } return null; }
/** * Executes all sub-transactions * @access protected */ function prepareSQL() { tNG_log::log('tNG_import', 'prepareSQL', 'begin'); $ret = $this->prepareData(); if ($ret === null) { $this->noSuccess = 0; $this->noSkip = 0; $failed = false; $line = $this->lineStart; $tNGindex = 1; for ($k = 0; $k < count($this->data); $k++) { $dataarr = $this->data[$k]; $skipped = false; $line++; /* if ( !is_array($dataarr) || count($dataarr) < 1 || (count($dataarr) == 1 && reset($dataarr) == '') ) { // skip empty lines continue; } */ // exports the values line to be available for KT_getRealValue and KT_DynamicData unset($GLOBALS[$this->importReference]); $GLOBALS[$this->importReference] = $dataarr; unset($GLOBALS[$this->importReference . '_LINE']); $GLOBALS[$this->importReference . '_LINE'] = $line; $isInsert = true; $uniqueColName = $this->uniqueKey; if ($uniqueColName != '') { $uniqueColDetails = $this->computeMultipleValues($this->columns[$uniqueColName], $tNGindex); if ($uniqueColDetails['value'] != '') { $sql = 'SELECT ' . KT_escapeFieldName($uniqueColName) . ' FROM ' . $this->getTable() . ' WHERE ' . KT_escapeFieldName($uniqueColName) . ' = ' . KT_escapeForSql($uniqueColDetails['value'], $uniqueColDetails['type']); $rs = $this->connection->Execute($sql); if ($rs === false) { $failed = true; $ret = new tNG_error('IMPORT_SQL_ERROR', array(), array($sql, $this->connection->ErrorMsg())); tNG_log::log('KT_ERROR'); break; } if ($rs->recordCount() >= 1) { // duplicates found if ($this->handleDuplicates == "SKIP") { // ignore case $isInsert = false; $this->noSkip++; continue; } if ($this->handleDuplicates == "UPDATE") { // update case $isInsert = false; $this->multTNGs[$tNGindex - 1] = new tNG_update($this->connection); } if ($this->handleDuplicates == "SKIPWITHERROR") { // throw error case $isInsert = false; $skipped = true; $this->noSkip++; $this->multTNGs[$tNGindex - 1] = new tNG_insert($this->connection); $this->multTNGs[$tNGindex - 1]->setError(new tNG_error($this->importType . '_IMPORT_DUPLICATE_ERROR', array($line, $uniqueColDetails['value'], $uniqueColName), array())); } } } } if ($isInsert) { $this->multTNGs[$tNGindex - 1] = new tNG_insert($this->connection); } $this->multTNGs[$tNGindex - 1]->setDispatcher($this->dispatcher); $this->multTNGs[$tNGindex - 1]->multipleIdx = $tNGindex; // register triggers for ($j = 0; $j < sizeof($this->multTriggers); $j++) { call_user_func_array(array(&$this->multTNGs[$tNGindex - 1], "registerConditionalTrigger"), $this->multTriggers[$j]); } $this->multTNGs[$tNGindex - 1]->setTable($this->table); // add columns foreach ($this->columns as $colName => $colDetails) { $colDetails = $this->computeMultipleValues($colDetails, $tNGindex); $this->columns[$colName]['value'] = $colDetails['value']; if ($this->multTNGs[$tNGindex - 1]->transactionType == '_update') { if ($colName != $uniqueColName) { $this->multTNGs[$tNGindex - 1]->addColumn($colName, $colDetails['type'], $colDetails['method'], $colDetails['reference']); } } else { $this->multTNGs[$tNGindex - 1]->addColumn($colName, $colDetails['type'], $colDetails['method'], $colDetails['reference'], $colDetails['default']); } } if ($this->multTNGs[$tNGindex - 1]->transactionType == '_update') { $this->multTNGs[$tNGindex - 1]->setPrimaryKey($uniqueColName, $uniqueColDetails['type'], 'VALUE', $uniqueColDetails['value']); } else { $this->multTNGs[$tNGindex - 1]->setPrimaryKey($this->primaryKey, $this->primaryKeyColumn['type']); } $this->multTNGs[$tNGindex - 1]->compileColumnsValues(); if ($this->getError()) { $this->multTNGs[$tNGindex - 1]->setError($this->getError()); } $this->multTNGs[$tNGindex - 1]->setStarted(true); $this->multTNGs[$tNGindex - 1]->doTransaction(); if (!$skipped) { if ($this->multTNGs[$tNGindex - 1]->getError()) { $err = $this->multTNGs[$tNGindex - 1]->getError(); $tmp_all_errmsg = ''; $tmp_unique_details = ''; if ($uniqueColName != '') { if ($uniqueColDetails['value'] != '') { $tmp_unique_details = ' (' . $uniqueColName . ' = ' . $uniqueColDetails['value'] . ')'; } } foreach ($err->fieldErrors as $tmp_col => $tmp_errmsg) { $tmp_all_errmsg .= "\n<br /> - " . $tmp_col . " : " . $tmp_errmsg; } if ($tmp_all_errmsg == '') { $tmp_all_errmsg = $err->getDetails(); } $lineErr = $line . $tmp_unique_details; $newErr = new tNG_error($this->importType . '_IMPORT_LINE_ERROR', array($lineErr, $tmp_all_errmsg), array()); $this->multTNGs[$tNGindex - 1]->setError($newErr); $failed = true; } else { $this->noSuccess++; if ($this->getPrimaryKey() == $this->multTNGs[$tNGindex - 1]->getPrimaryKey()) { $this->primaryKeyColumn['value'] = $this->multTNGs[$tNGindex - 1]->getPrimaryKeyValue(); } } } $tNGindex++; } if (!$failed) { for ($i = 0; $i < sizeof($this->multTNGs); $i++) { if ($this->multTNGs[$i]->getError()) { $failed = true; $ret = new tNG_error('IMPORT_SKIPPED', array(), array()); tNG_log::log('KT_ERROR'); break; } } } if ($failed) { if ($ret === null) { $ret = new tNG_error('IMPORT_ERROR', array(), array()); tNG_log::log('KT_ERROR'); } if ($this->executeSubSets === false) { for ($i = 0; $i < sizeof($this->multTNGs); $i++) { if (!$this->multTNGs[$i]->getError()) { $this->multTNGs[$i]->setError($ret); $this->multTNGs[$i]->executeTriggers('ERROR'); } } } } if ($this->executeSubSets === false) { $this->noSuccess = 0; } } else { tNG_log::log('KT_ERROR'); } tNG_log::log('tNG_import', 'prepareSQL', 'end'); return $ret; }
/** * Get the recordset associated to this transaction * The fake recordset on error or the local recordset * @params none * @return object resource Recordset resource */ function getRecordset() { tNG_log::log('tNG' . $this->transactionType, "getRecordset"); if ($this->getError()) { $fakeArr = array(); for ($i = 0; $i < sizeof($this->multTNGs); $i++) { if ($this->multTNGs[$i]->getError()) { $fakeArr[$i] = $this->multTNGs[$i]->getFakeRsArr(); } else { for ($j = $i + 1; $j < sizeof($this->multTNGs); $j++) { $this->multTNGs[$j - 1] =& $this->multTNGs[$j]; } array_pop($this->multTNGs); $i--; } } if (sizeof($fakeArr) > 0) { return $this->getFakeRecordset($fakeArr); } } return $this->getLocalRecordset(); }
/** * Get the local recordset associated to this transaction * @return object resource Recordset resource * @access public */ function getLocalRecordset() { tNG_log::log('tNG_update', 'getLocalRecordset'); $sql = ''; $tmpArr = $this->columns; $tmpArr[$this->primaryKey]['type'] = $this->primaryKeyColumn['type']; $tmpArr[$this->primaryKey]['method'] = $this->primaryKeyColumn['method']; $tmpArr[$this->primaryKey]['reference'] = $this->primaryKeyColumn['reference']; foreach ($tmpArr as $colName => $colDetails) { if ($sql != '') { $sql .= ','; } $sql .= KT_escapeFieldName($colName); } $sql .= ', ' . KT_escapeFieldName($this->primaryKey) . ' as ' . KT_escapeFieldName($this->pkName); $sql = 'SELECT ' . $sql . ' FROM ' . $this->table; $sql = $sql . ' WHERE ' . KT_escapeFieldName($this->primaryKey) . ' ='; $pkValue = KT_getRealValue($this->primaryKeyColumn['method'], $this->primaryKeyColumn['reference']); $sql = $sql . KT_escapeForSql($pkValue, $this->primaryKeyColumn['type']); if (isset($this->connection->servermodel)) { $rs = $this->connection->MySQL_Execute($sql); } else { $rs = $this->connection->Execute($sql); } if (!$rs) { tNG_log::log('KT_ERROR'); $this->setError(new tNG_error('UPD_RS', array(), array($this->connection->ErrorMsg(), $sql))); echo $this->dispatcher->getErrorMsg(); exit; } return $rs; }
/** * Get the local recordset associated to this transaction * @return object resource Recordset resource * @access protected */ function getLocalRecordset() { tNG_log::log('tNG_multipleUpdate', 'getLocalRecordset'); $sql = ''; $tmpArr = $this->columns; $tmpArr[$this->primaryKey]['type'] = $this->primaryKeyColumn['type']; $tmpArr[$this->primaryKey]['method'] = $this->primaryKeyColumn['method']; $tmpArr[$this->primaryKey]['reference'] = $this->primaryKeyColumn['reference']; foreach ($tmpArr as $colName => $colDetails) { if ($sql != '') { $sql .= ','; } $sql .= KT_escapeFieldName($colName); } $sql .= ', ' . KT_escapeFieldName($this->primaryKey) . ' as ' . KT_escapeFieldName($this->pkName); $sql = 'SELECT ' . $sql . ' FROM ' . $this->table; $tmp_colValue = KT_getRealValue($this->primaryKeyColumn['method'], $this->primaryKeyColumn['reference'] . "_1"); $pkv = KT_getRealValue($this->primaryKeyColumn['method'], $this->primaryKeyColumn['reference']); if (isset($tmp_colValue)) { $sql = $sql . ' WHERE ' . KT_escapeFieldName($this->primaryKey) . ' IN ('; $sql = $sql . KT_escapeForSql($pkv, $this->primaryKeyColumn['type']); $cnt = 1; while (true) { $tmp_colValue = KT_getRealValue($this->primaryKeyColumn['method'], $this->primaryKeyColumn['reference'] . "_" . $cnt++); if (isset($tmp_colValue)) { $sql = $sql . ", " . KT_escapeForSql($tmp_colValue, $this->primaryKeyColumn['type']); } else { break; } } $sql = $sql . ')'; } else { $sql = $sql . ' WHERE ' . KT_escapeFieldName($this->primaryKey) . '='; $sql = $sql . KT_escapeForSql($pkv, $this->primaryKeyColumn['type']); } $rs = false; if (isset($_SESSION['KT_lastUsedList']) && isset($_SESSION['sorter_tso_' . $_SESSION['KT_lastUsedList']])) { $tmp_sql = $sql . ' ORDER BY ' . $_SESSION['sorter_tso_' . $_SESSION['KT_lastUsedList']]; $table_columns = array(); if (isset($this->connection->servermodel)) { $res = $this->connection->Execute('SELECT * FROM ' . $this->table . ' LIMIT 1'); $table_columns = array_keys($res->fields); } else { $res = $this->connection->MetaColumns($this->table); foreach ($res as $field => $col) { $table_columns[] = $col->name; } } $order_column = str_replace(' DESC', '', $_SESSION['sorter_tso_' . $_SESSION['KT_lastUsedList']]); $order_column = explode('.', $order_column); $order_column = $order_column[count($order_column) - 1]; if (in_array($order_column, $table_columns)) { if (isset($this->connection->servermodel)) { $rs = $this->connection->MySQL_Execute($tmp_sql); } else { $rs = $this->connection->Execute($tmp_sql); } } } if (!$rs) { if (isset($this->connection->servermodel)) { $rs = $this->connection->MySQL_Execute($sql); } else { $rs = $this->connection->Execute($sql); } } if (!$rs) { tNG_log::log('KT_ERROR'); $this->setError(new tNG_error('MUPD_RS', array(), array($this->connection->ErrorMsg(), $sql))); echo $this->dispatcher->getErrorMsg(); exit; } return $rs; }
/** * Executes all sub-transactions * @access protected */ function prepareSQL() { tNG_log::log('tNG_multipleInsert', 'prepareSQL', 'begin'); $ret = null; $this->noSuccess = 0; $failed = false; for ($i = 1; true; $i++) { $tmp = KT_getRealValue("POST", $this->pkName . "_" . $i); if (!isset($tmp)) { break; } $this->multTNGs[$i - 1] = new tNG_insert($this->connection); $this->multTNGs[$i - 1]->setDispatcher($this->dispatcher); $this->multTNGs[$i - 1]->multipleIdx = $i; // register triggers for ($j = 0; $j < sizeof($this->multTriggers); $j++) { call_user_func_array(array(&$this->multTNGs[$i - 1], "registerConditionalTrigger"), $this->multTriggers[$j]); } // add columns $this->multTNGs[$i - 1]->setTable($this->table); foreach ($this->columns as $colName => $colDetails) { if ($colDetails['method'] == 'VALUE') { $reference = $colDetails['reference']; $value = KT_getRealValue($colDetails['method'], $colDetails['reference']); } else { $reference = $colDetails['reference'] . "_" . $i; $value = KT_getRealValue($colDetails['method'], $colDetails['reference'] . "_" . $i); if (!isset($value)) { $reference = $colDetails['reference']; $value = KT_getRealValue($colDetails['method'], $colDetails['reference']); } } $this->columns[$colName]['value'] = $value; $this->multTNGs[$i - 1]->addColumn($colName, $colDetails['type'], $colDetails['method'], $reference, $colDetails['default']); } $this->multTNGs[$i - 1]->setPrimaryKey($this->primaryKey, $this->primaryKeyColumn['type']); $this->multTNGs[$i - 1]->compileColumnsValues(); if ($this->getError()) { $this->multTNGs[$i - 1]->setError($this->getError()); } $this->multTNGs[$i - 1]->setStarted(true); $this->multTNGs[$i - 1]->doTransaction(); if ($this->multTNGs[$i - 1]->getError()) { $sw = $this->multTNGs[$i - 1]->wereValuesSubmitted(); if ($sw) { $failed = true; } else { if ($i != 1) { // if there was an unival error on one of the 2nd-to-last inserts, ignore it. $this->multTNGs[$i - 1]->setError(null); } } } else { $this->noSuccess++; $this->primaryKeyColumn['value'] = $this->multTNGs[$i - 1]->getPrimaryKeyValue(); } } if ($this->noSuccess == 0) { $failed = true; } if ($failed) { $ret = new tNG_error('MINS_ERROR', array(), array()); if ($this->executeSubSets === false) { for ($i = 0; $i < sizeof($this->multTNGs); $i++) { if (!$this->multTNGs[$i]->getError()) { $this->multTNGs[$i]->setError($ret); $this->multTNGs[$i]->executeTriggers('ERROR'); } } } } if ($this->executeSubSets === false) { $this->noSuccess = 0; } tNG_log::log('tNG_multipleInsert', 'prepareSQL', 'end'); return $ret; }