diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-12-18 15:15:26 -0800 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-12-18 15:15:26 -0800 |
commit | 62fdc2b0dcab8300c7bc87aeed669af4af12553c (patch) | |
tree | e75b40b8e6e0836688a298bef1b7fa6a5c8768ed | |
parent | 277ae281718febddd82846ebbdf7ec3c6380bc07 (diff) | |
parent | cacb66480b4bebc8511842bcc588ffd750ef0c38 (diff) | |
download | nextcloud-server-62fdc2b0dcab8300c7bc87aeed669af4af12553c.tar.gz nextcloud-server-62fdc2b0dcab8300c7bc87aeed669af4af12553c.zip |
Merge pull request #6476 from ogasser/dbal_precision_scale
DB: Support DECIMAL(precision,scale) syntax in XML
-rw-r--r-- | lib/private/db/mdb2schemareader.php | 8 | ||||
-rw-r--r-- | tests/data/db_structure.xml | 3 | ||||
-rw-r--r-- | tests/data/db_structure2.xml | 3 | ||||
-rw-r--r-- | tests/lib/db.php | 29 | ||||
-rw-r--r-- | tests/lib/db/mdb2schemareader.php | 5 | ||||
-rw-r--r-- | tests/lib/db/testschema.xml | 6 |
6 files changed, 51 insertions, 3 deletions
diff --git a/lib/private/db/mdb2schemareader.php b/lib/private/db/mdb2schemareader.php index 511bd1c90bd..b1fd2454cb0 100644 --- a/lib/private/db/mdb2schemareader.php +++ b/lib/private/db/mdb2schemareader.php @@ -183,6 +183,14 @@ class MDB2SchemaReader { $primary = $this->asBool($child); $options['primary'] = $primary; break; + case 'precision': + $precision = (string)$child; + $options['precision'] = $precision; + break; + case 'scale': + $scale = (string)$child; + $options['scale'] = $scale; + break; default: throw new \DomainException('Unknown element: ' . $child->getName()); diff --git a/tests/data/db_structure.xml b/tests/data/db_structure.xml index 5f2edbbc516..bfff2143349 100644 --- a/tests/data/db_structure.xml +++ b/tests/data/db_structure.xml @@ -216,7 +216,8 @@ <type>decimal</type> <default/> <notnull>true</notnull> - <length>15</length> + <precision>12</precision> + <scale>2</scale> </field> </declaration> </table> diff --git a/tests/data/db_structure2.xml b/tests/data/db_structure2.xml index 6cd071451df..ae5f22e9573 100644 --- a/tests/data/db_structure2.xml +++ b/tests/data/db_structure2.xml @@ -113,7 +113,8 @@ <type>decimal</type> <default/> <notnull>true</notnull> - <length>15</length> + <precision>12</precision> + <scale>2</scale> </field> </declaration> </table> diff --git a/tests/lib/db.php b/tests/lib/db.php index 3fcdf8a7dc6..96d5f873b5c 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -40,6 +40,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { $this->table1 = $this->test_prefix.'cntcts_addrsbks'; $this->table2 = $this->test_prefix.'cntcts_cards'; $this->table3 = $this->test_prefix.'vcategory'; + $this->table4 = $this->test_prefix.'decimal'; } public function tearDown() { @@ -172,4 +173,32 @@ class Test_DB extends PHPUnit_Framework_TestCase { $actual = OC_DB::prepare("SELECT `fullname` FROM `$table`")->execute()->fetchOne(); $this->assertSame($expected, $actual); } + + public function testDecimal() { + $table = "*PREFIX*" . $this->table4; + $rowname = 'decimaltest'; + + // Insert, select and delete decimal(12,2) values + $inserts = array('1337133713.37', '1234567890'); + $expects = array('1337133713.37', '1234567890.00'); + + for ($i = 0; $i < count($inserts); $i++) { + $insert = $inserts[$i]; + $expect = $expects[$i]; + + $query = OC_DB::prepare('INSERT INTO `' . $table . '` (`' . $rowname . '`) VALUES (?)'); + $result = $query->execute(array($insert)); + $this->assertEquals(1, $result); + $query = OC_DB::prepare('SELECT `' . $rowname . '` FROM `' . $table . '`'); + $result = $query->execute(); + $this->assertTrue((bool)$result); + $row = $result->fetchRow(); + $this->assertArrayHasKey($rowname, $row); + $this->assertEquals($expect, $row[$rowname]); + $query = OC_DB::prepare('DELETE FROM `' . $table . '`'); + $result = $query->execute(); + $this->assertTrue((bool)$result); + } + } + } diff --git a/tests/lib/db/mdb2schemareader.php b/tests/lib/db/mdb2schemareader.php index 57cafa7c76b..f08996cbeaf 100644 --- a/tests/lib/db/mdb2schemareader.php +++ b/tests/lib/db/mdb2schemareader.php @@ -39,7 +39,7 @@ class MDB2SchemaReader extends \PHPUnit_Framework_TestCase { $this->assertCount(1, $schema->getTables()); $table = $schema->getTable('test_table'); - $this->assertCount(7, $table->getColumns()); + $this->assertCount(8, $table->getColumns()); $this->assertEquals(4, $table->getColumn('integerfield')->getLength()); $this->assertTrue($table->getColumn('integerfield')->getAutoincrement()); @@ -69,6 +69,9 @@ class MDB2SchemaReader extends \PHPUnit_Framework_TestCase { $this->assertTrue($table->getColumn('booleanfield_true')->getDefault()); $this->assertFalse($table->getColumn('booleanfield_false')->getDefault()); + $this->assertEquals(12, $table->getColumn('decimalfield_precision_scale')->getPrecision()); + $this->assertEquals(2, $table->getColumn('decimalfield_precision_scale')->getScale()); + $this->assertCount(2, $table->getIndexes()); $this->assertEquals(array('integerfield'), $table->getIndex('primary')->getUnquotedColumns()); $this->assertTrue($table->getIndex('primary')->isPrimary()); diff --git a/tests/lib/db/testschema.xml b/tests/lib/db/testschema.xml index 509b55ee81f..dfca920a0ef 100644 --- a/tests/lib/db/testschema.xml +++ b/tests/lib/db/testschema.xml @@ -53,6 +53,12 @@ <type>boolean</type> <default>false</default> </field> + <field> + <name>decimalfield_precision_scale</name> + <type>decimal</type> + <precision>12</precision> + <scale>2</scale> + </field> <index> <name>index_primary</name> |