本文整理匯總了PHP中DboSource::length方法的典型用法代碼示例。如果您正苦於以下問題:PHP DboSource::length方法的具體用法?PHP DboSource::length怎麽用?PHP DboSource::length使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DboSource
的用法示例。
在下文中一共展示了DboSource::length方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testLength
/**
* testLength method
*
* @return void
*/
public function testLength()
{
$result = $this->Dbo->length('varchar(255)');
$expected = 255;
$this->assertSame($expected, $result);
$result = $this->Dbo->length('int(11)');
$expected = 11;
$this->assertSame($expected, $result);
$result = $this->Dbo->length('float(5,3)');
$expected = '5,3';
$this->assertSame($expected, $result);
$result = $this->Dbo->length('decimal(5,2)');
$expected = '5,2';
$this->assertSame($expected, $result);
$result = $this->Dbo->length("enum('test','me','now')");
$expected = 4;
$this->assertSame($expected, $result);
$result = $this->Dbo->length("set('a','b','cd')");
$expected = 2;
$this->assertSame($expected, $result);
$result = $this->Dbo->length(false);
$this->assertTrue($result === null);
$result = $this->Dbo->length('datetime');
$expected = null;
$this->assertSame($expected, $result);
$result = $this->Dbo->length('text');
$expected = null;
$this->assertSame($expected, $result);
}
示例2: length
/**
* Handle SQLServer specific length properties.
* SQLServer handles text types as nvarchar/varchar with a length of -1.
*
* @param mixed $length Either the length as a string, or a Column descriptor object.
* @return mixed null|integer with length of column.
*/
public function length($length)
{
if (is_object($length) && isset($length->Length)) {
$type = strtolower($length->Type);
if ($length->Size > 0) {
return $length->Precision . ',' . $length->Size;
}
if (strpos($type, 'number') !== false) {
if (!empty($length->Precision)) {
return $length->Precision;
} else {
return '11';
}
}
if (strpos($type, 'date') !== false) {
return null;
}
return $length->Length;
}
return parent::length($length);
}
示例3: length
/**
* Gets the length of a database-native column description, or null if no length
*
* @param string $real Real database-layer column type (i.e. "varchar(255)")
* @return int An integer representing the length of the column
*/
public function length($real)
{
$col = $real;
if (strpos($real, '(') !== false) {
list($col, $limit) = explode('(', $real);
}
if ($col === 'uuid') {
return 36;
}
return parent::length($real);
}
示例4: length
/**
* Handle SQLServer specific length properties.
* SQLServer handles text types as nvarchar/varchar with a length of -1.
*
* @param mixed $length Either the length as a string, or a Column descriptor object.
* @return mixed null|integer with length of column.
*/
public function length($length)
{
if (is_object($length) && isset($length->Length)) {
if ($length->Length == -1 && strpos($length->Type, 'char') !== false) {
return null;
}
if (in_array($length->Type, array('nchar', 'nvarchar'))) {
return floor($length->Length / 2);
}
return $length->Length;
}
return parent::length($length);
}
示例5: length
/**
* Handle SQLServer specific length properties.
* SQLServer handles text types as nvarchar/varchar with a length of -1.
*
* @param mixed $length Either the length as a string, or a Column descriptor object.
*
* @return mixed null|integer with length of column.
*/
public function length($length)
{
if (is_object($length) && isset($length->Length)) {
if ($length->Length == -1 && strpos($length->Type, 'char') !== FALSE) {
return NULL;
}
if (in_array($length->Type, array('nchar', 'nvarchar'))) {
return floor($length->Length / 2);
}
if ($length->Type === 'text') {
return NULL;
}
return $length->Length;
}
return parent::length($length);
}