mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Added MySQL support for Bigint.
Conflicts: model/MySQLDatabase.php
This commit is contained in:
parent
801574b9b0
commit
95b66d19b2
@ -486,6 +486,22 @@ class MySQLSchemaManager extends DBSchemaManager {
|
|||||||
return "int(11) not null" . $this->defaultClause($values);
|
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
|
* Return a datetime type-formatted string
|
||||||
* For MySQL, we simply return the word 'datetime', no other parameters are necessary
|
* For MySQL, we simply return the word 'datetime', no other parameters are necessary
|
||||||
|
25
model/fieldtypes/Bigint.php
Normal file
25
model/fieldtypes/Bigint.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -160,6 +160,11 @@ class DBFieldTest extends SapphireTest {
|
|||||||
$this->assertEquals("00:00:00", $time->getValue());
|
$this->assertEquals("00:00:00", $time->getValue());
|
||||||
$time->setValue('00:00:00');
|
$time->setValue('00:00:00');
|
||||||
$this->assertEquals("00:00:00", $time->getValue());
|
$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() {
|
public function testExists() {
|
||||||
|
@ -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 {
|
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 {
|
class DataObjectTest_SubEquipmentCompany extends DataObjectTest_EquipmentCompany implements TestOnly {
|
||||||
private static $db = array(
|
private static $db = array(
|
||||||
'SubclassDatabaseField' => 'Varchar'
|
'SubclassDatabaseField' => 'Varchar',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class DataObjectTest_Staff extends DataObject implements TestOnly {
|
class DataObjectTest_Staff extends DataObject implements TestOnly {
|
||||||
|
private static $db = array(
|
||||||
|
'Salary' => 'BigInt',
|
||||||
|
);
|
||||||
private static $has_one = array (
|
private static $has_one = array (
|
||||||
'CurrentCompany' => 'DataObjectTest_Company',
|
'CurrentCompany' => 'DataObjectTest_Company',
|
||||||
'PreviousCompany' => 'DataObjectTest_Company'
|
'PreviousCompany' => 'DataObjectTest_Company'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user