From b2264440a4cecb2490cbfe9b9a4e7b526f1fb263 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Fri, 12 Sep 2014 12:56:18 +0000 Subject: [PATCH] dblayer : add more unittests dblayer : add compatibility in column names with MySQL and SQLite git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1812 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- Tests/dblayerComplet.php | 16 ++++++++++++---- dblayer.php | 16 ++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Tests/dblayerComplet.php b/Tests/dblayerComplet.php index 44855ae..a30f7f4 100644 --- a/Tests/dblayerComplet.php +++ b/Tests/dblayerComplet.php @@ -33,9 +33,16 @@ class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase $db = new dblayer ($dbconfig["dsn"], $dbconfig["username"], $dbconfig["password"], $dbconfig["driver_options"]); $db->table = "grouped"; - $this->setExpectedException ("Exception"); - $res = $db->dropTable(); - // Never generate an error + try + { + $res = $db->dropTable(); + } + catch (Exception $e) + { + + } + // Never generate an error, just drop the table if it exists, and do noting + // if it doesn't exists } public function test_createTable () @@ -68,7 +75,8 @@ class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase "object"=>"/éobj%", "where"=>"\$'\"", "with space"=>"with space")); - $this->assertSame ("1", $res); + // SQLite start at 1, MySQL start at 0... + $this->assertThat($res, $this->lessThanOrEqual(1)); } public function test_read1 () diff --git a/dblayer.php b/dblayer.php index 2afa153..3869e82 100644 --- a/dblayer.php +++ b/dblayer.php @@ -433,9 +433,9 @@ class dblayer extends PDO $display = array_keys ($this->fields); } - $req = "SELECT \""; - $req .= implode ("\",\"", $display); - $req .= "\" FROM `$this->tableprefix$this->table`"; + $req = "SELECT `"; + $req .= implode ("`,`", $display); + $req .= "` FROM `$this->tableprefix$this->table`"; if ($select !== null) { $req .= " WHERE "; @@ -457,7 +457,7 @@ class dblayer extends PDO // name is 'group' // Don't put single quotes : don't work with SQLite // TODO : Test for PostgreSQL (Tested for SQLite and MySQL) - $req .= " \"".$s[0]."\" ".$s[2]." :".md5 ($s[0]); + $req .= " `".$s[0]."` ".$s[2]." :".md5 ($s[0]); } } @@ -661,8 +661,8 @@ class dblayer extends PDO continue; $table = $data[0]; $column = $data[1]; - $req = "SELECT $column FROM `$this->tableprefix$table` ". - "WHERE \"$column\"=:".md5 ($column); + $req = "SELECT `$column` FROM `$this->tableprefix$table` ". + "WHERE `$column`=:".md5 ($column); if ($this->debug) echo "DEBUG : $req\n"; $st = $this->db->prepare ($req); $val = $datasOK[$foreign]; @@ -698,11 +698,11 @@ class dblayer extends PDO foreach ($datasOK as $key=>$val) { if ($i>0) $req .= ","; - $req .= "\"$key\"=:".md5 ($key); + $req .= "`$key`=:".md5 ($key); $i++; } - $req .= " WHERE \"$this->primary\"=:".md5 ($this->primary); + $req .= " WHERE `$this->primary`=:".md5 ($this->primary); if ($this->debug) echo "DEBUG : $req\n"; $st = $this->db->prepare ($req); foreach ($datasOK as $key=>$val)