Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Check for results array null keys

givanz4e83343156df
diff --git a/system/sqlp/mysqli.php b/system/sqlp/mysqli.php
index b9a2652..93f67fb 100755
--- a/system/sqlp/mysqli.php
+++ b/system/sqlp/mysqli.php
@@ -85,10 +85,17 @@ class %name%SQL {
}
if ('%query_id%' == '_') {
- $results[$row['array_key']] = $values;
+ if ($row['array_key'] === null) {
+ $results[] = $values;
+ } else {
+ $results[$row['array_key']] = $values;
+ }
} else {
- $results['%query_id%'][$row['array_key']] = $values;
-
+ if ($row['array_key'] === null) {
+ $results['%query_id%'][] = $values;
+ } else {
+ $results['%query_id%'][$row['array_key']] = $values;
+ }
}
}
} else {
diff --git a/system/sqlp/pgsql.php b/system/sqlp/pgsql.php
index 1c4f84a..d0edf72 100755
--- a/system/sqlp/pgsql.php
+++ b/system/sqlp/pgsql.php
@@ -85,10 +85,17 @@ class %name%SQL {
}
if ('%query_id%' == '_') {
- $results[$row['array_key']] = $values;
+ if ($row['array_key'] === null) {
+ $results[] = $values;
+ } else {
+ $results[$row['array_key']] = $values;
+ }
} else {
- $results['%query_id%'][$row['array_key']] = $values;
-
+ if ($row['array_key'] === null) {
+ $results['%query_id%'][] = $values;
+ } else {
+ $results['%query_id%'][$row['array_key']] = $values;
+ }
}
}
} else {
@@ -160,4 +167,4 @@ class %name%SQL {
%fetch_all_start%
$this->db->fetchAll($result)
-%fetch_all_end%
\ No newline at end of file
+%fetch_all_end%
diff --git a/system/sqlp/sqlite.php b/system/sqlp/sqlite.php
index 8aec866..15b4188 100755
--- a/system/sqlp/sqlite.php
+++ b/system/sqlp/sqlite.php
@@ -86,10 +86,17 @@ class %name%SQL {
}
if ('%query_id%' == '_') {
- $results[$row['array_key']] = $values;
+ if ($row['array_key'] === null) {
+ $results[] = $values;
+ } else {
+ $results[$row['array_key']] = $values;
+ }
} else {
- $results['%query_id%'][$row['array_key']] = $values;
-
+ if ($row['array_key'] === null) {
+ $results['%query_id%'][] = $values;
+ } else {
+ $results['%query_id%'][$row['array_key']] = $values;
+ }
}
}
} else {
@@ -140,7 +147,7 @@ class %name%SQL {
//$result->fetchArray(SQLITE3_NUM)[0] ?? null
%fetch_one_start%
- $this->db->fetchOne($result)
+ $this->db->fetchOne($result)
%fetch_one_end%
%fetch_result_start%
@@ -149,4 +156,4 @@ class %name%SQL {
%fetch_all_start%
$this->db->fetchAll($result)
-%fetch_all_end%
\ No newline at end of file
+%fetch_all_end%
diff --git a/system/sqlp/sqlp.php b/system/sqlp/sqlp.php
old mode 100755
new mode 100644
index f401daf..e74e56f
--- a/system/sqlp/sqlp.php
+++ b/system/sqlp/sqlp.php
@@ -155,15 +155,15 @@ class Sqlp {
//avoid subselects with negative lookbehind for (
$selectRegex = '/(@[^\s]+\s*)?(?<!\()\s*SELECT.*?FROM\s*([`"]?\w+[`"]? AS \w+|[`"]?\w+[`"]?)/ims';
- $updateRegex = '/(@[^\s]+\s*)?UPDATE\s*([`"]?\w+[`"]? AS \w+|[`"]?\w+[`"]?)/ims';
$insertRegex = '/(@[^\s]+\s*)?INSERT\s*INTO\s*([`"]?\w+[`"]? AS \w+|[`"]?\w+[`"]?)/ims';
+ $updateRegex = '/(@[^\s]+\s*)?UPDATE\s*([`"]?\w+[`"]? AS \w+|[`"]?\w+[`"]?)/ims';
$deleteRegex = '/(@[^\s]+\s*)?DELETE.*FROM\s*([`"]?\w+[`"]? AS \w+|[`"]?\w+[`"]?)/ims';
$functionRegex = '/(@[^\s]+\s*)?(?<!\()SELECT.*?\w+\(\)\s*AS\s*[`"]?(\w+)[`"]?/ims';
$countRegex = '/(@[^\s]+\s*)?SELECT\s*count\(.*?\s*AS\s*[`"]?(\w+)[`"]?$/ims';
if (preg_match($selectRegex, $query, $matches1) ||
- preg_match($updateRegex, $query, $matches1) ||
preg_match($insertRegex, $query, $matches1) ||
+ preg_match($updateRegex, $query, $matches1) ||
preg_match($deleteRegex, $query, $matches1) ||
preg_match($functionRegex, $query, $matches1) ||
preg_match($countRegex, $query, $matches1)) {
@@ -228,11 +228,11 @@ class Sqlp {
//return '$result->fetch_array(MYSQLI_NUM)[0] ?? null';
case (isset($type[0]) && $type[0] == '@'):
- $key = str_replace('@result.', '', $type);
+ $key = str_replace('@result.', '', $type);
- return $this->template($this->model['fetch_result'], ['key' => $key]);
- //return sprintf($this->model['fetch_result'], $key, $key);
- //return "isset(\$results['$key']) ? \$results['$key'] : 'NULL'";
+ return $this->template($this->model['fetch_result'], ['key' => $key]);
+ //return sprintf($this->model['fetch_result'], $key, $key);
+ //return "isset(\$results['$key']) ? \$results['$key'] : 'NULL'";
case 'fetch_all':
default:
@@ -266,26 +266,26 @@ class Sqlp {
//replace macro template variables %$variable
$macro = preg_replace_callback(
- '@\$%(\w+)@',
- function ($varMatch) use ($match) {
- return
- preg_replace_callback(
- $this->config['varRegex'],
- function ($matches) {
- return '$' . \Vvveb\dotToArrayKey('params.' . $matches[1]);
- //return '$params[\'' . $matches[1] . '\']';
- },
- $match[$varMatch[1]]);
- },
- $macro);
+ '@\$%(\w+)@',
+ function ($varMatch) use ($match) {
+ return
+ preg_replace_callback(
+ $this->config['varRegex'],
+ function ($matches) {
+ return '$' . \Vvveb\dotToArrayKey('params.' . $matches[1]);
+ //return '$params[\'' . $matches[1] . '\']';
+ },
+ $match[$varMatch[1]]);
+ },
+ $macro);
//replace macro template placeholders %placeholder
$macro = preg_replace_callback(
- '@\%(\w+)@',
+ '@\%(\w+)@',
function ($varMatch) use ($match) {
return $match[$varMatch[1]];
},
- $macro);
+ $macro);
$statement = str_replace($match[0], $macro, $statement);
}
@@ -342,9 +342,9 @@ class Sqlp {
$key = $matches[1];
return "' . (isset(\$params['$key']) ? \$params['$key'] : 'NULL') . '";
- //return "' . \$results['". $matches[1] . "'] . '";
+ //return "' . \$results['". $matches[1] . "'] . '";
},
- $statement);
+ $statement);
$lex = new Lexer($this->config['tokenMap'], $this->config['macroMap']);
$structure = $lex->lex($statement);
@@ -362,7 +362,7 @@ class Sqlp {
return "' . (isset($key) ? $key : 'NULL') . '";
},
- $statement);
+ $statement);
//FILTER
if (preg_match_all($this->config['filterRegex'], $statement, $matches, PREG_SET_ORDER)) {
@@ -551,12 +551,12 @@ class Sqlp {
//$query = $this->parseSQLCount($query);
$statement .= $this->template($template,
- [
- 'statement' => $this->parseMacros($query, $method['params']),
- 'query_id' => $queryId,
- 'array_key' => $arrayKey,
- 'array_value' => $arrayValue,
- ]);
+ [
+ 'statement' => $this->parseMacros($query, $method['params']),
+ 'query_id' => $queryId,
+ 'array_key' => $arrayKey,
+ 'array_value' => $arrayValue,
+ ]);
$statement = $this->parseEach($statement, $method['params']);
@@ -644,19 +644,19 @@ class Sqlp {
$method['fetch'] = $this->fetchType($fetch);
$method['params'] = trim(implode(', ', array_map(
- function ($param) {
- if ($param['in_out'] == 'IN') {
- return '$' . $param['name'];
- }
- } ,$method['params'])), ', ');
+ function ($param) {
+ if ($param['in_out'] == 'IN') {
+ return '$' . $param['name'];
+ }
+ } ,$method['params'])), ', ');
//if ($queriesCount > 1)
//{
$methods .= $this->template($this->model['methodMultipleTemplate'], $method);
//} else
- //{
+ //{
//$methods .= $this->template($this->config['METHOD_TEMPLATE'], $method);
- //}
+ //}
}
}