From 20c7acd8a4b6dd8ef443fe8b629f699b037f18c2 Mon Sep 17 00:00:00 2001 From: Sergey Tsalkov Date: Wed, 16 Jun 2021 22:11:13 +0000 Subject: [PATCH] DB::parse() lets you generate queries without running them --- db.class.php | 5 +++++ simpletest/BasicTest.php | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/db.class.php b/db.class.php index 4df89a8..81a88b6 100644 --- a/db.class.php +++ b/db.class.php @@ -723,6 +723,11 @@ class MeekroDB { return $return; } + public function parse() { + $args = func_get_args(); + return call_user_func_array(array($this, 'parseQueryParams'), $args); + } + public function queryFirstRow() { $args = func_get_args(); $result = call_user_func_array(array($this, 'query'), $args); diff --git a/simpletest/BasicTest.php b/simpletest/BasicTest.php index 386f71b..9e90f13 100644 --- a/simpletest/BasicTest.php +++ b/simpletest/BasicTest.php @@ -413,6 +413,12 @@ class BasicTest extends SimpleTest { $this->assert($count === '0'); } + function test_10_parse() { + $parsed_query = DB::parse("SELECT * FROM %b WHERE id=%i AND name=%s", 'accounts', 5, 'Joe'); + $correct_query = "SELECT * FROM `accounts` WHERE id=5 AND name='Joe'"; + $this->assert($parsed_query === $correct_query); + } + }