length() public method

Gets the length of a database-native column description, or null if no length
public length ( string $real ) : mixed
$real string Real database-layer column type (i.e. "varchar(255)")
return mixed An integer or string representing the length of the column, or null for unknown length.
 /**
  * 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);
 }
 /**
  * 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);
 }
Example #3
0
 /**
  * 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);
 }
Example #4
0
 /**
  * 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);
 }
Example #5
0
 /**
  * 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);
 }