MDL-29415 xmldb - fix get_columns() in oracle to get char based lengths + test
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Sun, 18 Sep 2011 22:34:10 +0000 (00:34 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Sun, 18 Sep 2011 22:34:10 +0000 (00:34 +0200)
lib/dml/oci_native_moodle_database.php
lib/dml/simpletest/testdml.php

index 943dbbb..a007e66 100644 (file)
@@ -477,8 +477,11 @@ class oci_native_moodle_database extends moodle_database {
 
         $this->columns[$table] = array();
 
-        $sql = "SELECT CNAME, COLTYPE, WIDTH, SCALE, PRECISION, NULLS, DEFAULTVAL
-                  FROM COL
+        // We give precedence to CHAR_LENGTH for VARCHAR2 columns over WIDTH because the former is always
+        // BYTE based and, for cross-db operations, we want CHAR based results. See MDL-29415
+        $sql = "SELECT CNAME, COLTYPE, nvl(CHAR_LENGTH, WIDTH) AS WIDTH, SCALE, PRECISION, NULLS, DEFAULTVAL
+                  FROM COL c
+             LEFT JOIN USER_TAB_COLUMNS u ON (u.TABLE_NAME = c.TNAME AND u.COLUMN_NAME = c.CNAME AND u.DATA_TYPE = 'VARCHAR2')
                  WHERE TNAME = UPPER('{" . $table . "}')
               ORDER BY COLNO";
 
index f44e258..a4e6e93 100644 (file)
@@ -751,6 +751,7 @@ class dml_test extends UnitTestCase {
         $field = $columns['name'];
         $this->assertEqual('C', $field->meta_type);
         $this->assertFalse($field->auto_increment);
+        $this->assertEqual(255, $field->max_length);
         $this->assertTrue($field->has_default);
         $this->assertIdentical('lala', $field->default_value);
         $this->assertFalse($field->not_null);