Skip to content

armgit / Vvveb

Public Imported from GitHub
0

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

Order by escape macro

givanzc0f2a6af1c41
diff --git a/admin/sql/mysqli/order.sql b/admin/sql/mysqli/order.sql
index dbd0aa8..062f798 100644
--- a/admin/sql/mysqli/order.sql
+++ b/admin/sql/mysqli/order.sql
@@ -100,7 +100,8 @@
-- ORDER BY parameters can't be binded, because they are added to the query directly they must be properly sanitized by only allowing a predefined set of values
@IF isset(:order_by)
THEN
- ORDER BY $order_by $direction
+ -- ORDER BY $order_by $direction
+ ORDER BY order.@ESC(:order_by) @ESC(:direction)
@ELSE
ORDER BY order_id DESC
END @IF
diff --git a/admin/sql/mysqli/product_variant.sql b/admin/sql/mysqli/product_variant.sql
index 76b6979..24f6cb2 100644
--- a/admin/sql/mysqli/product_variant.sql
+++ b/admin/sql/mysqli/product_variant.sql
@@ -40,7 +40,8 @@
-- ORDER BY parameters can't be binded, because they are added to the query directly they must be properly sanitized by only allowing a predefined set of values
@IF isset(:order_by)
THEN
- ORDER BY product_variant.$order_by $direction
+ -- ORDER BY $order_by $direction
+ ORDER BY product_variant.@ESC(:order_by) @ESC(:direction)
@ELSE
ORDER BY product_variant.product_variant_id ASC
END @IF
diff --git a/admin/sql/mysqli/user.sql b/admin/sql/mysqli/user.sql
index 03d1e6d..681d62b 100644
--- a/admin/sql/mysqli/user.sql
+++ b/admin/sql/mysqli/user.sql
@@ -51,7 +51,8 @@
-- ORDER BY parameters can't be binded, because they are added to the query directly they must be properly sanitized by only allowing a predefined set of values
@IF isset(:order_by)
THEN
- ORDER BY user.$order_by $direction
+ -- ORDER BY $order_by $direction
+ ORDER BY user.@ESC(:order_by) @ESC(:direction)
@ELSE
ORDER BY user.user_id DESC
END @IF
diff --git a/admin/sql/pgsql/order.sql b/admin/sql/pgsql/order.sql
old mode 100755
new mode 100644
index 728a2d2..8573618
--- a/admin/sql/pgsql/order.sql
+++ b/admin/sql/pgsql/order.sql
@@ -100,9 +100,10 @@
-- ORDER BY parameters can't be binded, because they are added to the query directly they must be properly sanitized by only allowing a predefined set of values
@IF isset(:order_by)
THEN
- ORDER BY $order_by $direction
+ -- ORDER BY $order_by $direction
+ ORDER BY "order".@ESC(:order_by) @ESC(:direction)
@ELSE
- ORDER BY order_id DESC
+ ORDER BY "order".order_id DESC
END @IF
@SQL_LIMIT(:start, :limit);
diff --git a/admin/sql/pgsql/product_variant.sql b/admin/sql/pgsql/product_variant.sql
index d3b8db5..72cba48 100644
--- a/admin/sql/pgsql/product_variant.sql
+++ b/admin/sql/pgsql/product_variant.sql
@@ -40,7 +40,8 @@
-- ORDER BY parameters can't be binded, because they are added to the query directly they must be properly sanitized by only allowing a predefined set of values
@IF isset(:order_by)
THEN
- ORDER BY product_variant.$order_by $direction
+ -- ORDER BY $order_by $direction
+ ORDER BY product_variant.@ESC(:order_by) @ESC(:direction)
@ELSE
ORDER BY product_variant.product_variant_id ASC
END @IF
@@ -82,7 +83,8 @@
INSERT INTO product_variant
( @KEYS(:product_variant) )
- VALUES (:product_variant );
+ VALUES (:product_variant )
+ ON CONFLICT ("product_variant_id") DO UPDATE SET @LIST(:product_variant);
END
diff --git a/admin/sql/pgsql/user.sql b/admin/sql/pgsql/user.sql
old mode 100755
new mode 100644
index 857407a..7bfbf2c
--- a/admin/sql/pgsql/user.sql
+++ b/admin/sql/pgsql/user.sql
@@ -51,7 +51,8 @@
-- ORDER BY parameters can't be binded, because they are added to the query directly they must be properly sanitized by only allowing a predefined set of values
@IF isset(:order_by)
THEN
- ORDER BY "user".$order_by $direction
+ -- ORDER BY $order_by $direction
+ ORDER BY "user".@ESC(:order_by) @ESC(:direction)
@ELSE
ORDER BY "user".user_id DESC
END @IF
diff --git a/admin/sql/sqlite/order.sql b/admin/sql/sqlite/order.sql
old mode 100755
new mode 100644
index 2260c12..fc55031
--- a/admin/sql/sqlite/order.sql
+++ b/admin/sql/sqlite/order.sql
@@ -100,9 +100,10 @@
-- ORDER BY parameters can't be binded, because they are added to the query directly they must be properly sanitized by only allowing a predefined set of values
@IF isset(:order_by)
THEN
- ORDER BY $order_by $direction
+ -- ORDER BY $order_by $direction
+ ORDER BY `order`.@ESC(:order_by) @ESC(:direction)
@ELSE
- ORDER BY order_id DESC
+ ORDER BY `order`.order_id DESC
END @IF
@SQL_LIMIT(:start, :limit);
diff --git a/admin/sql/sqlite/product_variant.sql b/admin/sql/sqlite/product_variant.sql
index 3762e27..ded12b2 100644
--- a/admin/sql/sqlite/product_variant.sql
+++ b/admin/sql/sqlite/product_variant.sql
@@ -40,7 +40,8 @@
-- ORDER BY parameters can't be binded, because they are added to the query directly they must be properly sanitized by only allowing a predefined set of values
@IF isset(:order_by)
THEN
- ORDER BY product_variant.$order_by $direction
+ -- ORDER BY $order_by $direction
+ ORDER BY product_variant.@ESC(:order_by) @ESC(:direction)
@ELSE
ORDER BY product_variant.product_variant_id ASC
END @IF
diff --git a/admin/sql/sqlite/user.sql b/admin/sql/sqlite/user.sql
old mode 100755
new mode 100644
index f088638..0d905cf
--- a/admin/sql/sqlite/user.sql
+++ b/admin/sql/sqlite/user.sql
@@ -51,7 +51,8 @@
-- ORDER BY parameters can't be binded, because they are added to the query directly they must be properly sanitized by only allowing a predefined set of values
@IF isset(:order_by)
THEN
- ORDER BY user.$order_by $direction
+ -- ORDER BY $order_by $direction
+ ORDER BY user.@ESC(:order_by) @ESC(:direction)
@ELSE
ORDER BY user.user_id DESC
END @IF
diff --git a/system/sqlp/config.php b/system/sqlp/config.php
index d3cf34e..c0dde25 100755
--- a/system/sqlp/config.php
+++ b/system/sqlp/config.php
@@ -55,6 +55,7 @@ return
//'END @EACH' => 'T_EACH_END',
'@SQL_COUNT\(.+?\)' => 'T_SQL_COUNT',
'@SQL_LIMIT\(.+?\)' => 'T_SQL_LIMIT',
+ '@ESC\(.+?\)' => 'T_ESC',
'.+?' => 'T_SQL',
],
@@ -124,6 +125,15 @@ PHP
PHP
],
+ 'T_ESC' => [
+ '/@ESC\s*\(\s*:?(?<column>.+?)\s*\)/ms',
+ <<<'PHP'
+ ';
+ $sql .= preg_replace('/\W+/', '', $params['%column'] ?? '');
+ $sql .= '
+PHP
+ ],
+
//'T_EACH_START' => 'EACH()',
//'T_EACH_END' => '}',
'@SQL_COUNT\(.+?\)' => 'T_SQL_COUNT',
diff --git a/system/sqlp/sqlp.php b/system/sqlp/sqlp.php
index e74e56f..e566875 100644
--- a/system/sqlp/sqlp.php
+++ b/system/sqlp/sqlp.php
@@ -574,7 +574,9 @@ class Sqlp {
}
//clean empty sql strings
- $statement = preg_replace('@\s*\$sql .= \'\s*\';@ms', '', $statement);
+ $statement = preg_replace('@\$sql .= \'\s+\n\s*\';@ms', '$sql .= \' \';', $statement);
+ $statement = preg_replace('@\s*\$sql .= \'\';@ms', '', $statement);
+ //$statement = preg_replace('@\s*\$sql .= \'\s*\';@ms', '', $statement);
if (isset($fetch[$qIndex])) {
$method['fetch'] = $this->fetchType($fetch[$qIndex]);