本文整理汇总了PHP中PMA\libraries\Table::generateFieldSpec方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::generateFieldSpec方法的具体用法?PHP Table::generateFieldSpec怎么用?PHP Table::generateFieldSpec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PMA\libraries\Table
的用法示例。
在下文中一共展示了Table::generateFieldSpec方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PMA_buildColumnCreationStatement
/**
* Initiate the column creation statement according to the table creation or
* add columns to a existing table
*
* @param int $field_cnt number of columns
* @param boolean $is_create_tbl true if requirement is to get the statement
* for table creation
*
* @return array $definitions An array of initial sql statements
* according to the request
*/
function PMA_buildColumnCreationStatement($field_cnt, $is_create_tbl = true)
{
$definitions = array();
for ($i = 0; $i < $field_cnt; ++$i) {
// '0' is also empty for php :-(
if (empty($_REQUEST['field_name'][$i]) && $_REQUEST['field_name'][$i] != '0') {
continue;
}
$definition = PMA_getStatementPrefix($is_create_tbl) . Table::generateFieldSpec(trim($_REQUEST['field_name'][$i]), $_REQUEST['field_type'][$i], $_REQUEST['field_length'][$i], $_REQUEST['field_attribute'][$i], isset($_REQUEST['field_collation'][$i]) ? $_REQUEST['field_collation'][$i] : '', isset($_REQUEST['field_null'][$i]) ? $_REQUEST['field_null'][$i] : 'NOT NULL', $_REQUEST['field_default_type'][$i], $_REQUEST['field_default_value'][$i], isset($_REQUEST['field_extra'][$i]) ? $_REQUEST['field_extra'][$i] : false, isset($_REQUEST['field_comments'][$i]) ? $_REQUEST['field_comments'][$i] : '', isset($_REQUEST['field_virtuality'][$i]) ? $_REQUEST['field_virtuality'][$i] : '', isset($_REQUEST['field_expression'][$i]) ? $_REQUEST['field_expression'][$i] : '');
$definition .= PMA_setColumnCreationStatementSuffix($i, $is_create_tbl);
$definitions[] = $definition;
}
// end for
return $definitions;
}
示例2: testGenerateFieldSpec
/**
* Test for generateFieldSpec
*
* @return void
*/
public function testGenerateFieldSpec()
{
//type is BIT
$name = "PMA_name";
$type = "BIT";
$length = '12';
$attribute = 'PMA_attribute';
$collation = 'PMA_collation';
$null = 'NULL';
$default_type = 'USER_DEFINED';
$default_value = 12;
$extra = 'AUTO_INCREMENT';
$comment = 'PMA_comment';
$virtuality = '';
$expression = '';
$move_to = '-first';
$query = Table::generateFieldSpec($name, $type, $length, $attribute, $collation, $null, $default_type, $default_value, $extra, $comment, $virtuality, $expression, $move_to);
$this->assertEquals("`PMA_name` BIT(12) PMA_attribute NULL DEFAULT b'10' " . "AUTO_INCREMENT COMMENT 'PMA_comment' FIRST", $query);
//type is DOUBLE
$type = "DOUBLE";
$query = Table::generateFieldSpec($name, $type, $length, $attribute, $collation, $null, $default_type, $default_value, $extra, $comment, $virtuality, $expression, $move_to);
$this->assertEquals("`PMA_name` DOUBLE(12) PMA_attribute NULL DEFAULT '12' " . "AUTO_INCREMENT COMMENT 'PMA_comment' FIRST", $query);
//type is BOOLEAN
$type = "BOOLEAN";
$query = Table::generateFieldSpec($name, $type, $length, $attribute, $collation, $null, $default_type, $default_value, $extra, $comment, $virtuality, $expression, $move_to);
$this->assertEquals("`PMA_name` BOOLEAN PMA_attribute NULL DEFAULT TRUE " . "AUTO_INCREMENT COMMENT 'PMA_comment' FIRST", $query);
//$default_type is NULL
$default_type = 'NULL';
$query = Table::generateFieldSpec($name, $type, $length, $attribute, $collation, $null, $default_type, $default_value, $extra, $comment, $virtuality, $expression, $move_to);
$this->assertEquals("`PMA_name` BOOLEAN PMA_attribute NULL DEFAULT NULL " . "AUTO_INCREMENT COMMENT 'PMA_comment' FIRST", $query);
//$default_type is CURRENT_TIMESTAMP
$default_type = 'CURRENT_TIMESTAMP';
$query = Table::generateFieldSpec($name, $type, $length, $attribute, $collation, $null, $default_type, $default_value, $extra, $comment, $virtuality, $expression, $move_to);
$this->assertEquals("`PMA_name` BOOLEAN PMA_attribute NULL DEFAULT CURRENT_TIMESTAMP " . "AUTO_INCREMENT COMMENT 'PMA_comment' FIRST", $query);
//$default_type is NONE
$default_type = 'NONE';
$extra = 'INCREMENT';
$move_to = '-first';
$query = Table::generateFieldSpec($name, $type, $length, $attribute, $collation, $null, $default_type, $default_value, $extra, $comment, $virtuality, $expression, $move_to);
$this->assertEquals("`PMA_name` BOOLEAN PMA_attribute NULL INCREMENT " . "COMMENT 'PMA_comment' FIRST", $query);
}
示例3: generateAlter
/**
* Generates column specification for ALTER syntax
*
* @param string $oldcol old column name
* @param string $newcol new column name
* @param string $type type ('INT', 'VARCHAR', 'BIT', ...)
* @param string $length length ('2', '5,2', '', ...)
* @param string $attribute attribute
* @param string $collation collation
* @param bool|string $null with 'NULL' or 'NOT NULL'
* @param string $default_type whether default is CURRENT_TIMESTAMP,
* NULL, NONE, USER_DEFINED
* @param string $default_value default value for USER_DEFINED default
* type
* @param string $extra 'AUTO_INCREMENT'
* @param string $comment field comment
* @param string $virtuality virtuality of the column
* @param string $expression expression for the virtual column
* @param string $move_to new position for column
*
* @see Table::generateFieldSpec()
*
* @return string field specification
*/
public static function generateAlter($oldcol, $newcol, $type, $length, $attribute, $collation, $null, $default_type, $default_value, $extra, $comment, $virtuality, $expression, $move_to)
{
return Util::backquote($oldcol) . ' ' . Table::generateFieldSpec($newcol, $type, $length, $attribute, $collation, $null, $default_type, $default_value, $extra, $comment, $virtuality, $expression, $move_to);
}