summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Gass2020-09-03 11:12:52 +0200
committerNathan Gass2020-09-03 11:13:26 +0200
commit46280806236fedabb9a43e0517817c17c9b0d6bd (patch)
treecc8c8e12fa97c500cf8c24e82bd91a21ad5e80ec
parente69d39a96cbf3f40745bfa2648870b5a14c0ae84 (diff)
downloaditools-46280806236fedabb9a43e0517817c17c9b0d6bd.tar.gz
itools-46280806236fedabb9a43e0517817c17c9b0d6bd.tar.bz2
itools-46280806236fedabb9a43e0517817c17c9b0d6bd.zip
escape ID to avoid postgresql lowercasing it
-rw-r--r--it_dbi.class2
-rwxr-xr-xtest/it_dbi.t10
2 files changed, 6 insertions, 6 deletions
diff --git a/it_dbi.class b/it_dbi.class
index d84c194..316f3ca 100644
--- a/it_dbi.class
+++ b/it_dbi.class
@@ -890,7 +890,7 @@ function delete($query = null)
*/
function delete_untouched($query = null)
{
- if ($this->select(['SELECT' => $this->_p['keyfield']] + (array)$query))
+ if ($this->select(['SELECT' => $this->escape_name($this->_p['keyfield'])] + (array)$query))
while ($this->iterate())
if (($id = $this->_key) && !$this->_touchedids[$id] && $this->delete())
$result[] = $id;
diff --git a/test/it_dbi.t b/test/it_dbi.t
index 4341991..8039857 100755
--- a/test/it_dbi.t
+++ b/test/it_dbi.t
@@ -362,13 +362,13 @@ $r->update(['key4' => "val4'", 'key5' => "val5'"]); is($r->_writes, 1); is($r-
$r->update(['key4' => "val4'", 'key5' => "val5'"]); is($r->_writes, 1); is($r->key4, "val4'"); is($r->key5, "val5'");
# Check LIMIT
-$count = $r->select(['ID >' => 0, 'ORDER BY ID DESC', 'LIMIT' => 1]);
+$count = $r->select(['ID >' => 0, "ORDER BY $primarykey DESC", 'LIMIT' => 1]);
is($count, 1, "Simple LIMIT: count");
is($r->ID, 6, "Simple LIMIT: id");
-$count = $r->select(['ID >' => 0, 'ORDER BY ID DESC', 'LIMIT' => "1, 2"]);
+$count = $r->select(['ID >' => 0, "ORDER BY $primarykey DESC", 'LIMIT' => "1, 2"]);
is($count, 2, "LIMIT with offset: count");
is($r->ID, 5, "LIMIT with offset: id");
-is($r->select(['ID >' => 0, 'ORDER BY ID DESC', 'LIMIT' => false]), 5, "no limit");
+is($r->select(['ID >' => 0, "ORDER BY $primarykey DESC", 'LIMIT' => false]), 5, "no limit");
# Check if iterator clears dynfields left over from previous record
$r->delete(["WHERE 1"]);
@@ -376,7 +376,7 @@ $r->replace(['ID' => 1, 'key1' => "a"]);
$r->replace(['ID' => 2, 'key2' => "b"]);
$r->replace(['ID' => 3]);
$r->clear(false);
-$r->select("WHERE 1 ORDER BY ID");
+$r->select("WHERE 1 ORDER BY $primarykey");
$r->iterate();
is($r->key1, "a"); is($r->key2, null);
$r->iterate();
@@ -406,7 +406,7 @@ is($r->_where(['LOWER(a)' => 'x']), "WHERE LOWER(a) = 'x'", "don't do JSON_EXTRA
#
function allrecs()
{
- foreach (new it_dbi_test([0 => "ORDER BY ID"]) as $r)
+ foreach (new it_dbi_test([0 => "ORDER BY $GLOBALS[primarykey]"]) as $r)
$result[] = ['ID' => $r->ID, 'foo' => $r->foo];
return json_encode($result);
}