Maurits van der Schee 5 years ago
parent
commit
0f6ed92ddf

+ 4
- 4
src/Tqdev/PhpCrudApi/Database/GenericReflection.php View File

106
                 return 'SELECT c.name AS "COLUMN_NAME", c.is_nullable AS "IS_NULLABLE", t.Name AS "DATA_TYPE", (c.max_length/2) AS "CHARACTER_MAXIMUM_LENGTH", c.precision AS "NUMERIC_PRECISION", c.scale AS "NUMERIC_SCALE", \'\' AS "COLUMN_TYPE" FROM sys.columns c INNER JOIN sys.types t ON c.user_type_id = t.user_type_id WHERE c.object_id = OBJECT_ID(?) AND \'\' <> ?';
106
                 return 'SELECT c.name AS "COLUMN_NAME", c.is_nullable AS "IS_NULLABLE", t.Name AS "DATA_TYPE", (c.max_length/2) AS "CHARACTER_MAXIMUM_LENGTH", c.precision AS "NUMERIC_PRECISION", c.scale AS "NUMERIC_SCALE", \'\' AS "COLUMN_TYPE" FROM sys.columns c INNER JOIN sys.types t ON c.user_type_id = t.user_type_id WHERE c.object_id = OBJECT_ID(?) AND \'\' <> ?';
107
             case 'sqlite':
107
             case 'sqlite':
108
                 $this->updateSqlLiteReflectionTables();
108
                 $this->updateSqlLiteReflectionTables();
109
-                return 'SELECT "name" AS "COLUMN_NAME", case when "notnull"==1 then \'no\' else \'yes\' end as "IS_NULLABLE", "type" AS "DATA_TYPE", 2147483647 AS "CHARACTER_MAXIMUM_LENGTH", 0 AS "NUMERIC_PRECISION", 0 AS "NUMERIC_SCALE", \'\' AS "COLUMN_TYPE" FROM "sys/columns" WHERE "self" = ? AND \'\' <> ?';
109
+                return 'SELECT "name" AS "COLUMN_NAME", case when "notnull"==1 then \'no\' else \'yes\' end as "IS_NULLABLE", lower("type") AS "DATA_TYPE", 2147483647 AS "CHARACTER_MAXIMUM_LENGTH", 0 AS "NUMERIC_PRECISION", 0 AS "NUMERIC_SCALE", \'\' AS "COLUMN_TYPE" FROM "sys/columns" WHERE "self" = ? AND \'\' <> ?';
110
         }
110
         }
111
     }
111
     }
112
 
112
 
184
         if ($this->driver == 'mysql') {
184
         if ($this->driver == 'mysql') {
185
             foreach ($results as &$result) {
185
             foreach ($results as &$result) {
186
                 // mysql does not properly reflect display width of types
186
                 // mysql does not properly reflect display width of types
187
-                preg_match('|([a-zA-Z]+)(\(([0-9]+)(,([0-9]+))?\))?|', $result['DATA_TYPE'], $matches);
187
+                preg_match('|([a-z]+)(\(([0-9]+)(,([0-9]+))?\))?|', $result['DATA_TYPE'], $matches);
188
                 $result['DATA_TYPE'] = $matches[1];
188
                 $result['DATA_TYPE'] = $matches[1];
189
                 if (!$result['CHARACTER_MAXIMUM_LENGTH']) {
189
                 if (!$result['CHARACTER_MAXIMUM_LENGTH']) {
190
                     if (isset($matches[3])) {
190
                     if (isset($matches[3])) {
198
         }
198
         }
199
         if ($this->driver == 'sqlite') {
199
         if ($this->driver == 'sqlite') {
200
             foreach ($results as &$result) {
200
             foreach ($results as &$result) {
201
-                // mysql does not properly reflect display width of types
202
-                preg_match('|([a-zA-Z]+)(\(([0-9]+)(,([0-9]+))?\))?|', $result['DATA_TYPE'], $matches);
201
+                // sqlite does not properly reflect display width of types
202
+                preg_match('|([a-z]+)(\(([0-9]+)(,([0-9]+))?\))?|', $result['DATA_TYPE'], $matches);
203
                 if (isset($matches[1])) {
203
                 if (isset($matches[1])) {
204
                     $result['DATA_TYPE'] = $matches[1];
204
                     $result['DATA_TYPE'] = $matches[1];
205
                 } else {
205
                 } else {

+ 1
- 1
tests/fixtures/blog_sqlite.sql View File

17
 CREATE TABLE "comments" (
17
 CREATE TABLE "comments" (
18
   "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
18
   "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
19
   "post_id" integer NOT NULL,
19
   "post_id" integer NOT NULL,
20
-  "message" varchar(255) NOT NULL,
20
+  "message" VARCHAR(255) NOT NULL,
21
   "category_id" integer NOT NULL,
21
   "category_id" integer NOT NULL,
22
   FOREIGN KEY ("post_id") REFERENCES "posts" ("id") ON DELETE RESTRICT ON UPDATE RESTRICT,
22
   FOREIGN KEY ("post_id") REFERENCES "posts" ("id") ON DELETE RESTRICT ON UPDATE RESTRICT,
23
   FOREIGN KEY ("category_id") REFERENCES "categories" ("id") ON DELETE RESTRICT ON UPDATE RESTRICT
23
   FOREIGN KEY ("category_id") REFERENCES "categories" ("id") ON DELETE RESTRICT ON UPDATE RESTRICT

Loading…
Cancel
Save