本文整理匯總了PHP中DboSource::buildColumn方法的典型用法代碼示例。如果您正苦於以下問題:PHP DboSource::buildColumn方法的具體用法?PHP DboSource::buildColumn怎麽用?PHP DboSource::buildColumn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DboSource
的用法示例。
在下文中一共展示了DboSource::buildColumn方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testBuildColumn
/**
* test building columns with SQLite
*
* @return void
*/
public function testBuildColumn()
{
$data = array('name' => 'int_field', 'type' => 'integer', 'null' => false);
$result = $this->Dbo->buildColumn($data);
$expected = '"int_field" integer NOT NULL';
$this->assertEquals($expected, $result);
$data = array('name' => 'name', 'type' => 'string', 'length' => 20, 'null' => false);
$result = $this->Dbo->buildColumn($data);
$expected = '"name" varchar(20) NOT NULL';
$this->assertEquals($expected, $result);
$data = array('name' => 'testName', 'type' => 'string', 'length' => 20, 'default' => null, 'null' => true, 'collate' => 'NOCASE');
$result = $this->Dbo->buildColumn($data);
$expected = '"testName" varchar(20) DEFAULT NULL COLLATE NOCASE';
$this->assertEquals($expected, $result);
$data = array('name' => 'testName', 'type' => 'string', 'length' => 20, 'default' => 'test-value', 'null' => false);
$result = $this->Dbo->buildColumn($data);
$expected = '"testName" varchar(20) DEFAULT \'test-value\' NOT NULL';
$this->assertEquals($expected, $result);
$data = array('name' => 'testName', 'type' => 'integer', 'length' => 10, 'default' => 10, 'null' => false);
$result = $this->Dbo->buildColumn($data);
$expected = '"testName" integer(10) DEFAULT 10 NOT NULL';
$this->assertEquals($expected, $result);
$data = array('name' => 'testName', 'type' => 'integer', 'length' => 10, 'default' => 10, 'null' => false, 'collate' => 'BADVALUE');
$result = $this->Dbo->buildColumn($data);
$expected = '"testName" integer(10) DEFAULT 10 NOT NULL';
$this->assertEquals($expected, $result);
$data = array('name' => 'huge', 'type' => 'biginteger', 'length' => 20, 'null' => false);
$result = $this->Dbo->buildColumn($data);
$expected = '"huge" bigint(20) NOT NULL';
$this->assertEquals($expected, $result);
$data = array('name' => 'id', 'type' => 'biginteger', 'length' => 20, 'null' => false, 'key' => 'primary');
$result = $this->Dbo->buildColumn($data);
$expected = '"id" bigint(20) NOT NULL PRIMARY KEY';
$this->assertEquals($expected, $result);
}
示例2: testBuildColumn
/**
* test building columns with SQLite
*
* @return void
*/
function testBuildColumn()
{
$data = array('name' => 'int_field', 'type' => 'integer', 'null' => false);
$result = $this->Dbo->buildColumn($data);
$expected = '"int_field" integer NOT NULL';
$this->assertEqual($result, $expected);
$data = array('name' => 'name', 'type' => 'string', 'length' => 20, 'null' => false);
$result = $this->Dbo->buildColumn($data);
$expected = '"name" varchar(20) NOT NULL';
$this->assertEqual($result, $expected);
$data = array('name' => 'testName', 'type' => 'string', 'length' => 20, 'default' => null, 'null' => true, 'collate' => 'NOCASE');
$result = $this->Dbo->buildColumn($data);
$expected = '"testName" varchar(20) DEFAULT NULL COLLATE NOCASE';
$this->assertEqual($result, $expected);
$data = array('name' => 'testName', 'type' => 'string', 'length' => 20, 'default' => 'test-value', 'null' => false);
$result = $this->Dbo->buildColumn($data);
$expected = '"testName" varchar(20) DEFAULT \'test-value\' NOT NULL';
$this->assertEqual($result, $expected);
$data = array('name' => 'testName', 'type' => 'integer', 'length' => 10, 'default' => 10, 'null' => false);
$result = $this->Dbo->buildColumn($data);
$expected = '"testName" integer(10) DEFAULT 10 NOT NULL';
$this->assertEqual($result, $expected);
$data = array('name' => 'testName', 'type' => 'integer', 'length' => 10, 'default' => 10, 'null' => false, 'collate' => 'BADVALUE');
$result = $this->Dbo->buildColumn($data);
$expected = '"testName" integer(10) DEFAULT 10 NOT NULL';
$this->assertEqual($result, $expected);
}
示例3: testBuildColumnBadType
/**
* testBuildColumnBadType method
*
* @expectedException PHPUnit_Framework_Error
* @return void
*/
public function testBuildColumnBadType() {
$data = array(
'name' => 'testName',
'type' => 'varchar(255)',
'default',
'null' => true,
'key'
);
$this->Dbo->buildColumn($data);
}
示例4: testBuildColumn2
/**
* testBuildColumn method
*
* @access public
* @return void
*/
public function testBuildColumn2()
{
$this->expectError();
$data = array('name' => 'testName', 'type' => 'varchar(255)', 'default', 'null' => true, 'key');
$this->Dbo->buildColumn($data);
$data = array('name' => 'testName', 'type' => 'string', 'length' => 255, 'default', 'null' => true, 'key');
$result = $this->Dbo->buildColumn($data);
$expected = '`testName` varchar(255) DEFAULT NULL';
$this->assertEqual($expected, $result);
$data = array('name' => 'int_field', 'type' => 'integer', 'default' => '', 'null' => false);
$restore = $this->Dbo->columns;
$this->Dbo->columns = array('integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'));
$result = $this->Dbo->buildColumn($data);
$expected = '`int_field` int(11) NOT NULL';
$this->assertEqual($expected, $result);
$this->Dbo->fieldParameters['param'] = array('value' => 'COLLATE', 'quote' => false, 'join' => ' ', 'column' => 'Collate', 'position' => 'beforeDefault', 'options' => array('GOOD', 'OK'));
$data = array('name' => 'int_field', 'type' => 'integer', 'default' => '', 'null' => false, 'param' => 'BAD');
$result = $this->Dbo->buildColumn($data);
$expected = '`int_field` int(11) NOT NULL';
$this->assertEqual($expected, $result);
$data = array('name' => 'int_field', 'type' => 'integer', 'default' => '', 'null' => false, 'param' => 'GOOD');
$result = $this->Dbo->buildColumn($data);
$expected = '`int_field` int(11) COLLATE GOOD NOT NULL';
$this->assertEqual($expected, $result);
$this->Dbo->columns = $restore;
$data = array('name' => 'created', 'type' => 'timestamp', 'default' => 'current_timestamp', 'null' => false);
$result = $this->Dbo->buildColumn($data);
$expected = '`created` timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL';
$this->assertEqual($expected, $result);
$data = array('name' => 'created', 'type' => 'timestamp', 'default' => 'CURRENT_TIMESTAMP', 'null' => true);
$result = $this->Dbo->buildColumn($data);
$expected = '`created` timestamp DEFAULT CURRENT_TIMESTAMP';
$this->assertEqual($expected, $result);
$data = array('name' => 'modified', 'type' => 'timestamp', 'null' => true);
$result = $this->Dbo->buildColumn($data);
$expected = '`modified` timestamp NULL';
$this->assertEqual($expected, $result);
$data = array('name' => 'modified', 'type' => 'timestamp', 'default' => null, 'null' => true);
$result = $this->Dbo->buildColumn($data);
$expected = '`modified` timestamp NULL';
$this->assertEqual($expected, $result);
}
示例5: testColumnUseLength
/**
* Tests that column types without default lengths in $columns do not have length values
* applied when generating schemas.
*
* @return void
*/
public function testColumnUseLength()
{
$result = array('name' => 'foo', 'type' => 'string', 'length' => 100, 'default' => 'FOO');
$expected = '"foo" varchar(100) DEFAULT \'FOO\'';
$this->assertEquals($expected, $this->Dbo->buildColumn($result));
$result = array('name' => 'foo', 'type' => 'text', 'length' => 100, 'default' => 'FOO');
$expected = '"foo" text DEFAULT \'FOO\'';
$this->assertEquals($expected, $this->Dbo->buildColumn($result));
}
示例6: buildColumn
/**
* Generate a database-native column schema string
*
* @param array $column An array structured like the following: array('name'=>'value', 'type'=>'value'[, options]),
* where options can be 'default', 'length', or 'key'.
* @return string
*/
public function buildColumn($column)
{
$name = $type = null;
$column += array('null' => true);
extract($column);
if (empty($name) || empty($type)) {
trigger_error(__d('cake_dev', 'Column name or type not defined in schema'), E_USER_WARNING);
return null;
}
if (!isset($this->columns[$type])) {
trigger_error(__d('cake_dev', 'Column type %s does not exist', $type), E_USER_WARNING);
return null;
}
$isPrimary = isset($column['key']) && $column['key'] === 'primary';
if ($isPrimary && $type === 'integer') {
return $this->name($name) . ' ' . $this->columns['primary_key']['name'];
}
$out = parent::buildColumn($column);
if ($isPrimary && $type === 'biginteger') {
$replacement = 'PRIMARY KEY';
if ($column['null'] === false) {
$replacement = 'NOT NULL ' . $replacement;
}
return str_replace($this->columns['primary_key']['name'], $replacement, $out);
}
return $out;
}
示例7: buildColumn
/**
* Generate a Postgres-native column schema string
*
* @param array $column An array structured like the following:
* array('name'=>'value', 'type'=>'value'[, options]),
* where options can be 'default', 'length', or 'key'.
* @return string
*/
function buildColumn($column)
{
$col = $this->columns[$column['type']];
if (!isset($col['length']) && !isset($col['limit'])) {
unset($column['length']);
}
$out = preg_replace('/integer\\([0-9]+\\)/', 'integer', parent::buildColumn($column));
$out = str_replace('integer serial', 'serial', $out);
if (strpos($out, 'timestamp DEFAULT')) {
if (isset($column['null']) && $column['null']) {
$out = str_replace('DEFAULT NULL', '', $out);
} else {
$out = str_replace('DEFAULT NOT NULL', '', $out);
}
}
if (strpos($out, 'DEFAULT DEFAULT')) {
if (isset($column['null']) && $column['null']) {
$out = str_replace('DEFAULT DEFAULT', 'DEFAULT NULL', $out);
} elseif (in_array($column['type'], array('integer', 'float'))) {
$out = str_replace('DEFAULT DEFAULT', 'DEFAULT 0', $out);
} elseif ($column['type'] == 'boolean') {
$out = str_replace('DEFAULT DEFAULT', 'DEFAULT FALSE', $out);
}
}
return $out;
}
示例8: testBuildColumn
/**
* testBuildColumn
*
* @return void
*/
public function testBuildColumn()
{
$column = array('name' => 'id', 'type' => 'integer', 'null' => false, 'default' => '', 'length' => '8', 'key' => 'primary');
$result = $this->db->buildColumn($column);
$expected = '[id] int IDENTITY (1, 1) NOT NULL';
$this->assertEquals($expected, $result);
$column = array('name' => 'client_id', 'type' => 'integer', 'null' => false, 'default' => '0', 'length' => '11');
$result = $this->db->buildColumn($column);
$expected = '[client_id] int DEFAULT 0 NOT NULL';
$this->assertEquals($expected, $result);
$column = array('name' => 'client_id', 'type' => 'integer', 'null' => true);
$result = $this->db->buildColumn($column);
$expected = '[client_id] int NULL';
$this->assertEquals($expected, $result);
// 'name' => 'type' format for columns
$column = array('type' => 'integer', 'name' => 'client_id');
$result = $this->db->buildColumn($column);
$expected = '[client_id] int NULL';
$this->assertEquals($expected, $result);
$column = array('type' => 'string', 'name' => 'name');
$result = $this->db->buildColumn($column);
$expected = '[name] nvarchar(255) NULL';
$this->assertEquals($expected, $result);
$column = array('name' => 'name', 'type' => 'string', 'null' => false, 'default' => '', 'length' => '255');
$result = $this->db->buildColumn($column);
$expected = '[name] nvarchar(255) DEFAULT \'\' NOT NULL';
$this->assertEquals($expected, $result);
$column = array('name' => 'name', 'type' => 'string', 'null' => false, 'length' => '255');
$result = $this->db->buildColumn($column);
$expected = '[name] nvarchar(255) NOT NULL';
$this->assertEquals($expected, $result);
$column = array('name' => 'name', 'type' => 'string', 'null' => false, 'default' => null, 'length' => '255');
$result = $this->db->buildColumn($column);
$expected = '[name] nvarchar(255) NOT NULL';
$this->assertEquals($expected, $result);
$column = array('name' => 'name', 'type' => 'string', 'null' => true, 'default' => null, 'length' => '255');
$result = $this->db->buildColumn($column);
$expected = '[name] nvarchar(255) NULL';
$this->assertEquals($expected, $result);
$column = array('name' => 'name', 'type' => 'string', 'null' => true, 'default' => '', 'length' => '255');
$result = $this->db->buildColumn($column);
$expected = '[name] nvarchar(255) DEFAULT \'\'';
$this->assertEquals($expected, $result);
$column = array('name' => 'body', 'type' => 'text');
$result = $this->db->buildColumn($column);
$expected = '[body] nvarchar(MAX)';
$this->assertEquals($expected, $result);
}
示例9: buildColumn
/**
* Generate a database-native column schema string
*
* @param array $column An array structured like the following: array('name'=>'value', 'type'=>'value'[, options]),
* where options can be 'default', 'length', or 'key'.
* @return string
*/
function buildColumn($column)
{
$result = preg_replace('/(int|integer)\\([0-9]+\\)/i', '$1', parent::buildColumn($column));
if (strpos($result, 'DEFAULT NULL') !== false) {
$result = str_replace('DEFAULT NULL', 'NULL', $result);
} else {
if (array_keys($column) == array('type', 'name')) {
$result .= ' NULL';
}
}
return $result;
}
示例10: buildColumn
/**
* Generate a database-native column schema string
*
* @param array $column An array structured like the following: array('name'=>'value', 'type'=>'value'[, options]),
* where options can be 'default', 'length', or 'key'.
* @return string
* @access public
*/
function buildColumn($column)
{
$name = $type = null;
$column = array_merge(array('null' => true), $column);
extract($column);
if (empty($name) || empty($type)) {
trigger_error('Column name or type not defined in schema', E_USER_WARNING);
return null;
}
if (!isset($this->columns[$type])) {
trigger_error("Column type {$type} does not exist", E_USER_WARNING);
return null;
}
$real = $this->columns[$type];
$out = $this->name($name) . ' ' . $real['name'];
if (isset($column['key']) && $column['key'] == 'primary' && $type == 'integer') {
return $this->name($name) . ' ' . $this->columns['primary_key']['name'];
}
return parent::buildColumn($column);
}
示例11: buildColumn
/**
* Generate a database-native column schema string
*
* @param array $column An array structured like the following: array('name'=>'value', 'type'=>'value'[, options]),
* where options can be 'default', 'length', or 'key'.
* @return string
*/
function buildColumn($column)
{
$result = preg_replace('/(int|integer)\\([0-9]+\\)/i', '$1', parent::buildColumn($column));
$null = isset($column['null']) && $column['null'] == true || array_key_exists('default', $column) && $column['default'] === null || array_keys($column) == array('type', 'name');
$primaryKey = isset($column['key']) && $column['key'] == 'primary';
$stringKey = $primaryKey && $column['type'] != 'integer';
if ($null && !$primaryKey) {
$result .= " NULL";
}
return $result;
}
示例12: testBuildColumnUnsigned
/**
* Test `unsigned` field parameter
*
* @param array $data Column data
* @param string $expected Expected sql part
*
* @return void
*
* @dataProvider buildColumnUnsignedProvider
*/
public function testBuildColumnUnsigned($data, $expected)
{
$result = $this->Dbo->buildColumn($data);
$this->assertEquals($expected, $result);
}
示例13: buildColumn
/**
* Generate a Postgres-native column schema string
*
* @param array $column An array structured like the following: array('name'=>'value', 'type'=>'value'[, options]),
* where options can be 'default', 'length', or 'key'.
* @return string
*/
function buildColumn($column)
{
$out = preg_replace('/integer\\([0-9]+\\)/', 'integer', parent::buildColumn($column));
$out = str_replace('integer serial', 'serial', $out);
if (strpos($out, 'DEFAULT DEFAULT')) {
if (isset($column['null']) && $column['null']) {
$out = str_replace('DEFAULT DEFAULT', 'DEFAULT NULL', $out);
} elseif (in_array($column['type'], array('integer', 'float'))) {
$out = str_replace('DEFAULT DEFAULT', 'DEFAULT 0', $out);
} elseif ($column['type'] == 'boolean') {
$out = str_replace('DEFAULT DEFAULT', 'DEFAULT FALSE', $out);
}
}
return $out;
}
示例14: buildColumn
/**
* Generate a database-native column schema string
*
* @param array $column An array structured like the
* following: array('name'=>'value', 'type'=>'value'[, options]),
* where options can be 'default', 'length', or 'key'.
* @return string
*/
public function buildColumn($column)
{
$result = parent::buildColumn($column);
$result = preg_replace('/(bigint|int|integer)\\([0-9]+\\)/i', '$1', $result);
$result = preg_replace('/(bit)\\([0-9]+\\)/i', '$1', $result);
if (strpos($result, 'DEFAULT NULL') !== false) {
if (isset($column['default']) && $column['default'] === '') {
$result = str_replace('DEFAULT NULL', "DEFAULT ''", $result);
} else {
$result = str_replace('DEFAULT NULL', 'NULL', $result);
}
} elseif (array_keys($column) == array('type', 'name')) {
$result .= ' NULL';
} elseif (strpos($result, "DEFAULT N'")) {
$result = str_replace("DEFAULT N'", "DEFAULT '", $result);
}
return $result;
}
示例15: testBuildColumnUuid
/**
* Test build column working for new uuid types
*/
public function testBuildColumnUuid()
{
$column = array('name' => 'col1', 'type' => 'uuid');
$result = $this->Dbo2->buildColumn($column);
$this->assertEquals('"col1" uuid', $result);
}