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
This commit is contained in:
2014-09-12 12:56:18 +00:00
parent 5e93c78ddb
commit b2264440a4
2 changed files with 20 additions and 12 deletions

View File

@@ -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 ()

View File

@@ -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)