From 4bb5c8b6737f3fbcb0516b46a8210af24dcee6f2 Mon Sep 17 00:00:00 2001 From: Mr Kaos <65438130+Mr-Kaos@users.noreply.github.com> Date: Tue, 5 Dec 2023 10:28:11 +1100 Subject: [PATCH] Correct CREATE TABLE IF NOT EXISTS syntax for MSSQL (#26) --- lib/PicoDb/Driver/Mssql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/PicoDb/Driver/Mssql.php b/lib/PicoDb/Driver/Mssql.php index 2598cf8..4b3e1b7 100644 --- a/lib/PicoDb/Driver/Mssql.php +++ b/lib/PicoDb/Driver/Mssql.php @@ -135,7 +135,7 @@ public function getLastId() */ public function getSchemaVersion() { - $this->pdo->exec("CREATE TABLE IF NOT EXISTS [".$this->schemaTable."] ([version] INT DEFAULT '0')"); + $this->pdo->exec("IF (OBJECT_ID('".$this->schemaTable."')) IS NULL CREATE TABLE [".$this->schemaTable."] ([version] INT DEFAULT '0')"); $rq = $this->pdo->prepare('SELECT [version] FROM ['.$this->schemaTable.']'); $rq->execute();