diff options
-rw-r--r-- | it_dbi.class | 3 | ||||
-rwxr-xr-x | test/it_dbi.t | 4 |
2 files changed, 6 insertions, 1 deletions
diff --git a/it_dbi.class b/it_dbi.class index be802b7..156c487 100644 --- a/it_dbi.class +++ b/it_dbi.class @@ -326,6 +326,7 @@ function _from($params, $omit_from = false) */ function _where($params) { + $dyncols_enabled = !strlen($params['JOIN'] . $params['FROM']); unset($params['JOIN'], $params['FROM']); if (is_array($params) && (count($params) > 0)) @@ -372,7 +373,7 @@ function _where($params) $qval = $this->escape_string((string)$value); } - if ($this->_fields['dyncols'] && !$this->_fields[$field]) + if ($dyncols_enabled && $this->_fields['dyncols'] && !$this->_fields[$field]) $field = "JSON_EXTRACT(dyncols, " . $this->escape_string('$.' . $field) . ")"; switch ($op) diff --git a/test/it_dbi.t b/test/it_dbi.t index 89df3b8..4e22152 100755 --- a/test/it_dbi.t +++ b/test/it_dbi.t @@ -360,6 +360,10 @@ is($r->key1, "a"); is($r->key2, null); $r->iterate(); is($r->key1, null); is($r->key2, "b"); +# don't do dyncols stuff in where when we select form multiple tables (column names are unknown then) +is($r->_where(['FROM' => 'it_dbi_test AS a, it_dbi_test AS b', '-a.ID' => 'b.ID']), 'WHERE a.ID = b.ID', "don't do JSON_EXTRACT when we have multiple tables in FROM"); +is($r->_where(['JOIN' => 'it_dbi_test AS b', '-a.ID' => 'b.ID']), 'WHERE a.ID = b.ID', "don't do JSON_EXTRACT when we JOIN"); + # # Test tracked update # |