Merge pull request #3935 from dhensby/pulls/bigint-support

Added MySQL support for Bigint.
This commit is contained in:
Damian Mooyman 2016-10-12 10:20:45 +13:00 committed by GitHub
commit 7aa257594f
4 changed files with 57 additions and 1 deletions

View File

@ -486,6 +486,22 @@ class MySQLSchemaManager extends DBSchemaManager {
return "int(11) not null" . $this->defaultClause($values);
}
/**
* Return a bigint type-formatted string
*
* @param array $values Contains a tokenised list of info about this data type
* @return string
*/
public function bigint($values) {
//For reference, this is what typically gets passed to this function:
//$parts=Array('datatype'=>'bigint', 'precision'=>20, 'null'=>'not null', 'default'=>$this->defaultVal,
// 'arrayValue'=>$this->arrayValue);
//$values=Array('type'=>'bigint', 'parts'=>$parts);
//DB::requireField($this->tableName, $this->name, $values);
return 'bigint(20) not null' . $this->defaultClause($values);
}
/**
* Return a datetime type-formatted string
* For MySQL, we simply return the word 'datetime', no other parameters are necessary

View File

@ -0,0 +1,25 @@
<?php
/**
* Represents a signed 8 byte integer field. Do note PHP running as 32-bit might not work with Bigint properly, as it
* would convert the value to a float when queried from the database since the value is a 64-bit one.
*
* @package framework
* @subpackage model
* @see Int
*/
class BigInt extends Int {
public function requireField() {
$parts = array(
'datatype' => 'bigint',
'precision' => 8,
'null' => 'not null',
'default' => $this->defaultVal,
'arrayValue' => $this->arrayValue
);
$values = array('type' => 'bigint', 'parts' => $parts);
DB::require_field($this->tableName, $this->name, $values);
}
}

View File

@ -160,6 +160,11 @@ class DBFieldTest extends SapphireTest {
$this->assertEquals("00:00:00", $time->getValue());
$time->setValue('00:00:00');
$this->assertEquals("00:00:00", $time->getValue());
/* BigInt behaviour */
$bigInt = singleton('BigInt');
$bigInt->setValue(PHP_INT_MAX);
$this->assertEquals(PHP_INT_MAX, $bigInt->getValue());
}
public function testExists() {

View File

@ -1700,6 +1700,13 @@ class DataObjectTest extends SapphireTest {
}
public function testBigIntField() {
$staff = new DataObjectTest_Staff();
$staff->Salary = PHP_INT_MAX;
$staff->write();
$this->assertEquals(PHP_INT_MAX, DataObjectTest_Staff::get()->byID($staff->ID)->Salary);
}
}
class DataObjectTest_Player extends Member implements TestOnly {
@ -1913,11 +1920,14 @@ class DataObjectTest_EquipmentCompany extends DataObjectTest_Company implements
class DataObjectTest_SubEquipmentCompany extends DataObjectTest_EquipmentCompany implements TestOnly {
private static $db = array(
'SubclassDatabaseField' => 'Varchar'
'SubclassDatabaseField' => 'Varchar',
);
}
class DataObjectTest_Staff extends DataObject implements TestOnly {
private static $db = array(
'Salary' => 'BigInt',
);
private static $has_one = array (
'CurrentCompany' => 'DataObjectTest_Company',
'PreviousCompany' => 'DataObjectTest_Company'