/** * This function returns an associated array of default properties for the specified * SQL data type. * * @access public * @override * @param string $type the SQL data type * @return array an associated array of default properties * for the specified data type * * @license http://kohanaframework.org/license * * @see http://www.firebirdsql.org/manual/migration-mssql-data-types.html * @see http://web.firebirdsql.org/dotnetfirebird/firebird-and-dotnet-framework-data-types-mapping.html * @see http://www.promotic.eu/en/pmdoc/Subsystems/Db/FireBird/DataTypes.htm * @see http://www.ibphoenix.com/resources/documents/general/doc_54 */ public function data_type($type) { static $types = array('BLOB' => array('type' => 'Blob', 'max_length' => 2147483647), 'BLOB_ID' => array('type' => 'String'), 'BLOB SUB_TYPE 0' => array('type' => 'Blob', 'max_length' => 2147483647), 'BLOB SUB_TYPE 1' => array('type' => 'Text', 'max_length' => 2147483647), 'BLOB SUB_TYPE 2' => array('type' => 'Text', 'max_length' => 2147483647), 'BLOB SUB_TYPE 3' => array('type' => 'Text', 'max_length' => 2147483647), 'BLOB SUB_TYPE 4' => array('type' => 'Text', 'max_length' => 2147483647), 'BLOB SUB_TYPE 5' => array('type' => 'Blob', 'max_length' => 2147483647), 'BLOB SUB_TYPE 6' => array('type' => 'Text', 'max_length' => 2147483647), 'BLOB SUB_TYPE 7' => array('type' => 'Text', 'max_length' => 2147483647), 'BLOB SUB_TYPE 8' => array('type' => 'Text', 'max_length' => 2147483647), 'BLOB SUB_TYPE 9' => array('type' => 'Text', 'max_length' => 2147483647), 'BLOB SUB_TYPE ACL' => array('type' => 'Text', 'max_length' => 2147483647), 'BLOB SUB_TYPE BLR' => array('type' => 'Text', 'max_length' => 2147483647), 'BLOB SUB_TYPE EXTERNAL_FILE_DESCRIPTION' => array('type' => 'Text', 'max_length' => 2147483647), 'BLOB SUB_TYPE FORMAT' => array('type' => 'Text', 'max_length' => 2147483647), 'BLOB SUB_TYPE RANGES' => array('type' => 'Text', 'max_length' => 2147483647), 'BLOB SUB_TYPE SUMMARY' => array('type' => 'Blob', 'max_length' => 2147483647), 'BLOB SUB_TYPE TEXT' => array('type' => 'Text', 'max_length' => 2147483647), 'BLOB SUB_TYPE TEXT CHARACTER SET' => array('type' => 'Text', 'max_length' => 2147483647), 'BLOB SUB_TYPE TRANSACTION_DESCRIPTION' => array('type' => 'Text', 'max_length' => 2147483647), 'CSTRING' => array('type' => 'String'), 'D_FLOAT' => array('type' => 'Double'), 'INT64' => array('type' => 'Integer', 'range' => array('-9223372036854775808', '9223372036854775807')), 'QUAD' => array('type' => 'Integer', 'range' => array('-9223372036854775808', '9223372036854775807'))); $type = preg_match('/^BLOB SUB_TYPE TEXT CHARACTER SET.*$/i', $type) ? 'BLOB SUB_TYPE TEXT CHARACTER SET' : strtoupper($type); if (isset($types[$type])) { return $types[$type]; } return parent::data_type($type); }
/** * This function returns an associated array of default properties for the specified * SQL data type. * * @access public * @override * @param string $type the SQL data type * @return array an associated array of default properties * for the specified data type * * @license http://kohanaframework.org/license * @see https://github.com/xrado/kohana-mssql * @see http://msdn.microsoft.com/en-us/library/windows/desktop/ms713607%28v=vs.85%29.aspx * @see http://www.firebirdsql.org/manual/migration-mssql-data-types.html */ public function data_type($type) { static $types = array('BIT' => array('type' => 'Binary', 'max_length' => 1, 'nullable' => FALSE), 'DATETIME' => array('type' => 'Integer'), 'IMAGE' => array('type' => 'Blob', 'max_length' => 2147483647), 'MONEY' => array('type' => 'Decimal', 'precision' => 18, 'scale' => 4), 'NTEXT' => array('type' => 'Text', 'max_length' => '1073741823'), 'SMALLDATETIME' => array('type' => 'Integer'), 'SMALLMONEY' => array('type' => 'Decimal', 'precision' => 10, 'scale' => 4), 'SQL_VARIANT' => array('type' => 'Blob', 'varying' => TRUE), 'TINYINT' => array('type' => 'Integer', 'range' => array(0, 255)), 'UNIQUEIDENTIFIER' => array('type' => 'String', 'max_length' => 38)); $type = strtoupper($type); if (isset($types[$type])) { return $types[$type]; } return parent::data_type($type); }
/** * This function returns an associated array of default properties for the specified * SQL data type. * * @access public * @override * @param string $type the SQL data type * @return array an associated array of default properties * for the specified data type * * @license http://kohanaframework.org/license * * @see http://dev.mysql.com/doc/refman/5.0/en/data-types.html */ public function data_type($type) { static $types = array('BLOB' => array('type' => 'Blob', 'max_length' => 65535), 'BOOL' => array('type' => 'Boolean'), 'BIGINT UNSIGNED' => array('type' => 'Integer', 'range' => array(0, '18446744073709551615')), 'DEC UNSIGNED' => array('type' => 'Decimal', 'range' => array(0, NULL)), 'DECIMAL UNSIGNED' => array('type' => 'Decimal', 'range' => array(0, NULL)), 'DOUBLE PRECISION UNSIGNED' => array('type' => 'Double', 'range' => array(0, NULL)), 'DOUBLE UNSIGNED' => array('type' => 'Double', 'range' => array(0, NULL)), 'ENUM' => array('type' => 'String'), 'FIXED' => array('type' => 'Double'), 'FIXED UNSIGNED' => array('type' => 'Double', 'range' => array(0, NULL)), 'FLOAT UNSIGNED' => array('type' => 'Double', 'range' => array(0, NULL)), 'INT UNSIGNED' => array('type' => 'Integer', 'range' => array(0, '4294967295')), 'INTEGER UNSIGNED' => array('type' => 'Integer', 'range' => array(0, '4294967295')), 'LONGBLOB' => array('type' => 'Blob', 'max_length' => '4294967295'), 'LONGTEXT' => array('type' => 'Text', 'max_length' => '4294967295'), 'MEDIUMBLOB' => array('type' => 'Blob', 'max_length' => 16777215), 'MEDIUMINT' => array('type' => 'Integer', 'range' => array(-8388608, 8388607)), 'MEDIUMINT UNSIGNED' => array('type' => 'Integer', 'range' => array(0, 16777215)), 'MEDIUMTEXT' => array('type' => 'Text', 'max_length' => 16777215), 'NUMERIC UNSIGNED' => array('type' => 'Decimal', 'range' => array(0, NULL)), 'POINT' => array('type' => 'Binary'), 'REAL UNSIGNED' => array('type' => 'Double', 'range' => array(0, NULL)), 'SERIAL' => array('type' => 'Integer', 'range' => array(0, '18446744073709551615')), 'SET' => array('type' => 'String'), 'SMALLINT UNSIGNED' => array('type' => 'Integer', 'range' => array(0, 65535)), 'TEXT' => array('type' => 'Text', 'max_length' => 65535), 'TINYBLOB' => array('type' => 'Blob', 'max_length' => 255), 'TINYINT UNSIGNED' => array('type' => 'Integer', 'range' => array(0, 255)), 'TINYTEXT' => array('type' => 'String', 'max_length' => 255), 'YEAR' => array('type' => 'String')); $type = strtoupper($type); $type = trim(preg_replace('/ ZEROFILL/i', '', $type)); if (isset($types[$type])) { return $types[$type]; } return parent::data_type($type); }
public static function schema(&$data, $create_join_table = true) { $table = $data['name']; if (!isset($data['columns']['parent_id'])) { $data['columns']['parent_id'] = array('type' => 'int', 'default' => '0', 'not null' => true); $data['indexes']["idx_{$table}_parent_id"] = array('columns' => array('parent_id')); } if ($create_join_table && !empty($data['name'])) { $table = $data['name'] . '_tree'; $join_schema = array($table => array()); self::schema_join($join_schema[$table], $table); DB_Schema::process($join_schema); } }
public function inspect() { Core::load('DB.Schema'); return DB_Schema::Table($this->connection)->for_table($this->options['table'][0])->inspect(); }
static function process_schema($table, $fields, $engine = false) { Core::load('DB.Schema'); $table_schema = self::fields_to_schema($fields, $table); if ($engine) { $table_schema['mysql_engine'] = $engine; } DB_Schema::process(array($table => $table_schema)); foreach ($fields as $name => $data) { $type = self::type($data); $type->process_schema($name, $data, $table, $fields); } }
public function process_schema() { // process schema modules $modules = $this->schema_modules(); if (!empty($modules)) { foreach ($modules as $name => $module) { CMS::cached_run($module); } } // get data from config $schema = $this->config('schema'); $fields = $this->config('fields'); $tmp1 = (array) $schema; $tmp2 = (array) $fields; if (empty($tmp1) && empty($tmp2)) { return; } if (empty($fields)) { $fields = Core::hash(); } $schema = clone $schema; // some time we have fields without info in schema // fix it $schema_keys = array_keys((array) $schema); $fields_keys = array_keys((array) $fields); $diff = array_diff($fields_keys, $schema_keys); foreach ($diff as $name) { $schema->{$name} = array(); } //fields to schema Core::load('DB.Schema'); Core::load('CMS.Fields'); foreach ($schema as $name => &$table) { if (!empty($fields->{$name})) { $table_fields = $fields->{$name}; $table_name = $name; CMS_Fields::fields_to_schema($fields->{$name}, $name, $table); Events::add_once('db.schema.after_execute.' . $name, function ($tf_schema) use($table_fields, $table_name) { foreach ($table_fields as $tf_name => $tf_data) { $tf_type = CMS_Fields::type($tf_data); $tf_type->process_schema($tf_name, $tf_data, $table_name, $table_fields); } }); } } // remove empty values foreach ($schema as $name => $ttable) { if (empty($ttable)) { unset($schema->{$name}); } } // cache $cname = strtolower($this->get_name()); if (!empty($cname)) { $cache_key = 'cms:component:' . $cname . ':schema:' . md5(serialize($schema)); if ($this->cache->has($cache_key)) { return $this; } $this->cache->set($cache_key, 1, 0); } // run DB_Schema::process_cache($schema); }
public static function process_file($file, $cache = true, $connection = null, $force_update = false) { if (is_file($file)) { $schema = (include $file); if ($cache === true) { $cache = WS::env()->cache; } return DB_Schema::process($schema, $connection, $force_update, $cache); } return false; }