本文整理汇总了PHP中DataType::getBaseType方法的典型用法代码示例。如果您正苦于以下问题:PHP DataType::getBaseType方法的具体用法?PHP DataType::getBaseType怎么用?PHP DataType::getBaseType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataType
的用法示例。
在下文中一共展示了DataType::getBaseType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBaseType
/**
* tests whether the method BaseType returns the correct values
*/
public function testBaseType()
{
$types = array('bit(1)' => 'bit', 'tinyint(2)' => 'tinyint', 'bool' => 'bool', 'smallint(4)' => 'smallint', 'mediumint(8)' => 'mediumint', 'int(10)' => 'int', 'bigint(16)' => 'bigint', 'float(1)' => 'float', 'float' => 'float', 'float(1,1)' => 'float', 'double(14,4)' => 'double', 'decimal(3,5)' => 'decimal', 'char' => 'char', 'varchar(10)' => 'varchar', 'tinytext' => 'tinytext', 'text' => 'text', 'mediumtext' => 'mediumtext', 'longtext' => 'longtext', 'tinyblob' => 'tinyblob', 'blob' => 'blob', 'mediumblob' => 'mediumblob', 'longblob' => 'longblob', 'binary' => 'binary', 'varbinary' => 'varbinary', 'enum(1,2,3)' => 'enum', 'enum(\'1\',\'2\')' => 'enum', 'set(1,2,3)' => 'set', 'set(\'1\',\'2\')' => 'set', 'date' => 'date', 'date(YYYY-MM-DD)' => 'date', 'datetime(YYYY-MM-DD HH:MM:SS)' => 'datetime', 'datetime' => 'datetime', 'timestamp' => 'timestamp', 'time(HH:MM:SS)' => 'time', 'time' => 'time', 'year' => 'year');
foreach ($types as $type => $expected) {
$this->assertEquals($expected, DataType::getBaseType($type));
}
}
示例2: strlen
?>
<tr>
<?php
$columnName = CHtml::encode($column->name);
?>
<td style="font-weight: bold;"><?php
echo $columnName;
?>
</td>
<td><?php
echo strlen($column->dbType) > 50 ? substr($column->dbType, 0, 50) . "..." : $column->dbType;
?>
</td>
<td>
<?php
if (!in_array(DataType::getBaseType($column->dbType), array('set', 'enum'))) {
?>
<?php
echo CHtml::dropDownList($columnName . '[function]', '', $functions);
?>
<?php
}
?>
</td>
<td class="center">
<?php
echo $column->allowNull ? CHtml::checkBox($columnName . '[null]', is_null($row->getAttribute($columnName))) : '';
?>
</td>
<td>
<?php
示例3: exportRowData
/**
* Exports all rows of the given array and writes the dump to the output buffer.
*
* @param array array with identifiers of rows
*/
private function exportRowData()
{
$db = Yii::app()->db;
$pdo = $db->getPdoInstance();
// Columns
$cols = Column::model()->findAllByAttributes(array('TABLE_NAME' => $this->table, 'TABLE_SCHEMA' => $this->schema));
$blobCols = array();
// Create insert statement
if ($this->settings['completeInserts']) {
$columns = array();
$i = 0;
foreach ($cols as $col) {
$columns[] = $db->quoteColumnName($col->COLUMN_NAME);
if (in_array(DataType::getBaseType($col->DATA_TYPE), array('smallblob', 'blob', 'mediumblob', 'longblob'))) {
$blobCols[] = $i;
}
$i++;
}
$columns = ' (' . implode(', ', $columns) . ')';
} else {
$columns = '';
}
$insert = $this->settings['insertCommand'] . ($this->settings['delayedInserts'] ? ' DELAYED' : '') . ($this->settings['ignoreInserts'] ? ' IGNORE' : '') . ' INTO ' . $db->quoteTableName($this->table) . $columns . ' VALUES';
// Find all rows
$rowCount = count($this->rows);
// Settings
$hexBlobs = $this->settings['hexBlobs'];
$rowsPerInsert = (int) $this->settings['rowsPerInsert'];
// Cycle rows
$i = 0;
$k = 1;
foreach ($this->rows as $row) {
// Add comment
if ($i == 0) {
$this->comment('Data for table ' . $db->quoteTableName($this->table));
echo "\n\n";
echo $insert;
}
$attributes = $row->getAttributes();
SqlUtil::FixRow($attributes);
// Escape all contents
foreach ($attributes as $key => $value) {
if ($value === null) {
$attributes[$key] = 'NULL';
} elseif ($hexBlobs && in_array($key, $blobCols) && $value) {
$attributes[$key] = '0x' . bin2hex($value);
} else {
$attributes[$key] = $pdo->quote($value);
}
}
// Add this row
echo "\n (", implode(', ', $attributes), ')';
if ($i == $rowCount - 1) {
echo ";\n\n";
} elseif ($k == $rowsPerInsert) {
echo ";\n\n", $insert;
$k = 0;
} else {
echo ',';
}
$i++;
$k++;
}
}
示例4: exportRowData
/**
* Exports all rows of the given array and writes the dump to the output buffer.
*
* @param array array with identifiers of rows
*/
private function exportRowData()
{
$db = Yii::app()->db;
$pdo = $db->getPdoInstance();
// Columns
$cols = Column::model()->findAllByAttributes(array('TABLE_NAME' => $this->table, 'TABLE_SCHEMA' => $this->schema));
$blobCols = array();
$columns = array();
$i = 0;
foreach ($cols as $col) {
$columns[] = $db->quoteColumnName($col->COLUMN_NAME);
if (in_array(DataType::getBaseType($col->DATA_TYPE), array('smallblob', 'blob', 'mediumblob', 'longblob'))) {
$blobCols[] = $i;
}
$i++;
}
$columns = implode($this->settings['fieldTerminator'], $columns);
$insert = "";
// Find all rows
$rowCount = count($this->rows);
// Settings
$hexBlobs = $this->settings['hexBlobs'];
$rowsPerInsert = (int) $this->settings['rowsPerInsert'];
// Cycle rows
$i = 0;
$k = 1;
foreach ($this->rows as $row) {
if ($i == 0 && $this->settings['fieldsFirstRow']) {
echo $columns;
}
$attributes = $row->getAttributes();
SqlUtil::FixRow($attributes);
// Escape all contents
foreach ($attributes as $key => $value) {
if ($value === null) {
$attributes[$key] = 'NULL';
} elseif ($hexBlobs && in_array($key, $blobCols) && $value) {
$attributes[$key] = '0x' . bin2hex($value);
} else {
$attributes[$key] = $this->settings['fieldEncloseString'] . addcslashes($value, $this->settings['fieldEncloseString']) . $this->settings['fieldEncloseString'];
}
}
echo "\n", implode($this->settings['fieldTerminator'], $attributes);
if ($i == $rowCount - 1) {
echo "\n\n";
}
$i++;
$k++;
}
}
示例5: getDataType
public function getDataType()
{
return DataType::getBaseType($this->DATA_TYPE);
}