Skip to content

Commit 0f6ed92

Browse files
committed
bugfix
1 parent 5f1bde0 commit 0f6ed92

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Tqdev/PhpCrudApi/Database/GenericReflection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private function getTableColumnsSQL(): string
106106
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 \'\' <> ?';
107107
case 'sqlite':
108108
$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 \'\' <> ?';
110110
}
111111
}
112112

@@ -184,7 +184,7 @@ public function getTableColumns(string $tableName, string $type): array
184184
if ($this->driver == 'mysql') {
185185
foreach ($results as &$result) {
186186
// 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);
188188
$result['DATA_TYPE'] = $matches[1];
189189
if (!$result['CHARACTER_MAXIMUM_LENGTH']) {
190190
if (isset($matches[3])) {
@@ -198,8 +198,8 @@ public function getTableColumns(string $tableName, string $type): array
198198
}
199199
if ($this->driver == 'sqlite') {
200200
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);
203203
if (isset($matches[1])) {
204204
$result['DATA_TYPE'] = $matches[1];
205205
} else {

tests/fixtures/blog_sqlite.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ DROP TABLE IF EXISTS "comments";
1717
CREATE TABLE "comments" (
1818
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
1919
"post_id" integer NOT NULL,
20-
"message" varchar(255) NOT NULL,
20+
"message" VARCHAR(255) NOT NULL,
2121
"category_id" integer NOT NULL,
2222
FOREIGN KEY ("post_id") REFERENCES "posts" ("id") ON DELETE RESTRICT ON UPDATE RESTRICT,
2323
FOREIGN KEY ("category_id") REFERENCES "categories" ("id") ON DELETE RESTRICT ON UPDATE RESTRICT

0 commit comments

Comments
 (0)