Exemplo n.º 1
0
 /**
  * Creates a table
  *
  * @param string $tableName
  * @param string $schemaName
  * @param array $definition
  * @return boolean
  * @throws Exception
  */
 public function createTable($tableName, $schemaName, $definition)
 {
     if (is_array($definition) === false) {
         throw new Exception("Invalid definition to create the table '" . $tableName . "'");
     }
     if (isset($definition['columns']) === false || empty($definition['columns']) === true) {
         throw new Exception('The table must contain at least one column');
     }
     return $this->execute($this->_dialect->createTable($tableName, $schemaName, $definition));
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
 /**
  * create a new table
  *
  * @param string $name Name of the database that should be created
  * @param array $fields Associative array that contains the definition of
  *      each field of the new table. The indexes of the array entries are
  *      the names of the fields of the table an the array entry values are
  *      associative arrays like those that are meant to be passed with the
  *      field definitions to get[Type]Declaration() functions.
  *
  *      Example
  *        array(
  *            'id' => array(
  *                'type' => 'integer',
  *                'unsigned' => 1
  *                'notnull' => 1
  *                'default' => 0
  *            ),
  *            'name' => array(
  *                'type' => 'text',
  *                'length' => 12
  *            ),
  *            'password' => array(
  *                'type' => 'text',
  *                'length' => 12
  *            )
  *        );
  * @return mixed MDB_OK on success, a MDB error on failure
  * @access public
  */
 function createTable($name, $fields)
 {
     $result = $this->loadManager('Create table');
     if (MDB::isError($result)) {
         return $result;
     }
     return $this->manager->createTable($this, $name, $fields);
 }
Exemplo n.º 4
0
 /**
  * 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;
 }