diff --git a/.idea/dataSources.local.xml b/.idea/dataSources.local.xml index f081b67..ab3babf 100644 --- a/.idea/dataSources.local.xml +++ b/.idea/dataSources.local.xml @@ -1,6 +1,6 @@ - + diff --git a/.idea/instarecord.iml b/.idea/instarecord.iml index 0fc59c4..f8118e2 100644 --- a/.idea/instarecord.iml +++ b/.idea/instarecord.iml @@ -2,8 +2,8 @@ - - + + diff --git a/.idea/php.xml b/.idea/php.xml index b980d47..8e2ffea 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -50,22 +50,22 @@ - - + + - - /etc/php/8.1/cli/conf.d/10-mysqlnd.ini, /etc/php/8.1/cli/conf.d/10-opcache.ini, /etc/php/8.1/cli/conf.d/10-pdo.ini, /etc/php/8.1/cli/conf.d/15-xml.ini, /etc/php/8.1/cli/conf.d/20-apcu.ini, /etc/php/8.1/cli/conf.d/20-bcmath.ini, /etc/php/8.1/cli/conf.d/20-calendar.ini, /etc/php/8.1/cli/conf.d/20-ctype.ini, /etc/php/8.1/cli/conf.d/20-curl.ini, /etc/php/8.1/cli/conf.d/20-dom.ini, /etc/php/8.1/cli/conf.d/20-exif.ini, /etc/php/8.1/cli/conf.d/20-ffi.ini, /etc/php/8.1/cli/conf.d/20-fileinfo.ini, /etc/php/8.1/cli/conf.d/20-ftp.ini, /etc/php/8.1/cli/conf.d/20-gd.ini, /etc/php/8.1/cli/conf.d/20-gettext.ini, /etc/php/8.1/cli/conf.d/20-iconv.ini, /etc/php/8.1/cli/conf.d/20-igbinary.ini, /etc/php/8.1/cli/conf.d/20-imagick.ini, /etc/php/8.1/cli/conf.d/20-intl.ini, /etc/php/8.1/cli/conf.d/20-mbstring.ini, /etc/php/8.1/cli/conf.d/20-mcrypt.ini, /etc/php/8.1/cli/conf.d/20-mysqli.ini, /etc/php/8.1/cli/conf.d/20-pdo_mysql.ini, /etc/php/8.1/cli/conf.d/20-phar.ini, /etc/php/8.1/cli/conf.d/20-posix.ini, /etc/php/8.1/cli/conf.d/20-readline.ini, /etc/php/8.1/cli/conf.d/20-redis.ini, /etc/php/8.1/cli/conf.d/20-shmop.ini, /etc/php/8.1/cli/conf.d/20-simplexml.ini, /etc/php/8.1/cli/conf.d/20-sockets.ini, /etc/php/8.1/cli/conf.d/20-ssh2.ini, /etc/php/8.1/cli/conf.d/20-sysvmsg.ini, /etc/php/8.1/cli/conf.d/20-sysvsem.ini, /etc/php/8.1/cli/conf.d/20-sysvshm.ini, /etc/php/8.1/cli/conf.d/20-tokenizer.ini, /etc/php/8.1/cli/conf.d/20-xdebug.ini, /etc/php/8.1/cli/conf.d/20-xmlreader.ini, /etc/php/8.1/cli/conf.d/20-xmlwriter.ini, /etc/php/8.1/cli/conf.d/20-xsl.ini, /etc/php/8.1/cli/conf.d/20-zip.ini - /etc/php/8.1/cli/php.ini + + /etc/php/8.2/cli/conf.d/10-mysqlnd.ini, /etc/php/8.2/cli/conf.d/10-opcache.ini, /etc/php/8.2/cli/conf.d/10-pdo.ini, /etc/php/8.2/cli/conf.d/15-xml.ini, /etc/php/8.2/cli/conf.d/20-apcu.ini, /etc/php/8.2/cli/conf.d/20-bcmath.ini, /etc/php/8.2/cli/conf.d/20-calendar.ini, /etc/php/8.2/cli/conf.d/20-ctype.ini, /etc/php/8.2/cli/conf.d/20-curl.ini, /etc/php/8.2/cli/conf.d/20-dom.ini, /etc/php/8.2/cli/conf.d/20-exif.ini, /etc/php/8.2/cli/conf.d/20-ffi.ini, /etc/php/8.2/cli/conf.d/20-fileinfo.ini, /etc/php/8.2/cli/conf.d/20-ftp.ini, /etc/php/8.2/cli/conf.d/20-gd.ini, /etc/php/8.2/cli/conf.d/20-gettext.ini, /etc/php/8.2/cli/conf.d/20-iconv.ini, /etc/php/8.2/cli/conf.d/20-igbinary.ini, /etc/php/8.2/cli/conf.d/20-imagick.ini, /etc/php/8.2/cli/conf.d/20-intl.ini, /etc/php/8.2/cli/conf.d/20-mbstring.ini, /etc/php/8.2/cli/conf.d/20-mysqli.ini, /etc/php/8.2/cli/conf.d/20-pdo_mysql.ini, /etc/php/8.2/cli/conf.d/20-pdo_pgsql.ini, /etc/php/8.2/cli/conf.d/20-pgsql.ini, /etc/php/8.2/cli/conf.d/20-phar.ini, /etc/php/8.2/cli/conf.d/20-posix.ini, /etc/php/8.2/cli/conf.d/20-readline.ini, /etc/php/8.2/cli/conf.d/20-redis.ini, /etc/php/8.2/cli/conf.d/20-shmop.ini, /etc/php/8.2/cli/conf.d/20-simplexml.ini, /etc/php/8.2/cli/conf.d/20-soap.ini, /etc/php/8.2/cli/conf.d/20-sockets.ini, /etc/php/8.2/cli/conf.d/20-ssh2.ini, /etc/php/8.2/cli/conf.d/20-sysvmsg.ini, /etc/php/8.2/cli/conf.d/20-sysvsem.ini, /etc/php/8.2/cli/conf.d/20-sysvshm.ini, /etc/php/8.2/cli/conf.d/20-tokenizer.ini, /etc/php/8.2/cli/conf.d/20-xdebug.ini, /etc/php/8.2/cli/conf.d/20-xmlreader.ini, /etc/php/8.2/cli/conf.d/20-xmlwriter.ini, /etc/php/8.2/cli/conf.d/20-xsl.ini, /etc/php/8.2/cli/conf.d/20-yaml.ini, /etc/php/8.2/cli/conf.d/20-zip.ini + /etc/php/8.2/cli/php.ini - + @@ -99,18 +99,21 @@ - + + + + @@ -124,6 +127,7 @@ + diff --git a/lib/Database/Query.php b/lib/Database/Query.php index f04fec3..2d5f8e7 100644 --- a/lib/Database/Query.php +++ b/lib/Database/Query.php @@ -437,10 +437,9 @@ protected function processStatementParameters(string $statementText, array $para if ($markerSkip <= 0) { break; - } else { - $markerOffset += $markerIdx + 1; } + $markerOffset = $markerIdx + 1; $markerSkip--; } @@ -451,11 +450,10 @@ protected function processStatementParameters(string $statementText, array $para $extraMarkersStr = ""; for ($i = 0; $i < $extraMarkers; $i++) { - $extraMarkersStr .= ", ?"; + $extraMarkersStr .= ", #_TEMP_MARKER_#"; } $statementText = substr_replace($statementText, $extraMarkersStr, $markerIdx + 1, 0); - $finalizedRow[0] = $statementText; } // Bind each parameter @@ -468,6 +466,9 @@ protected function processStatementParameters(string $statementText, array $para } } + $statementText = str_replace('#_TEMP_MARKER_#', '?', $statementText); + $finalizedRow[0] = $statementText; + return $finalizedRow; } diff --git a/tests/Database/QueryTest.php b/tests/Database/QueryTest.php index c6cc692..c5be0c0 100644 --- a/tests/Database/QueryTest.php +++ b/tests/Database/QueryTest.php @@ -318,6 +318,29 @@ public function testWhereWithAnd() $this->assertEquals('DELETE FROM fruits WHERE (type = ?) AND (color IN (?, ?)) AND (tastes_nice = 1);', $queryString); } + public function testWhereWithMultipleINs() + { + $query = new Query(new Connection(new DatabaseConfig())); + + $query = $query->delete() + ->from('fruits') + ->where('color = ? OR (color IN (?)) OR (color IN (?))', + 'pink', ['red', 'blue', 'orange'], ['blurple', 'black']); + + $queryString = $query->createStatementText(); + + $this->assertEquals('DELETE FROM fruits WHERE (color = ? OR (color IN (?, ?, ?)) OR (color IN (?, ?)));', $queryString); + + $this->assertEquals([ + 'pink', + 'red', + 'blue', + 'orange', + 'blurple', + 'black' + ], $query->getBoundParametersForGeneratedStatement()); + } + public function testHaving() { $query = new Query(new Connection(new DatabaseConfig()));