The $cols parameter should be in this format ...
{{code: php
$cols = array(
'col_1' => array(
'type' => (string) bool, char, int, ...
'size' => (int) total length for char|varchar|numeric
'scope' => (int) decimal places for numeric
'default' => (bool) the default value, if any
'require' => (bool) is the value required to be NOT NULL?
'primary' => (bool) is this a primary key column?
'autoinc' => (bool) is this an auto-increment column?
),
'col_2' => array(...)
);
}}
For available field types, see Solar_Sql_Adapter::$_native.
/** * * Creates the table and indexes in the database using $this->_table_cols * and $this->_index. * * @return void * */ protected function _createTableAndIndexes() { /** * Create the table. */ $this->_sql->createTable($this->_table_name, $this->_table_cols); /** * Create the indexes. */ foreach ($this->_index as $name => $info) { try { // create this index $this->_sql->createIndex($this->_table_name, $info['name'], $info['type'] == 'unique', $info['cols']); } catch (Exception $e) { // cancel the whole deal. $this->_sql->dropTable($this->_table_name); throw $e; } } }
/** * * Overrides the adapter's create Table to manage Oracle's specific needs * for table creation. Creates a portable table. * * The $cols parameter should be in this format ... * * {{code: php * $cols = array( * 'col_1' => array( * 'type' => (string) bool, char, int, ... * 'size' => (int) total length for char|varchar|numeric * 'scope' => (int) decimal places for numeric * 'default' => (bool) the default value, if any * 'require' => (bool) is the value required to be NOT NULL? * 'primary' => (bool) is this a primary key column? * 'autoinc' => (bool) is this an auto-increment column? * ), * 'col_2' => array(...) * ); * }} * * For available field types, see Solar_Sql_Adapter::$_native. * * @param string $table The name of the table to create. * * @param array $cols Array of columns to create. * * @return string An SQL string. * * @todo Instead of stacking errors, stack info, then throw in exception. * */ public function createTable($table, $cols) { $table_name = strtoupper($table); // main creation routine parent::createTable($table, $cols); // create auto-increment triggers foreach ($cols as $col_name => $info) { $name = strtoupper($col_name); if (!empty($info['autoinc'])) { // create a sequence for the auto-increment $this->_createSequence("{$name}_SEQ", 1); // create a trigger for the auto-increment. // Do NOT reformat to have line breaks. // Oracle throws a fit if you do. $stmt = "CREATE OR REPLACE TRIGGER \"IN_{$name}\" " . "BEFORE INSERT ON {$table_name} " . "REFERENCING NEW AS NEW " . "FOR EACH ROW BEGIN " . "SELECT {$name}_SEQ.NEXTVAL INTO :NEW.{$name} FROM DUAL; " . "END;"; $this->query($stmt); } } }