/** * Use to update a table * * @param object $table {@link SmartDbTable} that will be updated * * @see SmartDbTable * * @return bool true if success, false if an error occured */ function updateTable($table) { global $xoopsDB; $ret = true; // if table has a structure, create the table if ($table->getStructure()) { $ret = $table->createTable() && $ret; } // if table is flag for drop, drop it if ($table->_flagForDrop) { $ret = $table->dropTable() && $ret; } // if table has data, insert it if ($table->getData()) { $ret = $table->addData() && $ret; } // if table has new fields to be added, add them if ($table->getNewFields()) { $ret = $table->addNewFields() && $ret; } // if table has altered field, alter the table if ($table->getAlteredFields()) { $ret = $table->alterTable() && $ret; } // if table has updated field values, update the table if ($table->getUpdatedFields()) { $ret = $table->updateFieldsValues($table) && $ret; } // if table has droped field, alter the table if ($table->getDropedFields()) { $ret = $table->dropFields($table) && $ret; } //felix // if table has updated field values, update the table if ($table->getUpdatedWhere()) { $ret = $table->UpdateWhereValues($table) && $ret; } return $ret; }
/** * Use to update a table * * @param object $table {@link icms_db_legacy_updater_Table} that will be updated * @param bool $force force the query even in a GET process * * @see icms_db_legacy_updater_Table * * @return bool true if success, false if an error occured */ function updateTable($table, $force = false) { $ret = true; $table->force = $force; // If table has a structure, create the table if ($table->getStructure()) { $ret = $table->createTable() && $ret; } // If table is flag for drop, drop it if ($table->_flagForDrop) { $ret = $table->dropTable() && $ret; } // If table has data, insert it if ($table->getData()) { $ret = $table->addData() && $ret; } // If table has new fields to be added, add them if ($table->getNewFields()) { $ret = $table->addNewFields() && $ret; } // If table has altered field, alter the table if ($table->getAlteredFields()) { $ret = $table->alterTable() && $ret; } // If table has droped field, alter the table if ($table->getDropedFields()) { $ret = $table->dropFields() && $ret; } // If table has updateAll items, update the table if ($table->getUpdateAll()) { $ret = $table->updateAll() && $ret; } return $ret; }
/** * alter an existing table * * @param string $name name of the table that is intended to be changed. * @param array $changes associative array that contains the details of * each type of change that is intended to be performed. The types of * changes that are currently supported are defined as follows: * * name * New name for the table. * * AddedFields * Associative array with the names of fields to be added as indexes of * the array. The value of each entry of the array should be set to * another associative array with the properties of the fields to be * added. The properties of the fields should be the same as defined by * the Metabase parser. * * Additionally, there should be an entry named Declaration that is * expected to contain the portion of the field declaration already in * DBMS specific SQL code as it is used in the CREATE TABLE statement. * * RemovedFields * Associative array with the names of fields to be removed as indexes of * the array. Currently the values assigned to each entry are ignored. An * empty array should be used for future compatibility. * * RenamedFields * Associative array with the names of fields to be renamed as indexes of * the array. The value of each entry of the array should be set to another * associative array with the entry named name with the new field name and * the entry named Declaration that is expected to contain the portion of * the field declaration already in DBMS specific SQL code as it is used * in the CREATE TABLE statement. * * ChangedFields * Associative array with the names of the fields to be changed as indexes * of the array. Keep in mind that if it is intended to change either the * name of a field and any other properties, the ChangedFields array * entries should have the new names of the fields as array indexes. * * The value of each entry of the array should be set to another * associative array with the properties of the fields to that are meant * to be changed as array entries. These entries should be assigned to the * new values of the respective properties. The properties of the fields * should be the* same as defined by the Metabase parser. * * If the default property is meant to be added, removed or changed, there * should also be an entry with index ChangedDefault assigned to 1. * Similarly, if the notnull constraint is to be added or removed, there * should also be an entry with index ChangedNotNull assigned to 1. * * Additionally, there should be an entry named Declaration that is * expected to contain the portion of the field changed declaration * already in DBMS specific SQL code as it is used in the CREATE TABLE * statement. * * Example * array( * 'name' => 'userlist', * 'AddedFields' => array( * 'quota' => array( * 'type' => 'integer', * 'unsigned' => 1, * 'Declaration' => 'quota INT' * ) * ), * 'RemovedFields' => array( * 'file_limit' => array(), * 'time_limit' => array() * ), * 'ChangedFields' => array( * 'gender' => array( * 'default' => 'M', * 'ChangeDefault' => 1, * 'Declaration' => "gender CHAR(1) DEFAULT 'M'" * ) * ), * 'RenamedFields' => array( * 'sex' => array( * 'name' => 'gender', * 'Declaration' => "gender CHAR(1) DEFAULT 'M'" * ) * ) * ) * * @param boolean $check indicates whether the function should just check * if the DBMS driver can perform the requested table alterations if * the value is TRUE or actually perform them otherwise. * @return mixed MDB_OK on success, a MDB error on failure * @access public */ function alterTable($name, $changes, $check) { $result = $this->loadManager('Alter table'); if (MDB::isError($result)) { return $result; } return $this->manager->alterTable($this, $name, $changes, $check); }
/** * save current TABLE properties, add or modify * * @access public */ function saveProp() { $query = 'CREATE TABLE ' . brackets($this->table) . ' (' . "\n"; if (!$this->isExist) { $error = false; while (list($key, $value) = each($_POST['fieldName'])) { if (!empty($_POST['fieldName'][$key])) { $query .= brackets(cleanFieldName($value)) . ' ' . $_POST['fieldType'][$key] . ($_POST['fieldLength'][$key] ? '(' . SQLiteStripSlashes($_POST['fieldLength'][$key]) . ') ' : ' '); $query .= $_POST['fieldNull'][$key]; if (isset($_POST['primary']) && $_POST['primary'] == $key) { $query .= ' PRIMARY KEY'; } $query .= ($_POST['fieldDefault'][$key] && $_POST['fieldNull'][$key] == 'NOT NULL' ? ' DEFAULT ' . quotes($_POST['fieldDefault'][$key]) : '') . ",\n"; } } $query = substr($query, 0, strlen($query) - 2) . "\n);"; $res = $this->connId->getResId($query); if ($res) { $this->isExist = true; $this->getTableProperties(); displayQuery($query); $this->tablePropView(); echo "<script type=\"text/javascript\">parent.left.location='left.php?dbsel=" . $GLOBALS['dbsel'] . "';</script>"; } return; } else { $listIndexSQL = $this->getIndexSQL(); $oldColumn = array(); $newColumn = array(); $nullToNotNull = array(); if (isset($_POST['after']) && $_POST['after'] == 'START') { while (list($key, $trash) = each($_POST['fieldName'])) { if (!empty($_POST['fieldName'][$key])) { $query .= $this->getPostProp($key); } } } if (is_array($this->infoTable)) { reset($this->infoTable); while (list($cid, $champ) = each($this->infoTable)) { if (isset($_POST['fieldName'][$cid]) && !isset($_POST['after'])) { $query .= $this->getPostProp($cid); $oldColumn[] = $this->infoTable[$cid]['name']; $newColumn[] = cleanFieldName($_POST['fieldName'][$cid]); } else { if ($GLOBALS['action'] == 'delete' && (isset($_POST['modify'][$cid]) && $_POST['modify'][$cid])) { continue; } $oldColumn[] = $this->infoTable[$cid]['name']; $query .= brackets($this->infoTable[$cid]['name']) . ' ' . strtoupper($this->infoTable[$cid]['type']); $query .= $this->infoTable[$cid]['notnull'] ? ' NOT NULL' : ''; $noprimary = isset($GLOBALS['action']) && $GLOBALS['action'] == 'noprimary' && isset($_POST['modify'][$cid]) && $_POST['modify'][$cid]; $addprimary = isset($GLOBALS['action']) && $GLOBALS['action'] == 'addprimary' && isset($_POST['modify'][$cid]) && $_POST['modify'][$cid]; if (!$noprimary && ($addprimary || isset($this->infoTable[$cid]['primary']) && $this->infoTable[$cid]['primary'])) { $query .= ' PRIMARY KEY'; } $query .= ($this->infoTable[$cid]['dflt_value'] && $this->infoTable[$cid]['notnull'] ? ' DEFAULT ' . quotes($this->infoTable[$cid]['dflt_value']) : '') . ",\n"; $newColumn[] = $this->infoTable[$cid]['name']; if (isset($_POST['after']) && $_POST['after'] == (string) $cid) { while (list($key, $trash) = each($_POST['fieldName'])) { if (!empty($_POST['fieldName'][$key])) { $query .= $this->getPostProp($key); } } } } if (isset($_POST['fieldNull'][$cid]) && !$this->infoTable[$cid]['notnull'] && $_POST['fieldNull'][$cid] == 'NOT NULL') { $nullToNotNull[] = $this->infoTable[$cid]['name']; } } } if (isset($_POST['after']) && $_POST['after'] == 'END') { while (list($key, $trash) = each($_POST['fieldName'])) { if (!empty($_POST['fieldName'][$key])) { $query .= $this->getPostProp($key); } } } $query = substr($query, 0, strlen($query) - 2) . "\n);"; } $condDrop = $GLOBALS['action'] == 'delete' && !isset($_POST['modify']); $displayError = false; if (!$condDrop && count($newColumn) > 0) { $GLOBALS['phpSQLiteError'] = ''; set_error_handler('phpSQLiteErrorHandling'); $displayError = $this->connId->alterTable($this->table, $query, $oldColumn, $newColumn, $nullToNotNull); restore_error_handler(); if (!$displayError) { // rebuild index if (is_array($listIndexSQL)) { foreach ($listIndexSQL as $numIndex => $indexSQL) { $res = @$this->connId->getResId($indexSQL['sql']); } } } } else { $this->connId->connId->query("BEGIN;", true, false); $query = 'DROP TABLE ' . brackets($this->table) . ';'; $res = $this->connId->connId->query($query, true, false); $this->connId->connId->query("COMMIT;", true, false); } $this->getTableProperties(); if ($displayError) { displayError($this->connId->errorMessage); } displayQuery($query); if ($GLOBALS['action'] != 'delete') { $this->tablePropView(); echo "<script type=\"text/javascript\">parent.left.location='left.php?dbsel=" . $GLOBALS['dbsel'] . "';</script>"; } else { echo "<script type=\"text/javascript\">parent.left.location='left.php?dbsel=" . $GLOBALS['dbsel'] . "'; parent.main.location='main.php?dbsel=" . $GLOBALS['dbsel'] . "';</script>"; } }