/** * @param string $name * @param array $info */ function __construct($name, $info) { $this->name = $name; foreach ($info as $col) { $dbcol = new DBColumn($col); $this->cols[$dbcol->field()] = $dbcol; } }
/** * @throws WrongArgumentException * @return DBTable **/ public function addColumn(DBColumn $column) { $name = $column->getName(); Assert::isFalse(isset($this->columns[$name]), "column '{$name}' already exist"); $this->order[] = $this->columns[$name] = $column; $column->setTable($this); return $this; }
/** * Adds a named DBColumn object to the table * * @param DBColumn $column a column to add to the table * @throws DuplicationException thrown when another column with the same name already added * @return DBTable itself */ function addColumn(DBColumn $column) { $name = $column->getName(); if (isset($this->columns[$name])) { throw new DuplicationException('column', $name); } $this->columns[$name] = $column; return $this; }
function createTable() { $allCats = Module_EComm::getIndexes("ecomm_category", "id", "name", 0); $parentDropDown = array("0" => "- Top Level -"); foreach ($allCats as $key => $val) { $parentDropDown[$key] = $val; } $cols = array('id?', DBColumn::make('!text', 'name', 'Name'), DBColumn::make('!select', 'parent_category', 'Parent Category', $parentDropDown), DBColumn::make('//integer', 'image', 'Image'), DBColumn::make('timestamp', 'date_added', 'Date Added'), DBColumn::make('//text', 'last_modified', 'Last Modified'), DBColumn::make('select', 'status', 'Status', array('1' => 'Active', '0' => 'Inactive')), DBColumn::make('tinymce', 'details', 'Details')); return new DBTable("ecomm_category", __CLASS__, $cols); }
/** */ public function testDiff() { $column1 = DBColumn::fromSQL('id int'); $column2 = DBColumn::fromSQL('id int'); $column3 = DBColumn::fromSQL('num int'); $column4 = DBColumn::fromSQL('name varchar(20)'); $diff1 = $column1->diff($column2); $this->assertEquals('', $diff1); $diff2 = $column1->diff($column3); $this->assertEquals('CHANGE id num int', $diff2); $diff3 = $column1->diff($column4); $this->assertEquals('CHANGE id name varchar(20)', $diff3); }
/** * @param String $sql * @return DBTable */ public static function fromSQL($sql) { if ($sql) { preg_match('/CREATE\\s+TABLE\\s+(\\w+)\\s*\\((.*)\\)/i', $sql, $match); $table = new static(); $table->name = $match[1]; $create_definitions = explode(',', $match[2]); foreach ($create_definitions as $definition) { $column = DBColumn::fromSQL($definition); $table->columns[$column->name] = $column; } return $table; } else { return null; } }
function createTable($table, $class, $customColumns = array()) { $cols = $customColumns; $columns = array(); $done = array(); foreach ($cols as $col) { $done[$col->name()] = true; } foreach ($columns as $col) { $name = $col->get('name'); if (isset($done[$name])) { error_log("Warning: column {$name} is specified twice; check both in {$class}.php and in dbtable"); } else { $cols[] = DBColumn::make($col->get('type'), $name, $col->get('label'), null, $col->get('modifier')); $done[$name] = true; } } $result = new DBTable($table, $class, $cols); return $result; }
function DBTable($dbname, $classname, $columns) { $this->columns = array(); $this->name = $dbname; $this->classname = $classname; foreach ($columns as $key => $column) { if (is_string($column)) { $column = DBColumn::make($column); } $this->columns[$column->name()] = $column; $sql = "select `" . $column->name() . "` from `{$dbname}` where id="; $column->setLoadSQL($sql); $column->setLoadQuery(new Query("{$sql}?", "i")); } $select = "select " . $this->loadColumnNames() . " from `{$dbname}`"; $this->select = $select; $this->fetchQuery = new Query("{$select} where id=?", "i"); $this->fetchAllQuery = new Query($select, ""); $this->deleteQuery = new Query("delete from `{$dbname}` where id=?", "i"); }
function createTable() { $cols = array('id?', DBColumn::make('integer', 'order_nb', 'Order'), DBColumn::make('integer', 'product', 'Product'), DBColumn::make('text', 'product_name', 'Product Name'), DBColumn::make('integer', 'quantity', 'Quantity')); return new DBTable("ecomm_order_detail", __CLASS__, $cols); }
<?php /***************************************************************************** * Copyright (C) 2006-2007, onPHP's MetaConfiguration Builder. * * Generated by onPHP-0.9.128 at 2007-03-31 16:25:48 * * This file is autogenerated - do not edit. * *****************************************************************************/ $schema = new DBSchema(); $schema->addTable(DBTable::create('administrator')->addColumn(DBColumn::create(DataType::create(DataType::BIGINT)->setNull(false), 'id')->setPrimaryKey(true)->setAutoincrement(true))->addColumn(DBColumn::create(DataType::create(DataType::VARCHAR)->setNull(false)->setSize(64), 'username'))->addColumn(DBColumn::create(DataType::create(DataType::VARCHAR)->setNull(false)->setSize(40), 'password')));
function createTable() { $cols = array('id?', DBColumn::make('!select', 'country', 'Country', Address::getCountries()), DBColumn::make('!select', 'province', 'Province / State', Address::getStates()), DBColumn::make('!select', 'tax_class', 'Tax Class', TaxClass::getAllTaxClassesIdAndName()), DBColumn::make('!float', 'tax_rate', 'Tax Rate %'), DBColumn::make('timestamp', 'date_added', 'Date Added'), DBColumn::make('//text', 'last_modified', 'Last Modified'), DBColumn::make('tinymce', 'details', 'Details')); return new DBTable("ecomm_tax_rate", __CLASS__, $cols); }
public function getTableInfo($table) { static $types = array('tinyint' => DataType::SMALLINT, 'smallint' => DataType::SMALLINT, 'int' => DataType::INTEGER, 'mediumint' => DataType::INTEGER, 'bigint' => DataType::BIGINT, 'double' => DataType::DOUBLE, 'decimal' => DataType::NUMERIC, 'char' => DataType::CHAR, 'varchar' => DataType::VARCHAR, 'text' => DataType::TEXT, 'tinytext' => DataType::TEXT, 'mediumtext' => DataType::TEXT, 'date' => DataType::DATE, 'time' => DataType::TIME, 'timestamp' => DataType::TIMESTAMP, 'datetime' => DataType::TIMESTAMP, 'set' => null, 'enum' => null, 'year' => null); try { $result = $this->queryRaw('SHOW COLUMNS FROM ' . $table); } catch (BaseException $e) { throw new ObjectNotFoundException("unknown table '{$table}'"); } $table = new DBTable($table); while ($row = mysql_fetch_assoc($result)) { $name = strtolower($row['Field']); $matches = array(); $info = array('type' => null, 'extra' => null); if (preg_match('~(\\w+)(\\((\\d+?)\\)){0,1}\\s*(\\w*)~', strtolower($row['Type']), $matches)) { $info['type'] = $matches[1]; $info['size'] = $matches[3]; $info['extra'] = $matches[4]; } Assert::isTrue(array_key_exists($info['type'], $types), 'unknown type "' . $types[$info['type']] . '" found in column "' . $name . '"'); if (empty($types[$info['type']])) { continue; } $column = DBColumn::create(DataType::create($types[$info['type']])->setUnsigned(strtolower($info['extra']) == 'unsigned')->setNull(strtolower($row['Null']) == 'yes'), $name)->setAutoincrement(strtolower($row['Extra']) == 'auto_increment')->setPrimaryKey(strtolower($row['Key']) == 'pri'); if ($row['Default']) { $column->setDefault($row['Default']); } $table->addColumn($column); } return $table; }
private static function checkColumn(DBColumn $column) { Assert::isTrue($column->getTable() !== null && $column->getDefault() === null); }
function createTable() { $cols = array('id?', DBColumn::make('!text', 'name', 'Title'), DBColumn::make('!select', 'supplier', 'Supplier', Module_EComm::getIndexes("ecomm_supplier", "id", "name", 0)), DBColumn::make('!select', 'category', 'Category', Module_EComm::getIndexes("ecomm_category", "id", "name", 0)), DBColumn::make('!select', 'producttype', 'Product Type', Module_EComm::getIndexes("ecomm_product_type", "id", "name", 0)), DBColumn::make('!select', 'tax_class', 'Tax Class', Module_EComm::getIndexes("ecomm_tax_class", "id", "name", 0)), DBColumn::make('!integer', 'stock_quantity', 'Stock Quantity'), DBColumn::make('//integer', 'image', 'Image'), DBColumn::make('!float', 'price', 'Price (' . SiteConfig::get("EComm::CurrencySign") . ")"), DBColumn::make('timestamp', 'date_added', 'Date Added'), DBColumn::make('//text', 'last_modified', 'Last Modified'), DBColumn::make('select', 'status', 'Status', array('1' => 'Active', '0' => 'Inactive')), DBColumn::make('tinymce', 'details', 'Details')); return new DBTable("ecomm_product", __CLASS__, $cols); }
function createTable() { $cols = array('id?', DBColumn::make('!integer', 'product', 'Product'), DBColumn::make('!integer', 'pallet_count', 'Pallet Count'), DBColumn::make('!float', 'weight', 'Weight'), DBColumn::make('!select', 'weight_unit', 'Weight Unit', array('KG' => 'KG', 'Cubic Feet' => 'Cubic Feet', 'Cubic Yards' => 'Cubic Yards', 'LB' => 'LB'))); return new DBTable("ecomm_product_properties", __CLASS__, $cols); }
function createTable() { $cols = array('id?', DBColumn::make('//integer', 'user', 'User'), DBColumn::make('//text', 'phone_number', 'Phone number'), DBColumn::make('//integer', 'shipping_address', 'Shipping Address'), DBColumn::make('//integer', 'billing_address', 'Billing Address')); return new DBTable("ecomm_user_details", __CLASS__, $cols); }
function createTable() { $cols = array('id?', DBColumn::make('//integer', 'order_nb', 'Order'), DBColumn::make('select', 'status', 'Order Status', array("Pending" => "Pending", "Shipped" => "Shipped", "Complete" => "Complete")), DBColumn::make('textarea', 'comment', 'Comment')); return new DBTable("ecomm_order_comment", __CLASS__, $cols); }
function createTable() { $cols = array('id?', DBColumn::make('!text', 'name', 'Name'), DBColumn::make('//integer', 'image', 'Image'), DBColumn::make('timestamp', 'date_added', 'Date Added'), DBColumn::make('//text', 'last_modified', 'Last Modified'), DBColumn::make('select', 'status', 'Status', array('1' => 'Active', '0' => 'Inactive')), DBColumn::make('tinymce', 'details', 'Details')); return new DBTable("ecomm_supplier", __CLASS__, $cols); }
function toDialectString(IDialect $dialect) { return $this->getHead($dialect) . ' FOREIGN KEY (' . $this->fields->toDialectString($dialect) . ')' . ' REFERENCES ' . $dialect->quoteIdentifier($this->referencedTable->getName()) . '(' . $this->pkFields->toDialectString($dialect) . ')' . ' ON DELETE ' . $this->associationBreakAction->toDialectString($dialect) . ' ON UPDATE ' . AssociationBreakAction::cascade()->toDialectString($dialect); }
public function preAutoincrement(DBColumn $column) { $column->setDefault(null); return null; }
private static function checkColumn(DBColumn $column) { $type = $column->getType(); Assert::isTrue(($type->getId() == DataType::BIGINT || $type->getId() == DataType::INTEGER) && $column->isPrimaryKey()); }
/** * Convert some data to a SQL value. * * @param DBColumn $col the column. * @param mixed $value the data to convert. * @throws SQLException if an exception occurred. */ public function sqlOf($col, $value) { if ($value === null) { return 'NULL'; } switch ($col->getType()) { case DBColumn::VARCHAR: $precision = $col->getPrecision(); if ($precision && strlen($value) > $precision) { // The length is exceeded } return $this->sqlstr($value); case DBColumn::INTEGER: return intval($value); case DBColumn::DATE: return $this->sqldate($value); break; case DBColumn::DATETIME: return $this->sqldatetime($value); break; case DBColumn::NUMERIC: return is_numeric($value) ? $value : 'NULL'; case DBColumn::BOOLEAN: return $this->sqlstr($value === NULL ? null : ($value ? 'Y' : 'N')); case DBColumn::GROUP: return $this->sqlstr(implode(',', $value)); default: throw new SQLException("Unknown SQL TYPE: " . $this->columnType); } }
function toDialectString(IDialect $dialect) { return 'ALTER TABLE ' . $dialect->quoteIdentifier($this->column->getTable()->getName()) . ' ADD COLUMN ' . $this->column->toDialectString($dialect) . ';'; }
function createTable() { $cols = array('id?', DBColumn::make('integer', 'session', 'Session ID'), DBColumn::make('integer', 'product', 'Product'), DBColumn::make('integer', 'quantity', 'Quantity'), DBColumn::make('integer', 'transaction', 'Transaction')); return new DBTable("ecomm_cart_item", __CLASS__, $cols); }
function createTable() { $cols = array('id?', DBColumn::make('!text', 'ip_address', 'IP Address'), DBColumn::make('select', 'status', 'Status', array('1' => 'Active', '0' => 'Inactive')), DBColumn::make('integer', 'user', 'User'), DBColumn::make('text', 'shipping_class', 'Shipping Class'), DBColumn::make('text', 'payment_class', 'Payment Class')); return new DBTable("ecomm_session", __CLASS__, $cols); }
function createTable() { $cols = array('id?', DBColumn::make('integer', 'is_verified', 'Is Verified'), DBColumn::make('text', 'transaction', 'Transaction'), DBColumn::make('text', 'txnid', 'Paypal Transaction ID'), DBColumn::make('text', 'payment_status', 'Payment Status'), DBColumn::make('text', 'post_string', 'Post fields'), DBColumn::make('text', 'memo', 'Memo')); return new DBTable("ecomm_paypal_ipn", __CLASS__, $cols); }
function addElementTo($args) { parent::addElementTo($args); }
function createTable() { $cols = array('id?', DBColumn::make('text', 'tid', 'Transaction ID'), DBColumn::make('integer', 'user', 'User'), DBColumn::make('text', 'customer_name', 'Customer Name'), DBColumn::make('text', 'user_email', 'Customer Email'), DBColumn::make('text', 'phone', 'Phone number'), DBColumn::make('text', 'shipping_street', 'Shipping street'), DBColumn::make('text', 'shipping_city', 'Shipping City'), DBColumn::make('text', 'shipping_postal', 'Shipping Postal'), DBColumn::make('text', 'shipping_province', 'Shipping Province'), DBColumn::make('text', 'shipping_country', 'Shipping Country'), DBColumn::make('text', 'billing_street', 'Billing Street'), DBColumn::make('text', 'billing_city', 'Billing City'), DBColumn::make('text', 'billing_postal', 'Billing Postal'), DBColumn::make('text', 'billing_province', 'Billing Province'), DBColumn::make('text', 'billing_country', 'Billing Country'), DBColumn::make('text', 'cost_subtotal', 'Sub Total'), DBColumn::make('text', 'cost_tax', 'Tax'), DBColumn::make('text', 'cost_shipping', 'Shipping Cost'), DBColumn::make('text', 'cost_total', 'Total'), DBColumn::make('text', 'ip', 'IP Address'), DBColumn::make('text', 'shipping_class', 'Shipping Class'), DBColumn::make('text', 'payment_class', 'Payment Class'), DBColumn::make('text', 'created', 'Timestamp'), DBColumn::make('textarea', 'delivery_instructions', 'Delivery Instructions'), DBColumn::make('text', 'status', 'Status')); return new DBTable("ecomm_order", __CLASS__, $cols); }
/** * @return void */ private function makeColumn(DBColumn $column, IDialect $dialect) { $this->commaSeparatedQueryParts[] = StringUtils::DELIM_STANDART . "\t" . $column->toDialectString($dialect); }
function createTable() { $cols = array('id?', DBColumn::make('!integer', 'product', 'Product'), DBColumn::make('!integer', 'image', 'Image')); return new DBTable("ecomm_product_alternative_image", __CLASS__, $cols); }