Skip to content

Commit 94279fb

Browse files
committed
Parse the type "array" in prepared queries
New parse method constant added PARAM_ARRAY, used to parse array values in prepared queries.
1 parent 784c625 commit 94279fb

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/JSONDB/JSONDB.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ class JSONDB
7272
*/
7373
const PARAM_NULL = 3;
7474

75+
/**
76+
* Parse value to array for
77+
* prepared queries.
78+
* @const integer
79+
*/
80+
const PARAM_ARRAY = 7;
81+
7582
/**
7683
* Define if we fetch results as arrays
7784
* @const int

src/JSONDB/PreparedQueryStatement.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ public function bindValue($key, $value, $parse_method = JSONDB::PARAM_STRING)
106106
case JSONDB::PARAM_NULL:
107107
$value = (string)$value . ':JSONDB::TO_NULL:';
108108
break;
109+
110+
case JSONDB::PARAM_ARRAY:
111+
$value = JSONDB::quote((string)serialize($value)) . ':JSONDB::TO_ARRAY:';
112+
break;
109113
}
110114
$this->queryString = str_replace($key, $value, $this->queryString);
111115
} else {

src/JSONDB/QueryParser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ protected function _parseValue($value)
451451
return TRUE;
452452
} elseif (strpos($value, ':JSONDB::TO_NULL:') !== FALSE || strtolower($value) === 'null') {
453453
return NULL;
454+
} elseif (strpos($value, ':JSONDB::TO_ARRAY:') !== FALSE) {
455+
return (array)unserialize($this->_parseValue(str_replace(':JSONDB::TO_ARRAY:', '', $value)));
454456
} elseif ($trim_value[0] === "'" && $trim_value[strlen($trim_value) - 1] === "'") {
455457
return (string)str_replace(array('{{quot}}', '{{comm}}', '{{dot}}', '{{pto}}', '{{ptc}}', '{{semi}}'), array('\'', ',', '.', '(', ')', ';'), (string)trim($value, self::TRIM_CHAR));
456458
} else {

0 commit comments

Comments
 (0)