From 299b90c85e1a4077f4dabdb3147fbf0991f7ab87 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Mon, 28 Apr 2025 05:06:17 +0400 Subject: [PATCH] modifs.mineures sans commentaires --- php/src/db/CapacitorStorage.php | 14 +++++++------- php/src/db/_private/_select.php | 2 +- php/src/db/mysql/MysqlStorage.php | 7 ++++++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/php/src/db/CapacitorStorage.php b/php/src/db/CapacitorStorage.php index 01412d4..2801fca 100644 --- a/php/src/db/CapacitorStorage.php +++ b/php/src/db/CapacitorStorage.php @@ -175,24 +175,24 @@ EOT; ]; protected function _prepareMetadata(): void { - if (!$this->tableExists(self::METADATA_TABLE)) { + if (!$this->tableExists(static::METADATA_TABLE)) { $db = $this->db(); $db->exec([ - "drop table", + "drop table if exists", "table" => self::CHANNELS_TABLE, ]); $db->exec([ - "drop table", + "drop table if exists", "table" => _migration::MIGRATION_TABLE ]); $db->exec([ "create table", - "table" => self::METADATA_TABLE, - "cols" => self::METADATA_COLS, + "table" => static::METADATA_TABLE, + "cols" => static::METADATA_COLS, ]); $db->exec([ "insert", - "into" => self::METADATA_TABLE, + "into" => static::METADATA_TABLE, "values" => [ "name" => "version", "value" => "1", @@ -205,7 +205,7 @@ EOT; const CHANNELS_TABLE = "_channels"; const CHANNELS_COLS = [ - "name" => "varchar primary key", + "name" => "varchar not null primary key", "table_name" => "varchar", "class_name" => "varchar", ]; diff --git a/php/src/db/_private/_select.php b/php/src/db/_private/_select.php index ea343f1..80b0460 100644 --- a/php/src/db/_private/_select.php +++ b/php/src/db/_private/_select.php @@ -83,7 +83,7 @@ class _select extends _common { ## from $from = $query["from"] ?? null; - if (self::consume('from\s+([a-z_][a-z0-9_]*)\s*(?=;?\s*$|\bwhere\b)', $tmpsql, $ms)) { + if (self::consume('from\s+([a-z_][a-z0-9_.]*)\s*(?=;?\s*$|\bwhere\b)', $tmpsql, $ms)) { if ($from === null) $from = $ms[1]; $sql[] = "from"; $sql[] = $from; diff --git a/php/src/db/mysql/MysqlStorage.php b/php/src/db/mysql/MysqlStorage.php index de4e3ff..4f27f1a 100644 --- a/php/src/db/mysql/MysqlStorage.php +++ b/php/src/db/mysql/MysqlStorage.php @@ -35,6 +35,11 @@ class MysqlStorage extends CapacitorStorage { return $found !== null; } + const METADATA_COLS = [ + "name" => "varchar(64) not null primary key", + "value" => "varchar(255)", + ]; + function _getMigration(CapacitorChannel $channel): _mysqlMigration { return new _mysqlMigration(cl::merge([ $this->_createSql($channel), @@ -47,7 +52,7 @@ class MysqlStorage extends CapacitorStorage { } const CHANNELS_COLS = [ - "name" => "varchar(255) primary key", + "name" => "varchar(255) not null primary key", "table_name" => "varchar(64)", "class_name" => "varchar(255)", ];