Skip to content

armgit / Vvveb

Public Imported from GitHub
0

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

Removed unnecessary 'table AS table' from queries

givanz28e6e747f27e
diff --git a/admin/sql/mysqli/admin.sql b/admin/sql/mysqli/admin.sql
index 26ceee9..df545d6 100755
--- a/admin/sql/mysqli/admin.sql
+++ b/admin/sql/mysqli/admin.sql
@@ -17,7 +17,7 @@
)
BEGIN
- SELECT * FROM admin AS admin WHERE 1 = 1
+ SELECT * FROM admin WHERE 1 = 1
@IF isset(:status) AND !empty(:status)
@@ -76,36 +76,36 @@
WHERE 1 = 1
- @IF isset(:username)
- THEN
- AND _.username = :username
- END @IF
+ @IF isset(:username)
+ THEN
+ AND _.username = :username
+ END @IF
- @IF isset(:email)
- THEN
- AND _.email = :email
- END @IF
+ @IF isset(:email)
+ THEN
+ AND _.email = :email
+ END @IF
- @IF isset(:admin_id)
+ @IF isset(:admin_id)
THEN
AND _.admin_id = :admin_id
- END @IF
+ END @IF
- @IF isset(:status)
+ @IF isset(:status)
THEN
AND _.status = :status
- END @IF
-
+ END @IF
+
@IF isset(:token)
THEN
AND _.token = :token
- END @IF
-
- @IF isset(:role_id)
+ END @IF
+
+ @IF isset(:role_id)
THEN
AND _.role_id = :role_id
- END @IF
-
+ END @IF
+
LIMIT 1;
END
diff --git a/admin/sql/mysqli/attribute.sql b/admin/sql/mysqli/attribute.sql
index 142e8cd..df4c387 100755
--- a/admin/sql/mysqli/attribute.sql
+++ b/admin/sql/mysqli/attribute.sql
@@ -20,7 +20,7 @@
,pa.value
END @IF
- FROM attribute AS attribute
+ FROM attribute
INNER JOIN attribute_content
ON attribute_content.attribute_id = attribute.attribute_id AND attribute_content.language_id = :language_id
INNER JOIN attribute_group_content
diff --git a/admin/sql/mysqli/attribute_group.sql b/admin/sql/mysqli/attribute_group.sql
index f42cb70..8924fa5 100755
--- a/admin/sql/mysqli/attribute_group.sql
+++ b/admin/sql/mysqli/attribute_group.sql
@@ -18,7 +18,7 @@
,pa.value
END @IF
- FROM attribute_group AS attribute_group
+ FROM attribute_group
INNER JOIN attribute_group_content
ON attribute_group_content.attribute_group_id = attribute_group.attribute_group_id AND attribute_group_content.language_id = :language_id
diff --git a/admin/sql/mysqli/comment.sql b/admin/sql/mysqli/comment.sql
index 2fbce6c..6cc5501 100755
--- a/admin/sql/mysqli/comment.sql
+++ b/admin/sql/mysqli/comment.sql
@@ -29,7 +29,7 @@
,post_content.name, post_content.slug
END @IF
- FROM comment AS comment
+ FROM comment
LEFT JOIN user ON (user.user_id = comment.user_id)
@IF isset(:post_title) AND :post_title
diff --git a/admin/sql/mysqli/country.sql b/admin/sql/mysqli/country.sql
index b490d3f..b1c7d5a 100755
--- a/admin/sql/mysqli/country.sql
+++ b/admin/sql/mysqli/country.sql
@@ -13,7 +13,7 @@
BEGIN
-- country
SELECT *
- FROM country AS country WHERE 1 = 1
+ FROM country WHERE 1 = 1
@IF isset(:status) AND :status != ""
THEN
diff --git a/admin/sql/mysqli/coupon.sql b/admin/sql/mysqli/coupon.sql
index 9bc27ee..38201b7 100755
--- a/admin/sql/mysqli/coupon.sql
+++ b/admin/sql/mysqli/coupon.sql
@@ -12,7 +12,7 @@
BEGIN
-- coupon
SELECT *
- FROM coupon AS coupon WHERE 1 = 1
+ FROM coupon WHERE 1 = 1
@SQL_LIMIT(:start, :limit);
diff --git a/admin/sql/mysqli/currency.sql b/admin/sql/mysqli/currency.sql
index 21a210b..71b0dc7 100755
--- a/admin/sql/mysqli/currency.sql
+++ b/admin/sql/mysqli/currency.sql
@@ -11,7 +11,7 @@
BEGIN
-- currency
SELECT *, code as array_key
- FROM currency as currency WHERE 1 = 1
+ FROM currency WHERE 1 = 1
@IF isset(:status) AND :status != ""
THEN
diff --git a/admin/sql/mysqli/digital_asset.sql b/admin/sql/mysqli/digital_asset.sql
index 174409c..3282fe1 100755
--- a/admin/sql/mysqli/digital_asset.sql
+++ b/admin/sql/mysqli/digital_asset.sql
@@ -21,7 +21,7 @@
, o.customer_order_id, o.order_id, op.name as product_name
END @IF
- FROM digital_asset AS digital_asset
+ FROM digital_asset
INNER JOIN digital_asset_content ON digital_asset_content.digital_asset_id = digital_asset.digital_asset_id
AND digital_asset_content.language_id = :language_id
diff --git a/admin/sql/mysqli/digital_asset_log.sql b/admin/sql/mysqli/digital_asset_log.sql
index 91d7eb3..0c6e8bf 100644
--- a/admin/sql/mysqli/digital_asset_log.sql
+++ b/admin/sql/mysqli/digital_asset_log.sql
@@ -13,7 +13,7 @@
SELECT digital_asset_log.*
- FROM digital_asset_log AS digital_asset_log
+ FROM digital_asset_log
WHERE 1 = 1
diff --git a/admin/sql/mysqli/field.sql b/admin/sql/mysqli/field.sql
index cf8b819..c90e913 100755
--- a/admin/sql/mysqli/field.sql
+++ b/admin/sql/mysqli/field.sql
@@ -18,7 +18,7 @@
BEGIN
-- field_item
SELECT *, field_id as array_key
- FROM field as field
+ FROM field
-- LEFT JOIN field_to_site t2s ON (field_item.field_item_id = t2s.field_item_id)
WHERE 1 = 1
diff --git a/admin/sql/mysqli/field_group.sql b/admin/sql/mysqli/field_group.sql
index 8a18f95..0ba2eed 100755
--- a/admin/sql/mysqli/field_group.sql
+++ b/admin/sql/mysqli/field_group.sql
@@ -12,7 +12,7 @@
BEGIN
-- field_group
SELECT *
- FROM field_group AS field_group
+ FROM field_group
INNER JOIN field_group_content ON field_group_content.field_group_id = field_group.field_group_id
WHERE 1 = 1
diff --git a/admin/sql/mysqli/language.sql b/admin/sql/mysqli/language.sql
index d76e436..64859d8 100755
--- a/admin/sql/mysqli/language.sql
+++ b/admin/sql/mysqli/language.sql
@@ -13,7 +13,7 @@
BEGIN
-- language
SELECT *, code as array_key
- FROM language as language WHERE 1 = 1
+ FROM language WHERE 1 = 1
@IF isset(:status)
THEN
diff --git a/admin/sql/mysqli/length_type.sql b/admin/sql/mysqli/length_type.sql
index 31146de..82bf858 100755
--- a/admin/sql/mysqli/length_type.sql
+++ b/admin/sql/mysqli/length_type.sql
@@ -12,7 +12,7 @@
BEGIN
-- length_type
SELECT *, length_type.length_type_id as array_key
- FROM length_type AS length_type
+ FROM length_type
INNER JOIN length_type_content ON length_type_content.length_type_id = length_type.length_type_id
WHERE 1 = 1
diff --git a/admin/sql/mysqli/manufacturer.sql b/admin/sql/mysqli/manufacturer.sql
index e512196..d0d96a9 100755
--- a/admin/sql/mysqli/manufacturer.sql
+++ b/admin/sql/mysqli/manufacturer.sql
@@ -109,7 +109,7 @@
)
BEGIN
- SELECT * FROM manufacturer AS manufacturer
+ SELECT * FROM manufacturer
LEFT JOIN manufacturer_to_site p2s ON (manufacturer.manufacturer_id = p2s.manufacturer_id)
WHERE p2s.site_id = :site_id
diff --git a/admin/sql/mysqli/media_content.sql b/admin/sql/mysqli/media_content.sql
index ff883d6..58b430b 100644
--- a/admin/sql/mysqli/media_content.sql
+++ b/admin/sql/mysqli/media_content.sql
@@ -12,24 +12,24 @@
)
BEGIN
-- media_content
- SELECT media.*,media_content.*
+ SELECT media_content.*,media_content.*
@IF !empty(:content)
THEN
,content
END @IF
- FROM media_content AS media
+ FROM media_content
WHERE 1 = 1
@IF !empty(:media_id)
THEN
- AND media.media_id = :media_id
+ AND media_content.media_id = :media_id
END @IF
@IF !empty(:language_id)
THEN
- AND media.language_id = :language_id
+ AND media_content.language_id = :language_id
END @IF
@IF !empty(:limit)
@@ -40,7 +40,7 @@
SELECT count(*) FROM (
- @SQL_COUNT(media.media_id, media_content) -- this takes previous query removes limit and replaces select columns with parameter product_id
+ @SQL_COUNT(media_content.media_id, media_content) -- this takes previous query removes limit and replaces select columns with parameter product_id
) as count;
diff --git a/admin/sql/mysqli/menu.sql b/admin/sql/mysqli/menu.sql
index ee44c36..935ca87 100644
--- a/admin/sql/mysqli/menu.sql
+++ b/admin/sql/mysqli/menu.sql
@@ -90,7 +90,7 @@
-- get all menus
- CREATE PROCEDURE getMenusList(
+ CREATE PROCEDURE getAll(
-- variables
IN language_id INT,
@@ -113,7 +113,7 @@
SELECT *, menu.menu_id as array_key
- FROM menu AS menu
+ FROM menu
@SQL_LIMIT(:start, :limit);
@@ -125,12 +125,12 @@
) as count;
- END -- get all menus
+ END
- -- get all menus
+ -- get menu
- CREATE PROCEDURE getMenus(
+ CREATE PROCEDURE get(
-- variables
IN language_id INT,
@@ -150,13 +150,13 @@
)
BEGIN
- SELECT td.*,menus.url, menus.sort_order, menus.parent_id, menus.type, menus.item_id, menus.menu_item_id as array_key
+ SELECT td.*,menu.url, menu.sort_order, menu.parent_id, menu.type, menu.item_id, menu.menu_item_id as array_key
- FROM menu_item AS menus
+ FROM menu_item AS menu
- -- INNER JOIN menu_to_site c2s ON (menus.menu_id = c2s.menu_id AND c2s.site_id = :site_id)
- INNER JOIN menu_item_content td ON (menus.menu_item_id = td.menu_item_id AND td.language_id = :language_id)
+ -- INNER JOIN menu_to_site c2s ON (menu.menu_id = c2s.menu_id AND c2s.site_id = :site_id)
+ INNER JOIN menu_item_content td ON (menu.menu_item_id = td.menu_item_id AND td.language_id = :language_id)
WHERE
@@ -166,18 +166,18 @@
@IF isset(:menu_id)
THEN
- AND menus.menu_id = :menu_id
+ AND menu.menu_id = :menu_id
END @IF
@IF isset(:slug)
THEN
- AND menus.menu_id = (SELECT menu_id FROM menu WHERE slug = :slug LIMIT 1)
+ AND menu.menu_id = (SELECT menu_id FROM menu WHERE slug = :slug LIMIT 1)
END @IF
- ORDER BY menus.parent_id, menus.sort_order, menus.menu_id
+ ORDER BY menu.parent_id, menu.sort_order, menu.menu_id
@IF isset(:limit)
THEN
diff --git a/admin/sql/mysqli/option.sql b/admin/sql/mysqli/option.sql
index 98e579b..1cb8a97 100644
--- a/admin/sql/mysqli/option.sql
+++ b/admin/sql/mysqli/option.sql
@@ -12,7 +12,7 @@
BEGIN
-- option
SELECT `option`.*, option_content.name
- FROM `option` AS `option`
+ FROM `option`
INNER JOIN option_content
ON option_content.option_id = `option`.option_id AND option_content.language_id = :language_id
diff --git a/admin/sql/mysqli/option_value.sql b/admin/sql/mysqli/option_value.sql
index f34eb7e..fa487cb 100644
--- a/admin/sql/mysqli/option_value.sql
+++ b/admin/sql/mysqli/option_value.sql
@@ -13,7 +13,7 @@
BEGIN
-- option_value
SELECT option_value.*, option_value_content.name
- FROM option_value AS option_value
+ FROM option_value
INNER JOIN option_value_content
ON option_value_content.option_value_id = option_value.option_value_id AND option_value_content.language_id = :language_id
diff --git a/admin/sql/mysqli/order.sql b/admin/sql/mysqli/order.sql
index f8cd849..f11e2d0 100755
--- a/admin/sql/mysqli/order.sql
+++ b/admin/sql/mysqli/order.sql
@@ -24,6 +24,8 @@
-- pagination
IN start INT,
IN limit INT,
+ IN order_by CHAR,
+ IN direction CHAR,
-- return
@@ -94,8 +96,14 @@
`order`.first_name LIKE CONCAT('%',:search,'%') OR
`order`.last_name LIKE CONCAT('%',:search,'%')
END @IF
-
- ORDER BY order_id DESC
+
+ -- 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
+ @ELSE
+ ORDER BY order_id DESC
+ END @IF
@SQL_LIMIT(:start, :limit);
diff --git a/admin/sql/mysqli/order_log.sql b/admin/sql/mysqli/order_log.sql
index 6814bd9..2f9f396 100644
--- a/admin/sql/mysqli/order_log.sql
+++ b/admin/sql/mysqli/order_log.sql
@@ -12,7 +12,7 @@
BEGIN
-- order_log
SELECT *
- FROM order_log AS order_log WHERE 1 = 1
+ FROM order_log WHERE 1 = 1
@IF !empty(:order_id)
THEN
diff --git a/admin/sql/mysqli/order_status.sql b/admin/sql/mysqli/order_status.sql
index 1f1d93d..f90c0da 100755
--- a/admin/sql/mysqli/order_status.sql
+++ b/admin/sql/mysqli/order_status.sql
@@ -11,7 +11,7 @@
)
BEGIN
SELECT *
- FROM order_status AS order_status WHERE 1 = 1
+ FROM order_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/mysqli/payment_status.sql b/admin/sql/mysqli/payment_status.sql
index 98449b5..98333a9 100644
--- a/admin/sql/mysqli/payment_status.sql
+++ b/admin/sql/mysqli/payment_status.sql
@@ -12,7 +12,7 @@
BEGIN
SELECT *
- FROM payment_status AS payment_status WHERE 1 = 1
+ FROM payment_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/mysqli/post.sql b/admin/sql/mysqli/post.sql
index 1d10c05..fb8a68b 100755
--- a/admin/sql/mysqli/post.sql
+++ b/admin/sql/mysqli/post.sql
@@ -27,7 +27,10 @@
IN categories INT,
IN tags INT,
IN taxonomy CHAR,
-
+
+ IN order_by CHAR,
+ IN direction CHAR,
+
-- return array of posts for posts query
OUT fetch_all,
-- return posts count for count query
@@ -35,13 +38,13 @@
)
BEGIN
- SELECT pd.*,posts.*,ad.username,ad.display_name,ad.admin_id,ad.email, ad.avatar, ad.bio, ad.first_name, ad.last_name
+ SELECT pd.*,post.*,ad.username,ad.display_name,ad.admin_id,ad.email, ad.avatar, ad.bio, ad.first_name, ad.last_name
@IF isset(:comment_count)
THEN
,(SELECT COUNT(c.comment_id)
FROM comment c
WHERE
- posts.post_id = c.post_id
+ post.post_id = c.post_id
@IF isset(:comment_status)
THEN
@@ -54,7 +57,14 @@
@IF isset(:search)
THEN
- ,MATCH(pd.name, pd.content) AGAINST(:search) as score
+ ,MATCH(pd.name, pd.content)
+ AGAINST(
+ :search
+ @IF isset(:search_boolean) && !empty(:search_boolean)
+ THEN
+ IN BOOLEAN MODE
+ END @IF
+ ) as score
END @IF
-- categories
@@ -72,7 +82,7 @@
WHERE
- td.language_id = :language_id AND t2s.site_id = :site_id AND pt.post_id = posts.post_id AND t.type = "categories" AND pt.post_id = posts.post_id
+ td.language_id = :language_id AND t2s.site_id = :site_id AND pt.post_id = post.post_id AND t.type = "categories" AND pt.post_id = post.post_id
LIMIT :categories
@@ -95,7 +105,7 @@
WHERE
- td.language_id = :language_id AND t2s.site_id = :site_id AND pt.post_id = posts.post_id AND t.type = "tags" AND pt.post_id = posts.post_id
+ td.language_id = :language_id AND t2s.site_id = :site_id AND pt.post_id = post.post_id AND t.type = "tags" AND pt.post_id = post.post_id
LIMIT :tags
@@ -118,15 +128,15 @@
WHERE
- td.language_id = :language_id AND t2s.site_id = :site_id AND pt.post_id = posts.post_id AND t.type = :taxonomy AND pt.post_id = posts.post_id
+ td.language_id = :language_id AND t2s.site_id = :site_id AND pt.post_id = post.post_id AND t.type = :taxonomy AND pt.post_id = post.post_id
) as taxonomy
END @IF
- FROM post AS posts
+ FROM post
LEFT JOIN post_content pd ON (
- posts.post_id = pd.post_id
+ post.post_id = pd.post_id
@IF isset(:language_id)
THEN
@@ -134,45 +144,52 @@
END @IF
)
- LEFT JOIN post_to_site ps ON (posts.post_id = ps.post_id)
- LEFT JOIN admin ad ON (posts.admin_id = ad.admin_id)
+ LEFT JOIN post_to_site ps ON (post.post_id = ps.post_id)
+ LEFT JOIN admin ad ON (post.admin_id = ad.admin_id)
@IF isset(:taxonomy_item_id) || isset(:taxonomy_item_slug)
THEN
- LEFT JOIN post_to_taxonomy_item pt ON (posts.post_id = pt.post_id)
+ LEFT JOIN post_to_taxonomy_item pt ON (post.post_id = pt.post_id)
END @IF
WHERE 1 = 1
@IF isset(:type) && !empty(:type)
THEN
- AND posts.type = :type
+ AND post.type = :type
END @IF
@IF isset(:status) && !empty(:status)
THEN
- AND posts.status = :status
+ AND post.status = :status
@ELSE
- AND posts.status = 'publish'
+ AND post.status = 'publish'
END @IF
-- username/author
@IF isset(:username)
THEN
- AND posts.admin_id = (SELECT admin_id FROM admin WHERE username = :username LIMIT 1)
+ AND post.admin_id = (SELECT admin_id FROM admin WHERE username = :username LIMIT 1)
END @IF
-- admin_id
@IF isset(:admin_id)
THEN
- AND posts.admin_id = :admin_id
+ AND post.admin_id = :admin_id
END @IF
-- search
@IF isset(:search) && !empty(:search)
THEN
-- AND pd.name LIKE CONCAT('%',:search,'%')
- AND MATCH(pd.name, pd.content) AGAINST(:search)
+ AND MATCH(pd.name, pd.content)
+ AGAINST(
+ :search
+ @IF isset(:search_boolean) && !empty(:search_boolean)
+ THEN
+ IN BOOLEAN MODE
+ END @IF
+ )
END @IF
-- like
@@ -185,7 +202,7 @@
@IF isset(:post_id) && count(:post_id) > 0
THEN
- AND posts.post_id IN (:post_id)
+ AND post.post_id IN (:post_id)
END @IF
@@ -215,21 +232,21 @@
-- month
@IF isset(:month) && !empty(:month)
THEN
- AND MONTH(posts.created_at) = :month
+ AND MONTH(post.created_at) = :month
END @IF
-- year
@IF isset(:year) && !empty(:year)
THEN
- AND YEAR(posts.created_at) = :year
+ AND YEAR(post.created_at) = :year
END @IF
- -- order by
+ -- 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 posts.$order_by $direction
+ ORDER BY post.$order_by $direction
@ELSE
- ORDER BY posts.post_id DESC
+ ORDER BY post.post_id DESC
END @IF
-- limit
@@ -242,7 +259,7 @@
-- SELECT FOUND_ROWS() as count;
SELECT count(*) FROM (
- @SQL_COUNT(posts.post_id, post) -- this takes previous query removes limit and replaces select columns with parameter product_id
+ @SQL_COUNT(post.post_id, post) -- this takes previous query removes limit and replaces select columns with parameter product_id
) as count;
@@ -324,7 +341,7 @@
-- content
SELECT *, language_id as array_key -- (underscore) _ column means that this column (language_id) value will be used as array key when adding row to result array
- FROM post_content AS post_content
+ FROM post_content
WHERE post_id = @result.post_id;
diff --git a/admin/sql/mysqli/post_content_revision.sql b/admin/sql/mysqli/post_content_revision.sql
index 77df20b..7e66382 100644
--- a/admin/sql/mysqli/post_content_revision.sql
+++ b/admin/sql/mysqli/post_content_revision.sql
@@ -14,34 +14,34 @@
)
BEGIN
-- post_content_revision
- SELECT revision.post_id, revision.language_id, revision.created_at, revision.admin_id, admin.display_name, admin.username
+ SELECT post_content_revision.post_id, post_content_revision.language_id, post_content_revision.created_at, post_content_revision.admin_id, admin.display_name, admin.username
@IF !empty(:content)
THEN
,content
END @IF
- FROM post_content_revision AS revision
- LEFT JOIN admin ON (admin.admin_id = revision.admin_id)
+ FROM post_content_revision
+ LEFT JOIN admin ON (admin.admin_id = post_content_revision.admin_id)
WHERE 1 = 1
@IF !empty(:post_id)
THEN
- AND revision.post_id = :post_id
+ AND post_content_revision.post_id = :post_id
END @IF
@IF !empty(:language_id)
THEN
- AND revision.language_id = :language_id
+ AND post_content_revision.language_id = :language_id
END @IF
@IF !empty(:created_at)
THEN
- AND revision.created_at = :created_at
+ AND post_content_revision.created_at = :created_at
END @IF
- ORDER BY revision.created_at DESC
+ ORDER BY post_content_revision.created_at DESC
@IF !empty(:limit)
THEN
@@ -51,7 +51,7 @@
SELECT count(*) FROM (
- @SQL_COUNT(revision.post_id, post_content_revision) -- this takes previous query removes limit and replaces select columns with parameter product_id
+ @SQL_COUNT(post_content_revision.post_id, post_content_revision) -- this takes previous query removes limit and replaces select columns with parameter product_id
) as count;
diff --git a/admin/sql/mysqli/product.sql b/admin/sql/mysqli/product.sql
index 56e1d99..c7a1fbd 100755
--- a/admin/sql/mysqli/product.sql
+++ b/admin/sql/mysqli/product.sql
@@ -346,13 +346,13 @@
user_group.user_group_id as array_key, -- stock_status_id as key
name as array_value -- name as value
- FROM user_group as user_group
+ FROM user_group
INNER JOIN user_group_content ON user_group_content.user_group_id = user_group.user_group_id;
-- subscription plan
SELECT subscription_plan.subscription_plan_id as array_key,
subscription_plan_content.name as array_value
- FROM subscription_plan AS subscription_plan
+ FROM subscription_plan
INNER JOIN subscription_plan_content ON subscription_plan_content.subscription_plan_id = subscription_plan.subscription_plan_id
AND subscription_plan_content.language_id = :language_id
-- LIMIT 100
@@ -362,7 +362,7 @@
`option`.option_id as array_key, -- option_id as key
option_content.name,
`option`.type
- FROM `option` AS `option`
+ FROM `option`
INNER JOIN option_content
ON option_content.option_id = `option`.option_id AND option_content.language_id = :language_id
-- LIMIT 100
@@ -776,7 +776,7 @@
)
BEGIN
- SELECT pd.*,products.*, products.product_id as array_key
+ SELECT pd.*,product.*, product.product_id as array_key
@IF !empty(:manufacturer)
THEN
@@ -790,7 +790,7 @@
THEN
-- ,(SELECT CONCAT('[', GROUP_CONCAT('{"id":"', pi.product_image_id, '","image":"', pi.image, '"}'), ']')
,(SELECT JSON_ARRAYAGG( JSON_OBJECT('id', pi.product_image_id, 'image', pi.image) )
- FROM product_image as pi WHERE pi.product_id = products.product_id GROUP BY pi.product_id) as images
+ FROM product_image as pi WHERE pi.product_id = product.product_id GROUP BY pi.product_id) as images
END @IF
-- include discount
@@ -799,7 +799,7 @@
,(SELECT price
FROM product_discount pd2
- WHERE pd2.product_id = products.product_id
+ WHERE pd2.product_id = product.product_id
AND pd2.user_group_id = :user_group_id
AND pd2.quantity = '1'
AND ((pd2.from_date = NULL
@@ -817,7 +817,7 @@
,(SELECT price
FROM product_promotion ps
- WHERE ps.product_id = products.product_id
+ WHERE ps.product_id = product.product_id
AND ps.user_group_id = :user_group_id
AND ((ps.from_date = NULL
OR ps.from_date < NOW())
@@ -835,7 +835,7 @@
,(SELECT points
FROM product_points pp
- WHERE pp.product_id = products.product_id
+ WHERE pp.product_id = product.product_id
AND pp.user_group_id = :user_group_id
AS points
@@ -847,7 +847,7 @@
,(SELECT ss.name
FROM stock_status ss
- WHERE ss.stock_status_id = products.stock_status_id
+ WHERE ss.stock_status_id = product.stock_status_id
AND ss.language_id = :language_id)
AS stock_status
@@ -861,7 +861,7 @@
,(SELECT wcd.unit
FROM weight_type_content wcd
- WHERE products.weight_type_id = wcd.weight_type_id
+ WHERE product.weight_type_id = wcd.weight_type_id
AND wcd.language_id = :language_id)
AS weight_type
@@ -874,7 +874,7 @@
,(SELECT lcd.unit
FROM length_type_content lcd
- WHERE products.length_type_id = lcd.length_type_id
+ WHERE product.length_type_id = lcd.length_type_id
AND lcd.language_id = :language_id)
AS length_type
@@ -887,7 +887,7 @@
,(SELECT AVG(rating) AS total
FROM review r1
- WHERE r1.product_id = products.product_id
+ WHERE r1.product_id = product.product_id
AND r1.status = '1'
GROUP BY r1.product_id)
AS rating
@@ -901,7 +901,7 @@
,(SELECT COUNT(*) AS total
FROM review r2
- WHERE r2.product_id = products.product_id
+ WHERE r2.product_id = product.product_id
AND r2.status = '1'
GROUP BY r2.product_id) AS reviews
@@ -911,15 +911,22 @@
@IF isset(:search)
THEN
- ,MATCH(pd.name, pd.content) AGAINST(:search) as score
+ ,MATCH(pd.name, pd.content)
+ AGAINST(
+ :search
+ @IF isset(:search_boolean) && !empty(:search_boolean)
+ THEN
+ IN BOOLEAN MODE
+ END @IF
+ ) as score
END @IF
- FROM product AS products
+ FROM product
- LEFT JOIN product_to_site p2s ON (products.product_id = p2s.product_id)
+ LEFT JOIN product_to_site p2s ON (product.product_id = p2s.product_id)
LEFT JOIN product_content pd ON (
- products.product_id = pd.product_id
+ product.product_id = pd.product_id
@IF isset(:language_id)
THEN
@@ -930,32 +937,32 @@
@IF !empty(:manufacturer)
THEN
- LEFT JOIN manufacturer m ON (products.manufacturer_id = m.manufacturer_id)
+ LEFT JOIN manufacturer m ON (product.manufacturer_id = m.manufacturer_id)
END @IF
@IF !empty(:taxonomy_item_id)
THEN
- INNER JOIN product_to_taxonomy_item pt ON (products.product_id = pt.product_id AND pt.taxonomy_item_id = :taxonomy_item_id)
+ INNER JOIN product_to_taxonomy_item pt ON (product.product_id = pt.product_id AND pt.taxonomy_item_id = :taxonomy_item_id)
END @IF
@IF !empty(:related)
THEN
- INNER JOIN product_related pr ON (pr.product_related_id = products.product_id)
+ INNER JOIN product_related pr ON (pr.product_related_id = product.product_id)
END @IF
@IF !empty(:variant)
THEN
- INNER JOIN product_variant pv ON (pv.product_variant_id = products.product_id)
+ INNER JOIN product_variant pv ON (pv.product_variant_id = product.product_id)
END @IF
@IF !empty(:option_value_id)
THEN
- INNER JOIN product_option_value pov ON (pov.product_id = products.product_id)
+ INNER JOIN product_option_value pov ON (pov.product_id = product.product_id)
END @IF
@IF !empty(:product_attribute) AND !empty(:product_attribute_id)
THEN
- INNER JOIN product_attribute pa ON (pa.product_id = products.product_id)
+ INNER JOIN product_attribute pa ON (pa.product_id = product.product_id)
END @IF
@@ -965,7 +972,14 @@
@IF isset(:search) && !empty(:search)
THEN
-- AND pd.name LIKE CONCAT('%',:search,'%')
- AND MATCH(pd.name, pd.content) AGAINST(:search)
+ AND MATCH(pd.name, pd.content)
+ AGAINST(
+ :search
+ @IF isset(:search_boolean) && !empty(:search_boolean)
+ THEN
+ IN BOOLEAN MODE
+ END @IF
+ )
END @IF
-- like
@@ -977,75 +991,75 @@
@IF isset(:type) && !empty(:type)
THEN
- AND products.type = :type
+ AND product.type = :type
END @IF
@IF isset(:manufacturer_id) && !empty(:manufacturer_id)
THEN
- AND products.manufacturer_id IN (:manufacturer_id)
+ AND product.manufacturer_id IN (:manufacturer_id)
END @IF
@IF isset(:admin_id) && !empty(:admin_id)
THEN
- AND products.admin_id = :admin_id
+ AND product.admin_id = :admin_id
END @IF
@IF isset(:vendor_id) && !empty(:vendor_id)
THEN
- AND products.vendor_id IN (:vendor_id)
+ AND product.vendor_id IN (:vendor_id)
END @IF
@IF isset(:price) && :price !== ""
THEN
- AND products.price = :price
+ AND product.price = :price
END @IF
@IF isset(:quantity) && :quantity !== ""
THEN
- AND products.quantity = :quantity
+ AND product.quantity = :quantity
END @IF
@IF isset(:model) && :model !== ""
THEN
- AND products.model = :model
+ AND product.model = :model
END @IF
@IF isset(:sku) && :sku !== ""
THEN
- AND products.sku = :sku
+ AND product.sku = :sku
END @IF
@IF isset(:barcode) && :barcode !== ""
THEN
- AND products.barcode = :barcode
+ AND product.barcode = :barcode
END @IF
@IF isset(:upc) && :upc !== ""
THEN
- AND products.upc = :upc
+ AND product.upc = :upc
END @IF
@IF isset(:ean) && :ean !== ""
THEN
- AND products.ean = :ean
+ AND product.ean = :ean
END @IF
@IF isset(:isbn) && :isbn !== ""
THEN
- AND products.isbn = :isbn
+ AND product.isbn = :isbn
END @IF
@IF isset(:status) && :status !== ""
THEN
- AND products.status = :status
+ AND product.status = :status
END @IF
@IF isset(:product_id) && count(:product_id) > 0
THEN
- AND products.product_id IN (:product_id)
+ AND product.product_id IN (:product_id)
END @IF
@@ -1098,9 +1112,9 @@
-- 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 products.$order_by $direction
+ ORDER BY product.$order_by $direction
@ELSE
- ORDER BY products.product_id DESC
+ ORDER BY product.product_id DESC
END @IF
@@ -1113,7 +1127,7 @@
SELECT count(*) FROM (
- @SQL_COUNT(products.product_id, product) -- this takes previous query removes limit and replaces select columns with parameter product_id
+ @SQL_COUNT(product.product_id, product) -- this takes previous query removes limit and replaces select columns with parameter product_id
) as count;
diff --git a/admin/sql/mysqli/product_attribute.sql b/admin/sql/mysqli/product_attribute.sql
index 22331e7..68774de 100755
--- a/admin/sql/mysqli/product_attribute.sql
+++ b/admin/sql/mysqli/product_attribute.sql
@@ -12,7 +12,7 @@
BEGIN
-- product_attribute
SELECT product_attribute.*
- FROM product_attribute AS product_attribute
+ FROM product_attribute
WHERE 1 = 1
diff --git a/admin/sql/mysqli/product_content_revision.sql b/admin/sql/mysqli/product_content_revision.sql
index 1c4e99c..1747262 100644
--- a/admin/sql/mysqli/product_content_revision.sql
+++ b/admin/sql/mysqli/product_content_revision.sql
@@ -14,34 +14,34 @@
)
BEGIN
-- product_content_revision
- SELECT revision.product_id, revision.language_id, revision.created_at, revision.admin_id, admin.display_name, admin.username
+ SELECT product_content_revision.product_id, product_content_revision.language_id, product_content_revision.created_at, product_content_revision.admin_id, admin.display_name, admin.username
@IF !empty(:content)
THEN
,content
END @IF
- FROM product_content_revision AS revision
- LEFT JOIN admin ON (admin.admin_id = revision.admin_id)
+ FROM product_content_revision
+ LEFT JOIN admin ON (admin.admin_id = product_content_revision.admin_id)
WHERE 1 = 1
@IF !empty(:product_id)
THEN
- AND revision.product_id = :product_id
+ AND product_content_revision.product_id = :product_id
END @IF
@IF !empty(:language_id)
THEN
- AND revision.language_id = :language_id
+ AND product_content_revision.language_id = :language_id
END @IF
@IF !empty(:created_at)
THEN
- AND revision.created_at = :created_at
+ AND product_content_revision.created_at = :created_at
END @IF
- ORDER BY revision.created_at DESC
+ ORDER BY product_content_revision.created_at DESC
@IF !empty(:limit)
THEN
@@ -51,7 +51,7 @@
SELECT count(*) FROM (
- @SQL_COUNT(revision.product_id, product_content_revision) -- this takes previous query removes limit and replaces select columns with parameter product_id
+ @SQL_COUNT(product_content_revision.product_id, product_content_revision) -- this takes previous query removes limit and replaces select columns with parameter product_id
) as count;
diff --git a/admin/sql/mysqli/product_option.sql b/admin/sql/mysqli/product_option.sql
index 982f469..a593ae6 100755
--- a/admin/sql/mysqli/product_option.sql
+++ b/admin/sql/mysqli/product_option.sql
@@ -13,7 +13,7 @@
BEGIN
-- product_option
SELECT product_option.*, oc.name, `option`.type, product_option.product_option_id as array_key
- FROM product_option AS product_option
+ FROM product_option
INNER JOIN `option` ON `option`.option_id = product_option.option_id
INNER JOIN option_content oc ON oc.option_id = product_option.option_id AND oc.language_id = :language_id
diff --git a/admin/sql/mysqli/product_option_value.sql b/admin/sql/mysqli/product_option_value.sql
index 6926db7..457e7dc 100644
--- a/admin/sql/mysqli/product_option_value.sql
+++ b/admin/sql/mysqli/product_option_value.sql
@@ -17,7 +17,7 @@
SELECT product_option_value.*,
option_value.image, ovc.name, oc.name as `option`,
product_option_value.product_option_value_id as array_key
- FROM product_option_value AS product_option_value
+ FROM product_option_value
INNER JOIN option_value ON option_value.option_value_id = product_option_value.option_value_id
INNER JOIN option_value_content ovc ON ovc.option_value_id = product_option_value.option_value_id AND ovc.language_id = :language_id
INNER JOIN option_content oc ON oc.option_id = product_option_value.option_id AND oc.language_id = :language_id
diff --git a/admin/sql/mysqli/product_question.sql b/admin/sql/mysqli/product_question.sql
index 4d0a41e..541a667 100755
--- a/admin/sql/mysqli/product_question.sql
+++ b/admin/sql/mysqli/product_question.sql
@@ -19,7 +19,7 @@
BEGIN
SELECT user.username, user.email, user.first_name, user.last_name, user.display_name, user.avatar, user.bio, user.subscribe, product_question.*,user.user_id as user_id
- FROM product_question AS product_question
+ FROM product_question
LEFT JOIN user on user.user_id = product_question.user_id
WHERE 1 = 1
diff --git a/admin/sql/mysqli/product_subscription.sql b/admin/sql/mysqli/product_subscription.sql
index f30d788..4412845 100644
--- a/admin/sql/mysqli/product_subscription.sql
+++ b/admin/sql/mysqli/product_subscription.sql
@@ -24,7 +24,7 @@
product_subscription.price,
product_subscription.trial_price
- FROM product_subscription AS product_subscription
+ FROM product_subscription
-- product_id
@IF isset(:product_id)
diff --git a/admin/sql/mysqli/region.sql b/admin/sql/mysqli/region.sql
index fb516e8..65626c9 100755
--- a/admin/sql/mysqli/region.sql
+++ b/admin/sql/mysqli/region.sql
@@ -14,7 +14,7 @@
BEGIN
-- region
SELECT country.name as country,region.*
- FROM region AS region
+ FROM region
LEFT JOIN country ON country.country_id = region.country_id
WHERE 1 = 1
diff --git a/admin/sql/mysqli/region_group.sql b/admin/sql/mysqli/region_group.sql
index e241e32..cbb0e21 100755
--- a/admin/sql/mysqli/region_group.sql
+++ b/admin/sql/mysqli/region_group.sql
@@ -12,7 +12,7 @@
BEGIN
-- region_group
SELECT *
- FROM region_group AS region_group WHERE 1 = 1
+ FROM region_group WHERE 1 = 1
@IF !empty(:limit)
THEN
diff --git a/admin/sql/mysqli/return_reason.sql b/admin/sql/mysqli/return_reason.sql
index 1624d4a..f05f6ac 100755
--- a/admin/sql/mysqli/return_reason.sql
+++ b/admin/sql/mysqli/return_reason.sql
@@ -12,7 +12,7 @@
BEGIN
-- return_reason
SELECT *
- FROM return_reason AS return_reason WHERE 1 = 1
+ FROM return_reason WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/mysqli/return_resolution.sql b/admin/sql/mysqli/return_resolution.sql
index 83f7f22..a58a3e7 100755
--- a/admin/sql/mysqli/return_resolution.sql
+++ b/admin/sql/mysqli/return_resolution.sql
@@ -12,7 +12,7 @@
BEGIN
-- return resolution
SELECT *
- FROM return_resolution AS return_resolution WHERE 1 = 1
+ FROM return_resolution WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/mysqli/return_status.sql b/admin/sql/mysqli/return_status.sql
index c8ed13c..1bd7981 100755
--- a/admin/sql/mysqli/return_status.sql
+++ b/admin/sql/mysqli/return_status.sql
@@ -12,7 +12,7 @@
BEGIN
-- return_status
SELECT *
- FROM return_status AS return_status WHERE 1 = 1
+ FROM return_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/mysqli/shipping_status.sql b/admin/sql/mysqli/shipping_status.sql
index d9ed4c9..dcdc489 100644
--- a/admin/sql/mysqli/shipping_status.sql
+++ b/admin/sql/mysqli/shipping_status.sql
@@ -12,7 +12,7 @@
BEGIN
SELECT *
- FROM shipping_status AS shipping_status WHERE 1 = 1
+ FROM shipping_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/mysqli/site.sql b/admin/sql/mysqli/site.sql
index f8f0d96..10ce1e9 100755
--- a/admin/sql/mysqli/site.sql
+++ b/admin/sql/mysqli/site.sql
@@ -15,14 +15,14 @@
BEGIN
-- site
SELECT *, site_id as array_key
- FROM site as sites
+ FROM site
WHERE 1 = 1
-- site_id
@IF isset(:site_id) && !empty(:site_id)
THEN
- AND sites.site_id IN (:site_id)
+ AND site.site_id IN (:site_id)
END @IF
-- limit
@@ -34,7 +34,7 @@
-- SELECT FOUND_ROWS() as count;
SELECT count(*) FROM (
- @SQL_COUNT(sites.site_id, site) -- this takes previous query removes limit and replaces select columns with parameter product_id
+ @SQL_COUNT(site.site_id, site) -- this takes previous query removes limit and replaces select columns with parameter product_id
) as count;
END
diff --git a/admin/sql/mysqli/stock_status.sql b/admin/sql/mysqli/stock_status.sql
index 71ce0f6..5a262dc 100755
--- a/admin/sql/mysqli/stock_status.sql
+++ b/admin/sql/mysqli/stock_status.sql
@@ -12,7 +12,7 @@
BEGIN
-- stock_status
SELECT *
- FROM stock_status AS stock_status WHERE 1 = 1
+ FROM stock_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/mysqli/subscription.sql b/admin/sql/mysqli/subscription.sql
index 952bfeb..3ae76a8 100755
--- a/admin/sql/mysqli/subscription.sql
+++ b/admin/sql/mysqli/subscription.sql
@@ -12,7 +12,7 @@
BEGIN
-- subscription
SELECT *
- FROM subscription AS subscription WHERE 1 = 1
+ FROM subscription WHERE 1 = 1
-- limit
@IF isset(:limit)
diff --git a/admin/sql/mysqli/subscription_plan.sql b/admin/sql/mysqli/subscription_plan.sql
index 35145a4..6e81661 100755
--- a/admin/sql/mysqli/subscription_plan.sql
+++ b/admin/sql/mysqli/subscription_plan.sql
@@ -13,7 +13,7 @@
BEGIN
-- subscription_plan
SELECT subscription_plan.*,subscription_plan_content.name,subscription_plan.subscription_plan_id as array_key
- FROM subscription_plan AS subscription_plan
+ FROM subscription_plan
INNER JOIN subscription_plan_content ON subscription_plan_content.subscription_plan_id = subscription_plan.subscription_plan_id
AND subscription_plan_content.language_id = :language_id
WHERE 1 = 1
diff --git a/admin/sql/mysqli/subscription_status.sql b/admin/sql/mysqli/subscription_status.sql
index b50fb65..8cb2343 100755
--- a/admin/sql/mysqli/subscription_status.sql
+++ b/admin/sql/mysqli/subscription_status.sql
@@ -12,7 +12,7 @@
BEGIN
-- subscription_status
SELECT *
- FROM subscription_status AS subscription_status WHERE 1 = 1
+ FROM subscription_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/mysqli/tax_rate.sql b/admin/sql/mysqli/tax_rate.sql
index 8ab847c..6528240 100755
--- a/admin/sql/mysqli/tax_rate.sql
+++ b/admin/sql/mysqli/tax_rate.sql
@@ -12,7 +12,7 @@
BEGIN
-- tax_rate
SELECT *
- FROM tax_rate AS tax_rate WHERE 1 = 1
+ FROM tax_rate WHERE 1 = 1
@IF !empty(:limit)
diff --git a/admin/sql/mysqli/tax_rule.sql b/admin/sql/mysqli/tax_rule.sql
index 9c0c441..116139f 100755
--- a/admin/sql/mysqli/tax_rule.sql
+++ b/admin/sql/mysqli/tax_rule.sql
@@ -12,7 +12,7 @@
BEGIN
-- tax_rule
SELECT *
- FROM tax_rule AS tax_rule WHERE 1 = 1
+ FROM tax_rule WHERE 1 = 1
@IF !empty(:tax_type_id)
diff --git a/admin/sql/mysqli/tax_type.sql b/admin/sql/mysqli/tax_type.sql
index d956d74..cb886f4 100755
--- a/admin/sql/mysqli/tax_type.sql
+++ b/admin/sql/mysqli/tax_type.sql
@@ -12,7 +12,7 @@
BEGIN
-- tax_type
SELECT *
- FROM tax_type AS tax_type WHERE 1 = 1
+ FROM tax_type WHERE 1 = 1
@SQL_LIMIT(:start, :limit);
diff --git a/admin/sql/mysqli/taxonomy.sql b/admin/sql/mysqli/taxonomy.sql
index 3c83f3f..b129d74 100755
--- a/admin/sql/mysqli/taxonomy.sql
+++ b/admin/sql/mysqli/taxonomy.sql
@@ -19,7 +19,7 @@
BEGIN
-- taxonomy_item
SELECT *, taxonomy_id as array_key
- FROM taxonomy as taxonomy
+ FROM taxonomy
-- LEFT JOIN taxonomy_to_site t2s ON (taxonomy_item.taxonomy_item_id = t2s.taxonomy_item_id)
WHERE 1 = 1
diff --git a/admin/sql/mysqli/user.sql b/admin/sql/mysqli/user.sql
index 05a11cb..bcb4073 100755
--- a/admin/sql/mysqli/user.sql
+++ b/admin/sql/mysqli/user.sql
@@ -3,13 +3,17 @@
-- get all entries
CREATE PROCEDURE getAll(
- IN start INT,
- IN limit INT,
IN status INT,
IN search CHAR,
IN email CHAR,
IN phone_number CHAR,
-
+
+ -- pagination
+ IN start INT,
+ IN limit INT,
+ IN order_by CHAR,
+ IN direction CHAR,
+
-- return array of user
OUT fetch_all,
-- return user count for count query
@@ -42,7 +46,14 @@
user.first_name LIKE CONCAT('%',:search,'%') OR
user.last_name LIKE CONCAT('%',:search,'%')
END @IF
-
+
+ -- 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
+ @ELSE
+ ORDER BY user.user_id DESC
+ END @IF
-- limit
@IF isset(:limit)
diff --git a/admin/sql/mysqli/user_address.sql b/admin/sql/mysqli/user_address.sql
index 783d572..581b3bf 100755
--- a/admin/sql/mysqli/user_address.sql
+++ b/admin/sql/mysqli/user_address.sql
@@ -19,7 +19,7 @@
SELECT *
- FROM user_address AS user_address
+ FROM user_address
WHERE 1 = 1
-- user
diff --git a/admin/sql/mysqli/user_group.sql b/admin/sql/mysqli/user_group.sql
index a5e7c3b..93afb8c 100755
--- a/admin/sql/mysqli/user_group.sql
+++ b/admin/sql/mysqli/user_group.sql
@@ -12,7 +12,7 @@
BEGIN
-- user_group
SELECT user_group.*,user_group_content.name, user_group_content.content, user_group_content.language_id
- FROM user_group AS user_group
+ FROM user_group
INNER JOIN user_group_content ON user_group_content.user_group_id = user_group.user_group_id
WHERE 1 = 1
diff --git a/admin/sql/mysqli/vendor.sql b/admin/sql/mysqli/vendor.sql
index abb7718..a6c21a0 100755
--- a/admin/sql/mysqli/vendor.sql
+++ b/admin/sql/mysqli/vendor.sql
@@ -106,7 +106,7 @@
)
BEGIN
- SELECT * FROM vendor AS vendor
+ SELECT * FROM vendor
LEFT JOIN vendor_to_site p2s ON (vendor.vendor_id = p2s.vendor_id)
WHERE p2s.site_id = :site_id
diff --git a/admin/sql/mysqli/voucher.sql b/admin/sql/mysqli/voucher.sql
index 1abacb8..07c946d 100755
--- a/admin/sql/mysqli/voucher.sql
+++ b/admin/sql/mysqli/voucher.sql
@@ -12,7 +12,7 @@
BEGIN
-- voucher
SELECT *
- FROM voucher AS voucher WHERE 1 = 1
+ FROM voucher WHERE 1 = 1
@SQL_LIMIT(:start, :limit);
diff --git a/admin/sql/mysqli/weight_type.sql b/admin/sql/mysqli/weight_type.sql
index 1c3f72a..127fb97 100755
--- a/admin/sql/mysqli/weight_type.sql
+++ b/admin/sql/mysqli/weight_type.sql
@@ -12,7 +12,7 @@
BEGIN
-- weight_type
SELECT *, weight_type.weight_type_id as array_key
- FROM weight_type AS weight_type
+ FROM weight_type
INNER JOIN weight_type_content ON weight_type_content.weight_type_id = weight_type.weight_type_id
WHERE 1 = 1
diff --git a/admin/sql/pgsql/admin.sql b/admin/sql/pgsql/admin.sql
index 76b3337..78b8bc5 100755
--- a/admin/sql/pgsql/admin.sql
+++ b/admin/sql/pgsql/admin.sql
@@ -17,7 +17,7 @@
)
BEGIN
- SELECT * FROM admin AS admin WHERE 1 = 1
+ SELECT * FROM admin WHERE 1 = 1
@IF isset(:status) AND !empty(:status)
diff --git a/admin/sql/pgsql/attribute.sql b/admin/sql/pgsql/attribute.sql
index 152dacf..e384ed0 100755
--- a/admin/sql/pgsql/attribute.sql
+++ b/admin/sql/pgsql/attribute.sql
@@ -20,7 +20,7 @@
,pa.value
END @IF
- FROM attribute AS attribute
+ FROM attribute
INNER JOIN attribute_content
ON attribute_content.attribute_id = attribute.attribute_id AND attribute_content.language_id = :language_id
INNER JOIN attribute_group_content
diff --git a/admin/sql/pgsql/attribute_group.sql b/admin/sql/pgsql/attribute_group.sql
index 543c7f7..7144afe 100755
--- a/admin/sql/pgsql/attribute_group.sql
+++ b/admin/sql/pgsql/attribute_group.sql
@@ -18,7 +18,7 @@
,pa.value
END @IF
- FROM attribute_group AS attribute_group
+ FROM attribute_group
INNER JOIN attribute_group_content
ON attribute_group_content.attribute_group_id = attribute_group.attribute_group_id AND attribute_group_content.language_id = :language_id
diff --git a/admin/sql/pgsql/comment.sql b/admin/sql/pgsql/comment.sql
index 9ac885a..e277637 100755
--- a/admin/sql/pgsql/comment.sql
+++ b/admin/sql/pgsql/comment.sql
@@ -23,14 +23,14 @@
)
BEGIN
- SELECT user.username, user.email, user.first_name, user.last_name, user.display_name, user.avatar, user.bio, user.subscribe, comment.*, comment_id as array_key
+ SELECT "user".username, "user".email, "user".first_name, "user".last_name, "user".display_name, "user".avatar, "user".bio, "user".subscribe, comment.*, comment_id as array_key
@IF isset(:post_title) AND :post_title
THEN
,post_content.name, post_content.slug
END @IF
- FROM comment AS comment
- LEFT JOIN user ON (user.user_id = comment.user_id)
+ FROM comment
+ LEFT JOIN "user" ON ("user".user_id = comment.user_id)
@IF isset(:post_title) AND :post_title
THEN
@@ -95,7 +95,7 @@
SELECT *
FROM comment AS _
- LEFT JOIN user ON user.user_id = _.user_id
+ LEFT JOIN "user" ON "user".user_id = _.user_id
WHERE 1 = 1
@IF isset(:comment_id)
diff --git a/admin/sql/pgsql/country.sql b/admin/sql/pgsql/country.sql
index e85abf3..8bea25e 100755
--- a/admin/sql/pgsql/country.sql
+++ b/admin/sql/pgsql/country.sql
@@ -13,7 +13,7 @@
BEGIN
-- country
SELECT *
- FROM country AS country WHERE 1 = 1
+ FROM country WHERE 1 = 1
@IF isset(:status) AND :status != ""
THEN
diff --git a/admin/sql/pgsql/coupon.sql b/admin/sql/pgsql/coupon.sql
index 0e43fc6..226d4e9 100755
--- a/admin/sql/pgsql/coupon.sql
+++ b/admin/sql/pgsql/coupon.sql
@@ -12,7 +12,7 @@
BEGIN
-- coupon
SELECT *
- FROM coupon AS coupon WHERE 1 = 1
+ FROM coupon WHERE 1 = 1
@SQL_LIMIT(:start, :limit);
diff --git a/admin/sql/pgsql/currency.sql b/admin/sql/pgsql/currency.sql
index 65056c9..97af59c 100755
--- a/admin/sql/pgsql/currency.sql
+++ b/admin/sql/pgsql/currency.sql
@@ -11,7 +11,7 @@
BEGIN
-- currency
SELECT *, code as array_key
- FROM currency as currency WHERE 1 = 1
+ FROM currency WHERE 1 = 1
@IF isset(:status) AND :status != ""
THEN
diff --git a/admin/sql/pgsql/digital_asset.sql b/admin/sql/pgsql/digital_asset.sql
index 23a2701..6d822f0 100755
--- a/admin/sql/pgsql/digital_asset.sql
+++ b/admin/sql/pgsql/digital_asset.sql
@@ -21,7 +21,7 @@
, o.customer_order_id, o.order_id, op.name as product_name
END @IF
- FROM digital_asset AS digital_asset
+ FROM digital_asset
INNER JOIN digital_asset_content ON digital_asset_content.digital_asset_id = digital_asset.digital_asset_id
AND digital_asset_content.language_id = :language_id
diff --git a/admin/sql/pgsql/digital_asset_log.sql b/admin/sql/pgsql/digital_asset_log.sql
index 6df0642..c4774e5 100644
--- a/admin/sql/pgsql/digital_asset_log.sql
+++ b/admin/sql/pgsql/digital_asset_log.sql
@@ -13,7 +13,7 @@
SELECT digital_asset_log.*
- FROM digital_asset_log AS digital_asset_log
+ FROM digital_asset_log
WHERE 1 = 1
diff --git a/admin/sql/pgsql/field.sql b/admin/sql/pgsql/field.sql
index cf8b819..c90e913 100755
--- a/admin/sql/pgsql/field.sql
+++ b/admin/sql/pgsql/field.sql
@@ -18,7 +18,7 @@
BEGIN
-- field_item
SELECT *, field_id as array_key
- FROM field as field
+ FROM field
-- LEFT JOIN field_to_site t2s ON (field_item.field_item_id = t2s.field_item_id)
WHERE 1 = 1
diff --git a/admin/sql/pgsql/field_group.sql b/admin/sql/pgsql/field_group.sql
index 1593f5b..502d068 100755
--- a/admin/sql/pgsql/field_group.sql
+++ b/admin/sql/pgsql/field_group.sql
@@ -12,7 +12,7 @@
BEGIN
-- field_group
SELECT *
- FROM field_group AS field_group
+ FROM field_group
INNER JOIN field_group_content ON field_group_content.field_group_id = field_group.field_group_id
WHERE 1 = 1
diff --git a/admin/sql/pgsql/language.sql b/admin/sql/pgsql/language.sql
index 773ddd8..eaaf67c 100755
--- a/admin/sql/pgsql/language.sql
+++ b/admin/sql/pgsql/language.sql
@@ -13,7 +13,7 @@
BEGIN
-- language
SELECT *, code as array_key
- FROM language as language WHERE 1 = 1
+ FROM language WHERE 1 = 1
@IF isset(:status)
THEN
diff --git a/admin/sql/pgsql/length_type.sql b/admin/sql/pgsql/length_type.sql
index d569779..0145c3e 100755
--- a/admin/sql/pgsql/length_type.sql
+++ b/admin/sql/pgsql/length_type.sql
@@ -12,7 +12,7 @@
BEGIN
-- length_type
SELECT *, length_type.length_type_id as array_key
- FROM length_type AS length_type
+ FROM length_type
INNER JOIN length_type_content ON length_type_content.length_type_id = length_type.length_type_id
WHERE 1 = 1
diff --git a/admin/sql/pgsql/manufacturer.sql b/admin/sql/pgsql/manufacturer.sql
index 6db8d93..1b95d58 100755
--- a/admin/sql/pgsql/manufacturer.sql
+++ b/admin/sql/pgsql/manufacturer.sql
@@ -110,7 +110,7 @@
)
BEGIN
- SELECT * FROM manufacturer AS manufacturer
+ SELECT * FROM manufacturer
LEFT JOIN manufacturer_to_site p2s ON (manufacturer.manufacturer_id = p2s.manufacturer_id)
WHERE p2s.site_id = :site_id
diff --git a/admin/sql/pgsql/menu.sql b/admin/sql/pgsql/menu.sql
index b610652..a87cc7c 100755
--- a/admin/sql/pgsql/menu.sql
+++ b/admin/sql/pgsql/menu.sql
@@ -90,7 +90,7 @@
-- get all menus
- CREATE PROCEDURE getMenusList(
+ CREATE PROCEDURE getAll(
-- variables
IN language_id INT,
@@ -113,7 +113,7 @@
SELECT *, menu.menu_id as array_key
- FROM menu AS menu
+ FROM menu
@SQL_LIMIT(:start, :limit);
@@ -125,12 +125,12 @@
) as count;
- END -- get all menus
+ END
- -- get all menus
+ -- get menu
- CREATE PROCEDURE getMenus(
+ CREATE PROCEDURE get(
-- variables
IN language_id INT,
@@ -150,13 +150,13 @@
)
BEGIN
- SELECT td.*,menus.url, menus.sort_order, menus.parent_id, menus.type, menus.item_id, menus.menu_item_id as array_key
+ SELECT td.*,menu.url, menu.sort_order, menu.parent_id, menu.type, menu.item_id, menu.menu_item_id as array_key
- FROM menu_item AS menus
+ FROM menu_item AS menu
- -- INNER JOIN menu_to_site c2s ON (menus.menu_id = c2s.menu_id AND c2s.site_id = :site_id)
- INNER JOIN menu_item_content td ON (menus.menu_item_id = td.menu_item_id AND td.language_id = :language_id)
+ -- INNER JOIN menu_to_site c2s ON (menu.menu_id = c2s.menu_id AND c2s.site_id = :site_id)
+ INNER JOIN menu_item_content td ON (menu.menu_item_id = td.menu_item_id AND td.language_id = :language_id)
WHERE
@@ -166,18 +166,18 @@
@IF isset(:menu_id)
THEN
- AND menus.menu_id = :menu_id
+ AND menu.menu_id = :menu_id
END @IF
@IF isset(:slug)
THEN
- AND menus.menu_id = (SELECT menu_id FROM menu WHERE slug = :slug LIMIT 1)
+ AND menu.menu_id = (SELECT menu_id FROM menu WHERE slug = :slug LIMIT 1)
END @IF
- ORDER BY menus.parent_id, menus.sort_order, menus.menu_id
+ ORDER BY menu.parent_id, menu.sort_order, menu.menu_id
@IF isset(:limit)
THEN
diff --git a/admin/sql/pgsql/option.sql b/admin/sql/pgsql/option.sql
index 9620131..3628517 100644
--- a/admin/sql/pgsql/option.sql
+++ b/admin/sql/pgsql/option.sql
@@ -12,7 +12,7 @@
BEGIN
-- option
SELECT "option".*, option_content.name
- FROM "option" AS "option"
+ FROM "option"
INNER JOIN option_content
ON option_content.option_id = "option".option_id AND option_content.language_id = :language_id
diff --git a/admin/sql/pgsql/option_value.sql b/admin/sql/pgsql/option_value.sql
index e2fce4f..492bdcf 100644
--- a/admin/sql/pgsql/option_value.sql
+++ b/admin/sql/pgsql/option_value.sql
@@ -13,7 +13,7 @@
BEGIN
-- option_value
SELECT option_value.*, option_value_content.name
- FROM option_value AS option_value
+ FROM option_value
INNER JOIN option_value_content
ON option_value_content.option_value_id = option_value.option_value_id AND option_value_content.language_id = :language_id
diff --git a/admin/sql/pgsql/order.sql b/admin/sql/pgsql/order.sql
index ac388b4..728a2d2 100755
--- a/admin/sql/pgsql/order.sql
+++ b/admin/sql/pgsql/order.sql
@@ -24,6 +24,8 @@
-- pagination
IN start INT,
IN limit INT,
+ IN order_by CHAR,
+ IN direction CHAR,
-- return
@@ -95,7 +97,13 @@
"order".last_name LIKE '%' || :search || '%'
END @IF
- ORDER BY order_id DESC
+ -- 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
+ @ELSE
+ ORDER BY order_id DESC
+ END @IF
@SQL_LIMIT(:start, :limit);
diff --git a/admin/sql/pgsql/order_log.sql b/admin/sql/pgsql/order_log.sql
index fb58cae..2cae4ba 100644
--- a/admin/sql/pgsql/order_log.sql
+++ b/admin/sql/pgsql/order_log.sql
@@ -12,7 +12,7 @@
BEGIN
-- order_log
SELECT *
- FROM order_log AS order_log WHERE 1 = 1
+ FROM order_log WHERE 1 = 1
@IF !empty(:order_id)
THEN
diff --git a/admin/sql/pgsql/order_status.sql b/admin/sql/pgsql/order_status.sql
index 97eefd7..9a4ca73 100755
--- a/admin/sql/pgsql/order_status.sql
+++ b/admin/sql/pgsql/order_status.sql
@@ -11,7 +11,7 @@
)
BEGIN
SELECT *
- FROM order_status AS order_status WHERE 1 = 1
+ FROM order_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/pgsql/payment_status.sql b/admin/sql/pgsql/payment_status.sql
index 20e5259..3f6f826 100644
--- a/admin/sql/pgsql/payment_status.sql
+++ b/admin/sql/pgsql/payment_status.sql
@@ -11,7 +11,7 @@
)
BEGIN
SELECT *
- FROM payment_status AS payment_status WHERE 1 = 1
+ FROM payment_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/pgsql/post.sql b/admin/sql/pgsql/post.sql
index 8cdf552..ca218a4 100755
--- a/admin/sql/pgsql/post.sql
+++ b/admin/sql/pgsql/post.sql
@@ -28,6 +28,9 @@
IN tags INT,
IN taxonomy CHAR,
+ IN order_by CHAR,
+ IN direction CHAR,
+
-- return array of posts for posts query
OUT fetch_all,
-- return posts count for count query
@@ -35,13 +38,13 @@
)
BEGIN
- SELECT pd.*,posts.*,ad.username,ad.display_name,ad.admin_id,ad.email, ad.avatar, ad.bio, ad.first_name, ad.last_name
+ SELECT pd.*,post.*,ad.username,ad.display_name,ad.admin_id,ad.email, ad.avatar, ad.bio, ad.first_name, ad.last_name
@IF isset(:comment_count)
THEN
,(SELECT COUNT(c.comment_id)
FROM comment c
WHERE
- posts.post_id = c.post_id
+ post.post_id = c.post_id
@IF isset(:comment_status)
THEN
@@ -62,9 +65,9 @@
END @IF
- FROM post AS posts
+ FROM post
LEFT JOIN post_content pd ON (
- posts.post_id = pd.post_id
+ post.post_id = pd.post_id
@IF isset(:language_id)
THEN
@@ -72,38 +75,38 @@
END @IF
)
- LEFT JOIN post_to_site ps ON (posts.post_id = ps.post_id)
- LEFT JOIN admin ad ON (posts.admin_id = ad.admin_id)
+ LEFT JOIN post_to_site ps ON (post.post_id = ps.post_id)
+ LEFT JOIN admin ad ON (post.admin_id = ad.admin_id)
@IF isset(:taxonomy_item_id) || isset(:taxonomy_item_slug)
THEN
- LEFT JOIN post_to_taxonomy_item pt ON (posts.post_id = pt.post_id)
+ LEFT JOIN post_to_taxonomy_item pt ON (post.post_id = pt.post_id)
END @IF
WHERE 1 = 1
@IF isset(:type) && !empty(:type)
THEN
- AND posts.type = :type
+ AND post.type = :type
END @IF
@IF isset(:status) && !empty(:status)
THEN
- AND posts.status = :status
+ AND post.status = :status
@ELSE
- AND posts.status = 'publish'
+ AND post.status = 'publish'
END @IF
-- username/author
@IF isset(:username)
THEN
- AND posts.admin_id = (SELECT admin_id FROM admin WHERE username = :username LIMIT 1)
+ AND post.admin_id = (SELECT admin_id FROM admin WHERE username = :username LIMIT 1)
END @IF
-- admin_id
@IF isset(:admin_id)
THEN
- AND posts.admin_id = :admin_id
+ AND post.admin_id = :admin_id
END @IF
-- search
@@ -125,7 +128,7 @@
@IF isset(:post_id) && count(:post_id) > 0
THEN
- AND posts.post_id IN (:post_id)
+ AND post.post_id IN (:post_id)
END @IF
@@ -155,21 +158,21 @@
-- month
@IF isset(:month) && !empty(:month)
THEN
- AND date_part('month',posts.created_at) = :month
+ AND date_part('month',post.created_at) = :month
END @IF
-- year
@IF isset(:year) && !empty(:year)
THEN
- AND date_part('year',posts.created_at) = :year
+ AND date_part('year',post.created_at) = :year
END @IF
- -- order by
+ -- 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 posts.$order_by $direction
+ ORDER BY post.$order_by $direction
@ELSE
- ORDER BY posts.post_id DESC
+ ORDER BY post.post_id DESC
END @IF
-- limit
@@ -182,7 +185,7 @@
-- SELECT FOUND_ROWS() as count;
SELECT count(*) FROM (
- @SQL_COUNT(posts.post_id, post) -- this takes previous query removes limit and replaces select columns with parameter product_id
+ @SQL_COUNT(post.post_id, post) -- this takes previous query removes limit and replaces select columns with parameter product_id
) as count;
@@ -264,7 +267,7 @@
-- content
SELECT *, language_id as array_key -- (underscore) _ column means that this column (language_id) value will be used as array key when adding row to result array
- FROM post_content AS post_content
+ FROM post_content
WHERE post_id = @result.post_id;
diff --git a/admin/sql/pgsql/post_content_revision.sql b/admin/sql/pgsql/post_content_revision.sql
index 77df20b..7e66382 100644
--- a/admin/sql/pgsql/post_content_revision.sql
+++ b/admin/sql/pgsql/post_content_revision.sql
@@ -14,34 +14,34 @@
)
BEGIN
-- post_content_revision
- SELECT revision.post_id, revision.language_id, revision.created_at, revision.admin_id, admin.display_name, admin.username
+ SELECT post_content_revision.post_id, post_content_revision.language_id, post_content_revision.created_at, post_content_revision.admin_id, admin.display_name, admin.username
@IF !empty(:content)
THEN
,content
END @IF
- FROM post_content_revision AS revision
- LEFT JOIN admin ON (admin.admin_id = revision.admin_id)
+ FROM post_content_revision
+ LEFT JOIN admin ON (admin.admin_id = post_content_revision.admin_id)
WHERE 1 = 1
@IF !empty(:post_id)
THEN
- AND revision.post_id = :post_id
+ AND post_content_revision.post_id = :post_id
END @IF
@IF !empty(:language_id)
THEN
- AND revision.language_id = :language_id
+ AND post_content_revision.language_id = :language_id
END @IF
@IF !empty(:created_at)
THEN
- AND revision.created_at = :created_at
+ AND post_content_revision.created_at = :created_at
END @IF
- ORDER BY revision.created_at DESC
+ ORDER BY post_content_revision.created_at DESC
@IF !empty(:limit)
THEN
@@ -51,7 +51,7 @@
SELECT count(*) FROM (
- @SQL_COUNT(revision.post_id, post_content_revision) -- this takes previous query removes limit and replaces select columns with parameter product_id
+ @SQL_COUNT(post_content_revision.post_id, post_content_revision) -- this takes previous query removes limit and replaces select columns with parameter product_id
) as count;
diff --git a/admin/sql/pgsql/product.sql b/admin/sql/pgsql/product.sql
index 4b283fc..beb89db 100755
--- a/admin/sql/pgsql/product.sql
+++ b/admin/sql/pgsql/product.sql
@@ -346,13 +346,13 @@
user_group.user_group_id as array_key, -- stock_status_id as key
name as array_value -- name as value
- FROM user_group as user_group
+ FROM user_group
INNER JOIN user_group_content ON user_group_content.user_group_id = user_group.user_group_id;
-- subscription plan
SELECT subscription_plan.subscription_plan_id as array_key,
subscription_plan_content.name as array_value
- FROM subscription_plan AS subscription_plan
+ FROM subscription_plan
INNER JOIN subscription_plan_content ON subscription_plan_content.subscription_plan_id = subscription_plan.subscription_plan_id
AND subscription_plan_content.language_id = :language_id
-- LIMIT 100
@@ -362,7 +362,7 @@
"option".option_id as array_key, -- option_id as key
option_content.name,
"option".type
- FROM "option" AS "option"
+ FROM "option"
INNER JOIN option_content
ON option_content.option_id = "option".option_id AND option_content.language_id = :language_id
-- LIMIT 100
@@ -774,7 +774,7 @@
)
BEGIN
- SELECT pd.*,products.*, products.product_id as array_key
+ SELECT pd.*,product.*, product.product_id as array_key
@IF !empty(:manufacturer)
THEN
@@ -786,8 +786,8 @@
@IF !empty(:product_image)
THEN
- --,(SELECT '[' || STRING_AGG('{"id":"' || pi.product_image_id || '","image":"' || pi.image || '"}') || ']' FROM product_image as pi WHERE pi.product_id = products.product_id GROUP BY pi.product_id) as images
- ,(SELECT json_agg(json_build_object('id',pi.product_image_id,'image',pi.image)) FROM product_image as pi WHERE pi.product_id = products.product_id GROUP BY pi.product_id) as images
+ --,(SELECT '[' || STRING_AGG('{"id":"' || pi.product_image_id || '","image":"' || pi.image || '"}') || ']' FROM product_image as pi WHERE pi.product_id = product.product_id GROUP BY pi.product_id) as images
+ ,(SELECT json_agg(json_build_object('id',pi.product_image_id,'image',pi.image)) FROM product_image as pi WHERE pi.product_id = product.product_id GROUP BY pi.product_id) as images
END @IF
-- include discount
@@ -796,7 +796,7 @@
,(SELECT price
FROM product_discount pd2
- WHERE pd2.product_id = products.product_id
+ WHERE pd2.product_id = product.product_id
AND pd2.user_group_id = :user_group_id
AND pd2.quantity = '1'
AND ((pd2.from_date = NULL
@@ -814,7 +814,7 @@
,(SELECT price
FROM product_promotion ps
- WHERE ps.product_id = products.product_id
+ WHERE ps.product_id = product.product_id
AND ps.user_group_id = :user_group_id
AND ((ps.from_date = NULL
OR ps.from_date < NOW())
@@ -832,7 +832,7 @@
,(SELECT points
FROM product_points pp
- WHERE pp.product_id = products.product_id
+ WHERE pp.product_id = product.product_id
AND pp.user_group_id = :user_group_id
AS points
@@ -844,7 +844,7 @@
,(SELECT ss.name
FROM stock_status ss
- WHERE ss.stock_status_id = products.stock_status_id
+ WHERE ss.stock_status_id = product.stock_status_id
AND ss.language_id = :language_id)
AS stock_status
@@ -858,7 +858,7 @@
,(SELECT wcd.unit
FROM weight_type_content wcd
- WHERE products.weight_type_id = wcd.weight_type_id
+ WHERE product.weight_type_id = wcd.weight_type_id
AND wcd.language_id = :language_id)
AS weight_type
@@ -871,7 +871,7 @@
,(SELECT lcd.unit
FROM length_type_content lcd
- WHERE products.length_type_id = lcd.length_type_id
+ WHERE product.length_type_id = lcd.length_type_id
AND lcd.language_id = :language_id)
AS length_type
@@ -884,7 +884,7 @@
,(SELECT AVG(rating) AS total
FROM review r1
- WHERE r1.product_id = products.product_id
+ WHERE r1.product_id = product.product_id
AND r1.status = '1'
GROUP BY r1.product_id)
AS rating
@@ -898,7 +898,7 @@
,(SELECT COUNT(*) AS total
FROM review r2
- WHERE r2.product_id = products.product_id
+ WHERE r2.product_id = product.product_id
AND r2.status = '1'
GROUP BY r2.product_id) AS reviews
@@ -916,11 +916,11 @@
END @IF
- FROM product AS products
+ FROM product
- LEFT JOIN product_to_site p2s ON (products.product_id = p2s.product_id)
+ LEFT JOIN product_to_site p2s ON (product.product_id = p2s.product_id)
LEFT JOIN product_content pd ON (
- products.product_id = pd.product_id
+ product.product_id = pd.product_id
@IF isset(:language_id)
THEN
@@ -931,22 +931,22 @@
@IF !empty(:manufacturer)
THEN
- LEFT JOIN manufacturer m ON (products.manufacturer_id = m.manufacturer_id)
+ LEFT JOIN manufacturer m ON (product.manufacturer_id = m.manufacturer_id)
END @IF
@IF !empty(:taxonomy_item_id)
THEN
- INNER JOIN product_to_taxonomy_item pt ON (products.product_id = pt.product_id AND pt.taxonomy_item_id = :taxonomy_item_id)
+ INNER JOIN product_to_taxonomy_item pt ON (product.product_id = pt.product_id AND pt.taxonomy_item_id = :taxonomy_item_id)
END @IF
@IF !empty(:related)
THEN
- INNER JOIN product_related pr ON (pr.product_related_id = products.product_id)
+ INNER JOIN product_related pr ON (pr.product_related_id = product.product_id)
END @IF
@IF !empty(:variant)
THEN
- INNER JOIN product_variant pv ON (pv.product_variant_id = products.product_id)
+ INNER JOIN product_variant pv ON (pv.product_variant_id = product.product_id)
END @IF
@@ -969,75 +969,75 @@
@IF isset(:type) && !empty(:type)
THEN
- AND products.type = :type
+ AND product.type = :type
END @IF
@IF isset(:manufacturer_id) && !empty(:manufacturer_id)
THEN
- AND products.manufacturer_id IN (:manufacturer_id)
+ AND product.manufacturer_id IN (:manufacturer_id)
END @IF
@IF isset(:admin_id) && !empty(:admin_id)
THEN
- AND products.admin_id = :admin_id
+ AND product.admin_id = :admin_id
END @IF
@IF isset(:vendor_id) && !empty(:vendor_id)
THEN
- AND products.vendor_id IN (:vendor_id)
+ AND product.vendor_id IN (:vendor_id)
END @IF
@IF isset(:price) && :price !== ""
THEN
- AND products.price = :price
+ AND product.price = :price
END @IF
@IF isset(:quantity) && :quantity !== ""
THEN
- AND products.quantity = :quantity
+ AND product.quantity = :quantity
END @IF
@IF isset(:model) && :model !== ""
THEN
- AND products.model = :model
+ AND product.model = :model
END @IF
@IF isset(:sku) && :sku !== ""
THEN
- AND products.sku = :sku
+ AND product.sku = :sku
END @IF
@IF isset(:barcode) && :barcode !== ""
THEN
- AND products.barcode = :barcode
+ AND product.barcode = :barcode
END @IF
@IF isset(:upc) && :upc !== ""
THEN
- AND products.upc = :upc
+ AND product.upc = :upc
END @IF
@IF isset(:ean) && :ean !== ""
THEN
- AND products.ean = :ean
+ AND product.ean = :ean
END @IF
@IF isset(:isbn) && :isbn !== ""
THEN
- AND products.isbn = :isbn
+ AND product.isbn = :isbn
END @IF
@IF isset(:status) && :status !== ""
THEN
- AND products.status = :status
+ AND product.status = :status
END @IF
@IF isset(:product_id) && count(:product_id) > 0
THEN
- AND products.product_id IN (:product_id)
+ AND product.product_id IN (:product_id)
END @IF
@@ -1074,9 +1074,9 @@
-- 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 products.$order_by $direction
+ ORDER BY product.$order_by $direction
@ELSE
- ORDER BY products.product_id DESC
+ ORDER BY product.product_id DESC
END @IF
@@ -1089,7 +1089,7 @@
SELECT count(*) FROM (
- @SQL_COUNT(products.product_id, product) -- this takes previous query removes limit and replaces select columns with parameter product_id
+ @SQL_COUNT(product.product_id, product) -- this takes previous query removes limit and replaces select columns with parameter product_id
) as count;
diff --git a/admin/sql/pgsql/product_attribute.sql b/admin/sql/pgsql/product_attribute.sql
index fcf4954..f7ac07d 100755
--- a/admin/sql/pgsql/product_attribute.sql
+++ b/admin/sql/pgsql/product_attribute.sql
@@ -12,7 +12,7 @@
BEGIN
-- product_attribute
SELECT product_attribute.*
- FROM product_attribute AS product_attribute
+ FROM product_attribute
WHERE 1 = 1
diff --git a/admin/sql/pgsql/product_content_revision.sql b/admin/sql/pgsql/product_content_revision.sql
index 1c4e99c..1747262 100644
--- a/admin/sql/pgsql/product_content_revision.sql
+++ b/admin/sql/pgsql/product_content_revision.sql
@@ -14,34 +14,34 @@
)
BEGIN
-- product_content_revision
- SELECT revision.product_id, revision.language_id, revision.created_at, revision.admin_id, admin.display_name, admin.username
+ SELECT product_content_revision.product_id, product_content_revision.language_id, product_content_revision.created_at, product_content_revision.admin_id, admin.display_name, admin.username
@IF !empty(:content)
THEN
,content
END @IF
- FROM product_content_revision AS revision
- LEFT JOIN admin ON (admin.admin_id = revision.admin_id)
+ FROM product_content_revision
+ LEFT JOIN admin ON (admin.admin_id = product_content_revision.admin_id)
WHERE 1 = 1
@IF !empty(:product_id)
THEN
- AND revision.product_id = :product_id
+ AND product_content_revision.product_id = :product_id
END @IF
@IF !empty(:language_id)
THEN
- AND revision.language_id = :language_id
+ AND product_content_revision.language_id = :language_id
END @IF
@IF !empty(:created_at)
THEN
- AND revision.created_at = :created_at
+ AND product_content_revision.created_at = :created_at
END @IF
- ORDER BY revision.created_at DESC
+ ORDER BY product_content_revision.created_at DESC
@IF !empty(:limit)
THEN
@@ -51,7 +51,7 @@
SELECT count(*) FROM (
- @SQL_COUNT(revision.product_id, product_content_revision) -- this takes previous query removes limit and replaces select columns with parameter product_id
+ @SQL_COUNT(product_content_revision.product_id, product_content_revision) -- this takes previous query removes limit and replaces select columns with parameter product_id
) as count;
diff --git a/admin/sql/pgsql/product_option.sql b/admin/sql/pgsql/product_option.sql
index f59c2aa..867006e 100755
--- a/admin/sql/pgsql/product_option.sql
+++ b/admin/sql/pgsql/product_option.sql
@@ -13,7 +13,7 @@
BEGIN
-- product_option
SELECT product_option.*, oc.name, "option".type, product_option.product_option_id as array_key
- FROM product_option AS product_option
+ FROM product_option
INNER JOIN "option" ON "option".option_id = product_option.option_id
INNER JOIN option_content oc ON oc.option_id = product_option.option_id AND oc.language_id = :language_id
diff --git a/admin/sql/pgsql/product_option_value.sql b/admin/sql/pgsql/product_option_value.sql
index ad07329..c84ab1b 100644
--- a/admin/sql/pgsql/product_option_value.sql
+++ b/admin/sql/pgsql/product_option_value.sql
@@ -17,7 +17,7 @@
SELECT product_option_value.*,
option_value.image, ovc.name, oc.name as "option",
product_option_value.product_option_value_id as array_key
- FROM product_option_value AS product_option_value
+ FROM product_option_value
INNER JOIN option_value ON option_value.option_value_id = product_option_value.option_value_id
INNER JOIN option_value_content ovc ON ovc.option_value_id = product_option_value.option_value_id AND ovc.language_id = :language_id
INNER JOIN option_content oc ON oc.option_id = product_option_value.option_id AND oc.language_id = :language_id
diff --git a/admin/sql/pgsql/product_question.sql b/admin/sql/pgsql/product_question.sql
index 9a3bb1c..2a6f2ce 100755
--- a/admin/sql/pgsql/product_question.sql
+++ b/admin/sql/pgsql/product_question.sql
@@ -19,7 +19,7 @@
BEGIN
SELECT "user".username, "user".email, "user".first_name, "user".last_name, "user".display_name, "user".avatar, "user".bio, "user".subscribe, product_question.*, "user".user_id as user_id
- FROM product_question AS product_question
+ FROM product_question
LEFT JOIN "user" on "user".user_id = product_question.user_id
WHERE 1 = 1
diff --git a/admin/sql/pgsql/product_subscription.sql b/admin/sql/pgsql/product_subscription.sql
index 2f29401..50a1ca3 100644
--- a/admin/sql/pgsql/product_subscription.sql
+++ b/admin/sql/pgsql/product_subscription.sql
@@ -24,7 +24,7 @@
product_subscription.price,
product_subscription.trial_price
- FROM product_subscription AS product_subscription
+ FROM product_subscription
-- product_id
@IF isset(:product_id)
diff --git a/admin/sql/pgsql/region.sql b/admin/sql/pgsql/region.sql
index 9a35008..44460b1 100755
--- a/admin/sql/pgsql/region.sql
+++ b/admin/sql/pgsql/region.sql
@@ -14,7 +14,7 @@
BEGIN
-- region
SELECT country.name as country,region.*
- FROM region AS region
+ FROM region
LEFT JOIN country ON country.country_id = region.country_id
WHERE 1 = 1
diff --git a/admin/sql/pgsql/region_group.sql b/admin/sql/pgsql/region_group.sql
index ee248d2..0839c38 100755
--- a/admin/sql/pgsql/region_group.sql
+++ b/admin/sql/pgsql/region_group.sql
@@ -12,7 +12,7 @@
BEGIN
-- region_group
SELECT *
- FROM region_group AS region_group WHERE 1 = 1
+ FROM region_group WHERE 1 = 1
@IF !empty(:limit)
THEN
diff --git a/admin/sql/pgsql/return.sql b/admin/sql/pgsql/return.sql
index 866fe15..e126008 100755
--- a/admin/sql/pgsql/return.sql
+++ b/admin/sql/pgsql/return.sql
@@ -12,7 +12,7 @@
BEGIN
-- return
SELECT return.*, return_resolution.name as return_resolution, return_reason.name as return_reason, return_status.name as return_status
- FROM return AS return
+ FROM return
INNER JOIN return_resolution ON return_resolution.return_resolution_id = return.return_resolution_id AND return_resolution.language_id = :language_id
INNER JOIN return_reason ON return_reason.return_reason_id = return.return_reason_id AND return_reason.language_id = :language_id
INNER JOIN return_status ON return_status.return_status_id = return.return_status_id AND return_status.language_id = :language_id
diff --git a/admin/sql/pgsql/return_reason.sql b/admin/sql/pgsql/return_reason.sql
index 9583a96..fabe20a 100755
--- a/admin/sql/pgsql/return_reason.sql
+++ b/admin/sql/pgsql/return_reason.sql
@@ -12,7 +12,7 @@
BEGIN
-- return_reason
SELECT *
- FROM return_reason AS return_reason WHERE 1 = 1
+ FROM return_reason WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/pgsql/return_resolution.sql b/admin/sql/pgsql/return_resolution.sql
index 639ced6..cc32a8b 100755
--- a/admin/sql/pgsql/return_resolution.sql
+++ b/admin/sql/pgsql/return_resolution.sql
@@ -12,7 +12,7 @@
BEGIN
-- return resolution
SELECT *
- FROM return_resolution AS return_resolution WHERE 1 = 1
+ FROM return_resolution WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/pgsql/return_status.sql b/admin/sql/pgsql/return_status.sql
index cc1f32a..b4762fa 100755
--- a/admin/sql/pgsql/return_status.sql
+++ b/admin/sql/pgsql/return_status.sql
@@ -12,7 +12,7 @@
BEGIN
-- return_status
SELECT *
- FROM return_status AS return_status WHERE 1 = 1
+ FROM return_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/pgsql/shipping_status.sql b/admin/sql/pgsql/shipping_status.sql
index 1db6624..abf7cc6 100644
--- a/admin/sql/pgsql/shipping_status.sql
+++ b/admin/sql/pgsql/shipping_status.sql
@@ -11,7 +11,7 @@
)
BEGIN
SELECT *
- FROM shipping_status AS shipping_status WHERE 1 = 1
+ FROM shipping_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/pgsql/site.sql b/admin/sql/pgsql/site.sql
index 6da9497..74333f9 100755
--- a/admin/sql/pgsql/site.sql
+++ b/admin/sql/pgsql/site.sql
@@ -15,14 +15,14 @@
BEGIN
-- site
SELECT *, site_id as array_key
- FROM site as sites
+ FROM site
WHERE 1 = 1
-- site_id
@IF isset(:site_id) && !empty(:site_id)
THEN
- AND sites.site_id IN (:site_id)
+ AND site.site_id IN (:site_id)
END @IF
-- limit
@@ -34,7 +34,7 @@
-- SELECT FOUND_ROWS() as count;
SELECT count(*) FROM (
- @SQL_COUNT(sites.site_id, site) -- this takes previous query removes limit and replaces select columns with parameter product_id
+ @SQL_COUNT(site.site_id, site) -- this takes previous query removes limit and replaces select columns with parameter product_id
) as count;
END
diff --git a/admin/sql/pgsql/stock_status.sql b/admin/sql/pgsql/stock_status.sql
index c8949ea..a3e62ff 100755
--- a/admin/sql/pgsql/stock_status.sql
+++ b/admin/sql/pgsql/stock_status.sql
@@ -12,7 +12,7 @@
BEGIN
-- stock_status
SELECT *
- FROM stock_status AS stock_status WHERE 1 = 1
+ FROM stock_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/pgsql/subscription.sql b/admin/sql/pgsql/subscription.sql
index f225d30..29c7302 100755
--- a/admin/sql/pgsql/subscription.sql
+++ b/admin/sql/pgsql/subscription.sql
@@ -12,7 +12,7 @@
BEGIN
-- subscription
SELECT *
- FROM subscription AS subscription WHERE 1 = 1
+ FROM subscription WHERE 1 = 1
-- limit
@IF isset(:limit)
diff --git a/admin/sql/pgsql/subscription_plan.sql b/admin/sql/pgsql/subscription_plan.sql
index 136b35b..749670c 100755
--- a/admin/sql/pgsql/subscription_plan.sql
+++ b/admin/sql/pgsql/subscription_plan.sql
@@ -13,7 +13,7 @@
BEGIN
-- subscription_plan
SELECT subscription_plan.*,subscription_plan_content.name,subscription_plan.subscription_plan_id as array_key
- FROM subscription_plan AS subscription_plan
+ FROM subscription_plan
INNER JOIN subscription_plan_content ON subscription_plan_content.subscription_plan_id = subscription_plan.subscription_plan_id
AND subscription_plan_content.language_id = :language_id
WHERE 1 = 1
diff --git a/admin/sql/pgsql/subscription_status.sql b/admin/sql/pgsql/subscription_status.sql
index d061427..2e6390c 100755
--- a/admin/sql/pgsql/subscription_status.sql
+++ b/admin/sql/pgsql/subscription_status.sql
@@ -12,7 +12,7 @@
BEGIN
-- subscription_status
SELECT *
- FROM subscription_status AS subscription_status WHERE 1 = 1
+ FROM subscription_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/pgsql/tax_rate.sql b/admin/sql/pgsql/tax_rate.sql
index 6c8f88f..e198872 100755
--- a/admin/sql/pgsql/tax_rate.sql
+++ b/admin/sql/pgsql/tax_rate.sql
@@ -12,7 +12,7 @@
BEGIN
-- tax_rate
SELECT *
- FROM tax_rate AS tax_rate WHERE 1 = 1
+ FROM tax_rate WHERE 1 = 1
@IF !empty(:limit)
diff --git a/admin/sql/pgsql/tax_rule.sql b/admin/sql/pgsql/tax_rule.sql
index 146e390..5cac870 100755
--- a/admin/sql/pgsql/tax_rule.sql
+++ b/admin/sql/pgsql/tax_rule.sql
@@ -12,7 +12,7 @@
BEGIN
-- tax_rule
SELECT *
- FROM tax_rule AS tax_rule WHERE 1 = 1
+ FROM tax_rule WHERE 1 = 1
@IF !empty(:tax_type_id)
diff --git a/admin/sql/pgsql/tax_type.sql b/admin/sql/pgsql/tax_type.sql
index 879b976..1e5faaa 100755
--- a/admin/sql/pgsql/tax_type.sql
+++ b/admin/sql/pgsql/tax_type.sql
@@ -12,7 +12,7 @@
BEGIN
-- tax_type
SELECT *
- FROM tax_type AS tax_type WHERE 1 = 1
+ FROM tax_type WHERE 1 = 1
@SQL_LIMIT(:start, :limit);
diff --git a/admin/sql/pgsql/taxonomy.sql b/admin/sql/pgsql/taxonomy.sql
index b57b372..2d59173 100755
--- a/admin/sql/pgsql/taxonomy.sql
+++ b/admin/sql/pgsql/taxonomy.sql
@@ -19,7 +19,7 @@
BEGIN
-- taxonomy_item
SELECT *, taxonomy_id as array_key
- FROM taxonomy as taxonomy
+ FROM taxonomy
-- LEFT JOIN taxonomy_to_site t2s ON (taxonomy_item.taxonomy_item_id = t2s.taxonomy_item_id)
WHERE 1 = 1
diff --git a/admin/sql/pgsql/user.sql b/admin/sql/pgsql/user.sql
index 69ebf64..3d3d9b8 100755
--- a/admin/sql/pgsql/user.sql
+++ b/admin/sql/pgsql/user.sql
@@ -3,13 +3,17 @@
-- get all entries
CREATE PROCEDURE getAll(
- IN start INT,
- IN limit INT,
IN status INT,
IN search CHAR,
IN email CHAR,
IN phone_number CHAR,
+ -- pagination
+ IN start INT,
+ IN limit INT,
+ IN order_by CHAR,
+ IN direction CHAR,
+
-- return array of user
OUT fetch_all,
-- return user count for count query
@@ -43,6 +47,13 @@
"user".last_name LIKE '%' || :search || '%'
END @IF
+ -- 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
+ @ELSE
+ ORDER BY "user".user_id DESC
+ END @IF
-- limit
@IF isset(:limit)
diff --git a/admin/sql/pgsql/user_address.sql b/admin/sql/pgsql/user_address.sql
index 566c117..ea7473c 100755
--- a/admin/sql/pgsql/user_address.sql
+++ b/admin/sql/pgsql/user_address.sql
@@ -19,7 +19,7 @@
SELECT *
- FROM user_address AS user_address
+ FROM user_address
WHERE 1 = 1
-- user
diff --git a/admin/sql/pgsql/user_group.sql b/admin/sql/pgsql/user_group.sql
index 30e60dd..82ab547 100755
--- a/admin/sql/pgsql/user_group.sql
+++ b/admin/sql/pgsql/user_group.sql
@@ -12,7 +12,7 @@
BEGIN
-- user_group
SELECT user_group.*,user_group_content.name, user_group_content.content, user_group_content.language_id
- FROM user_group AS user_group
+ FROM user_group
INNER JOIN user_group_content ON user_group_content.user_group_id = user_group.user_group_id
WHERE 1 = 1
diff --git a/admin/sql/pgsql/vendor.sql b/admin/sql/pgsql/vendor.sql
index 27b7aa9..76a63a7 100755
--- a/admin/sql/pgsql/vendor.sql
+++ b/admin/sql/pgsql/vendor.sql
@@ -107,7 +107,7 @@
)
BEGIN
- SELECT * FROM vendor AS vendor
+ SELECT * FROM vendor
LEFT JOIN vendor_to_site p2s ON (vendor.vendor_id = p2s.vendor_id)
WHERE p2s.site_id = :site_id
diff --git a/admin/sql/pgsql/voucher.sql b/admin/sql/pgsql/voucher.sql
index 689ce35..2dcb2f2 100755
--- a/admin/sql/pgsql/voucher.sql
+++ b/admin/sql/pgsql/voucher.sql
@@ -12,7 +12,7 @@
BEGIN
-- voucher
SELECT *
- FROM voucher AS voucher WHERE 1 = 1
+ FROM voucher WHERE 1 = 1
@SQL_LIMIT(:start, :limit);
diff --git a/admin/sql/pgsql/weight_type.sql b/admin/sql/pgsql/weight_type.sql
index 8a6efc6..be3d1d8 100755
--- a/admin/sql/pgsql/weight_type.sql
+++ b/admin/sql/pgsql/weight_type.sql
@@ -12,7 +12,7 @@
BEGIN
-- weight_type
SELECT *, weight_type.weight_type_id as array_key
- FROM weight_type AS weight_type
+ FROM weight_type
INNER JOIN weight_type_content ON weight_type_content.weight_type_id = weight_type.weight_type_id
WHERE 1 = 1
diff --git a/admin/sql/sqlite/admin.sql b/admin/sql/sqlite/admin.sql
index 5a62b10..5282aee 100755
--- a/admin/sql/sqlite/admin.sql
+++ b/admin/sql/sqlite/admin.sql
@@ -17,7 +17,7 @@
)
BEGIN
- SELECT * FROM admin AS admin WHERE 1 = 1
+ SELECT * FROM admin WHERE 1 = 1
@IF isset(:status) AND !empty(:status)
diff --git a/admin/sql/sqlite/attribute.sql b/admin/sql/sqlite/attribute.sql
index d741f93..6258985 100755
--- a/admin/sql/sqlite/attribute.sql
+++ b/admin/sql/sqlite/attribute.sql
@@ -20,7 +20,7 @@
,pa.value
END @IF
- FROM attribute AS attribute
+ FROM attribute
INNER JOIN attribute_content
ON attribute_content.attribute_id = attribute.attribute_id AND attribute_content.language_id = :language_id
INNER JOIN attribute_group_content
diff --git a/admin/sql/sqlite/attribute_group.sql b/admin/sql/sqlite/attribute_group.sql
index f42cb70..8924fa5 100755
--- a/admin/sql/sqlite/attribute_group.sql
+++ b/admin/sql/sqlite/attribute_group.sql
@@ -18,7 +18,7 @@
,pa.value
END @IF
- FROM attribute_group AS attribute_group
+ FROM attribute_group
INNER JOIN attribute_group_content
ON attribute_group_content.attribute_group_id = attribute_group.attribute_group_id AND attribute_group_content.language_id = :language_id
diff --git a/admin/sql/sqlite/comment.sql b/admin/sql/sqlite/comment.sql
index 7ddc58e..3c1958b 100755
--- a/admin/sql/sqlite/comment.sql
+++ b/admin/sql/sqlite/comment.sql
@@ -29,7 +29,7 @@
,post_content.name, post_content.slug
END @IF
- FROM comment AS comment
+ FROM comment
LEFT JOIN user ON (user.user_id = comment.user_id)
@IF isset(:post_title) AND :post_title
diff --git a/admin/sql/sqlite/country.sql b/admin/sql/sqlite/country.sql
index ff294f6..7660479 100755
--- a/admin/sql/sqlite/country.sql
+++ b/admin/sql/sqlite/country.sql
@@ -13,7 +13,7 @@
BEGIN
-- country
SELECT *
- FROM country AS country WHERE 1 = 1
+ FROM country WHERE 1 = 1
@IF isset(:status) AND :status != ""
THEN
diff --git a/admin/sql/sqlite/coupon.sql b/admin/sql/sqlite/coupon.sql
index 3a53f4d..321f159 100755
--- a/admin/sql/sqlite/coupon.sql
+++ b/admin/sql/sqlite/coupon.sql
@@ -12,7 +12,7 @@
BEGIN
-- coupon
SELECT *
- FROM coupon AS coupon WHERE 1 = 1
+ FROM coupon WHERE 1 = 1
@SQL_LIMIT(:start, :limit);
diff --git a/admin/sql/sqlite/currency.sql b/admin/sql/sqlite/currency.sql
index aa64b30..de14f5e 100755
--- a/admin/sql/sqlite/currency.sql
+++ b/admin/sql/sqlite/currency.sql
@@ -11,7 +11,7 @@
BEGIN
-- currency
SELECT *, code as array_key
- FROM currency as currency WHERE 1 = 1
+ FROM currency WHERE 1 = 1
@IF isset(:status) AND :status != ""
THEN
diff --git a/admin/sql/sqlite/digital_asset.sql b/admin/sql/sqlite/digital_asset.sql
index b53679e..f3eb588 100755
--- a/admin/sql/sqlite/digital_asset.sql
+++ b/admin/sql/sqlite/digital_asset.sql
@@ -21,7 +21,7 @@
, o.customer_order_id, o.order_id, op.name as product_name
END @IF
- FROM digital_asset AS digital_asset
+ FROM digital_asset
INNER JOIN digital_asset_content ON digital_asset_content.digital_asset_id = digital_asset.digital_asset_id
AND digital_asset_content.language_id = :language_id
diff --git a/admin/sql/sqlite/digital_asset_log.sql b/admin/sql/sqlite/digital_asset_log.sql
index 91d7eb3..0c6e8bf 100644
--- a/admin/sql/sqlite/digital_asset_log.sql
+++ b/admin/sql/sqlite/digital_asset_log.sql
@@ -13,7 +13,7 @@
SELECT digital_asset_log.*
- FROM digital_asset_log AS digital_asset_log
+ FROM digital_asset_log
WHERE 1 = 1
diff --git a/admin/sql/sqlite/field.sql b/admin/sql/sqlite/field.sql
index cf8b819..c90e913 100755
--- a/admin/sql/sqlite/field.sql
+++ b/admin/sql/sqlite/field.sql
@@ -18,7 +18,7 @@
BEGIN
-- field_item
SELECT *, field_id as array_key
- FROM field as field
+ FROM field
-- LEFT JOIN field_to_site t2s ON (field_item.field_item_id = t2s.field_item_id)
WHERE 1 = 1
diff --git a/admin/sql/sqlite/field_group.sql b/admin/sql/sqlite/field_group.sql
index 8a18f95..0ba2eed 100755
--- a/admin/sql/sqlite/field_group.sql
+++ b/admin/sql/sqlite/field_group.sql
@@ -12,7 +12,7 @@
BEGIN
-- field_group
SELECT *
- FROM field_group AS field_group
+ FROM field_group
INNER JOIN field_group_content ON field_group_content.field_group_id = field_group.field_group_id
WHERE 1 = 1
diff --git a/admin/sql/sqlite/language.sql b/admin/sql/sqlite/language.sql
index 603ce0c..a2ce384 100755
--- a/admin/sql/sqlite/language.sql
+++ b/admin/sql/sqlite/language.sql
@@ -13,7 +13,7 @@
BEGIN
-- language
SELECT *, code as array_key
- FROM language as language WHERE 1 = 1
+ FROM language WHERE 1 = 1
@IF isset(:status)
THEN
diff --git a/admin/sql/sqlite/length_type.sql b/admin/sql/sqlite/length_type.sql
index 31146de..82bf858 100755
--- a/admin/sql/sqlite/length_type.sql
+++ b/admin/sql/sqlite/length_type.sql
@@ -12,7 +12,7 @@
BEGIN
-- length_type
SELECT *, length_type.length_type_id as array_key
- FROM length_type AS length_type
+ FROM length_type
INNER JOIN length_type_content ON length_type_content.length_type_id = length_type.length_type_id
WHERE 1 = 1
diff --git a/admin/sql/sqlite/manufacturer.sql b/admin/sql/sqlite/manufacturer.sql
index e512196..d0d96a9 100755
--- a/admin/sql/sqlite/manufacturer.sql
+++ b/admin/sql/sqlite/manufacturer.sql
@@ -109,7 +109,7 @@
)
BEGIN
- SELECT * FROM manufacturer AS manufacturer
+ SELECT * FROM manufacturer
LEFT JOIN manufacturer_to_site p2s ON (manufacturer.manufacturer_id = p2s.manufacturer_id)
WHERE p2s.site_id = :site_id
diff --git a/admin/sql/sqlite/menu.sql b/admin/sql/sqlite/menu.sql
index 732bcc4..0c695be 100755
--- a/admin/sql/sqlite/menu.sql
+++ b/admin/sql/sqlite/menu.sql
@@ -90,7 +90,7 @@
-- get all menus
- CREATE PROCEDURE getMenusList(
+ CREATE PROCEDURE getAll(
-- variables
IN language_id INT,
@@ -113,7 +113,7 @@
SELECT *, menu.menu_id as array_key
- FROM menu AS menu
+ FROM menu
@SQL_LIMIT(:start, :limit);
@@ -125,12 +125,12 @@
) as count;
- END -- get all menus
+ END
- -- get all menus
+ -- get menu
- CREATE PROCEDURE getMenus(
+ CREATE PROCEDURE get(
-- variables
IN language_id INT,
@@ -150,13 +150,13 @@
)
BEGIN
- SELECT td.*,menus.url, menus.sort_order, menus.parent_id, menus.type, menus.item_id, menus.menu_item_id as array_key
+ SELECT td.*,menu.url, menu.sort_order, menu.parent_id, menu.type, menu.item_id, menu.menu_item_id as array_key
- FROM menu_item AS menus
+ FROM menu_item AS menu
- -- INNER JOIN menu_to_site c2s ON (menus.menu_id = c2s.menu_id AND c2s.site_id = :site_id)
- INNER JOIN menu_item_content td ON (menus.menu_item_id = td.menu_item_id AND td.language_id = :language_id)
+ -- INNER JOIN menu_to_site c2s ON (menu.menu_id = c2s.menu_id AND c2s.site_id = :site_id)
+ INNER JOIN menu_item_content td ON (menu.menu_item_id = td.menu_item_id AND td.language_id = :language_id)
WHERE
@@ -166,18 +166,18 @@
@IF isset(:menu_id)
THEN
- AND menus.menu_id = :menu_id
+ AND menu.menu_id = :menu_id
END @IF
@IF isset(:slug)
THEN
- AND menus.menu_id = (SELECT menu_id FROM menu WHERE slug = :slug LIMIT 1)
+ AND menu.menu_id = (SELECT menu_id FROM menu WHERE slug = :slug LIMIT 1)
END @IF
- ORDER BY menus.parent_id, menus.sort_order, menus.menu_id
+ ORDER BY menu.parent_id, menu.sort_order, menu.menu_id
@IF isset(:limit)
THEN
diff --git a/admin/sql/sqlite/option.sql b/admin/sql/sqlite/option.sql
index 98e579b..1cb8a97 100644
--- a/admin/sql/sqlite/option.sql
+++ b/admin/sql/sqlite/option.sql
@@ -12,7 +12,7 @@
BEGIN
-- option
SELECT `option`.*, option_content.name
- FROM `option` AS `option`
+ FROM `option`
INNER JOIN option_content
ON option_content.option_id = `option`.option_id AND option_content.language_id = :language_id
diff --git a/admin/sql/sqlite/option_value.sql b/admin/sql/sqlite/option_value.sql
index f34eb7e..fa487cb 100644
--- a/admin/sql/sqlite/option_value.sql
+++ b/admin/sql/sqlite/option_value.sql
@@ -13,7 +13,7 @@
BEGIN
-- option_value
SELECT option_value.*, option_value_content.name
- FROM option_value AS option_value
+ FROM option_value
INNER JOIN option_value_content
ON option_value_content.option_value_id = option_value.option_value_id AND option_value_content.language_id = :language_id
diff --git a/admin/sql/sqlite/order.sql b/admin/sql/sqlite/order.sql
index cf5a4e2..2260c12 100755
--- a/admin/sql/sqlite/order.sql
+++ b/admin/sql/sqlite/order.sql
@@ -24,6 +24,8 @@
-- pagination
IN start INT,
IN limit INT,
+ IN order_by CHAR,
+ IN direction CHAR,
-- return
@@ -95,7 +97,13 @@
`order`.last_name LIKE '%' || :search || '%'
END @IF
- ORDER BY order_id DESC
+ -- 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
+ @ELSE
+ ORDER BY order_id DESC
+ END @IF
@SQL_LIMIT(:start, :limit);
diff --git a/admin/sql/sqlite/order_log.sql b/admin/sql/sqlite/order_log.sql
index 6814bd9..2f9f396 100644
--- a/admin/sql/sqlite/order_log.sql
+++ b/admin/sql/sqlite/order_log.sql
@@ -12,7 +12,7 @@
BEGIN
-- order_log
SELECT *
- FROM order_log AS order_log WHERE 1 = 1
+ FROM order_log WHERE 1 = 1
@IF !empty(:order_id)
THEN
diff --git a/admin/sql/sqlite/order_status.sql b/admin/sql/sqlite/order_status.sql
index 29d956d..51a00b2 100755
--- a/admin/sql/sqlite/order_status.sql
+++ b/admin/sql/sqlite/order_status.sql
@@ -11,7 +11,7 @@
)
BEGIN
SELECT *
- FROM order_status AS order_status WHERE 1 = 1
+ FROM order_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/sqlite/payment_status.sql b/admin/sql/sqlite/payment_status.sql
index 98449b5..98333a9 100644
--- a/admin/sql/sqlite/payment_status.sql
+++ b/admin/sql/sqlite/payment_status.sql
@@ -12,7 +12,7 @@
BEGIN
SELECT *
- FROM payment_status AS payment_status WHERE 1 = 1
+ FROM payment_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/sqlite/post.sql b/admin/sql/sqlite/post.sql
index 0b108fc..0cc7ddc 100755
--- a/admin/sql/sqlite/post.sql
+++ b/admin/sql/sqlite/post.sql
@@ -28,6 +28,9 @@
IN tags INT,
IN taxonomy CHAR,
+ IN order_by CHAR,
+ IN direction CHAR,
+
-- return array of posts for posts query
OUT fetch_all,
-- return posts count for count query
@@ -35,13 +38,13 @@
)
BEGIN
- SELECT pd.*,posts.*,ad.username,ad.display_name,ad.admin_id,ad.email, ad.avatar, ad.bio, ad.first_name, ad.last_name
+ SELECT pd.*,post.*,ad.username,ad.display_name,ad.admin_id,ad.email, ad.avatar, ad.bio, ad.first_name, ad.last_name
@IF isset(:comment_count)
THEN
,(SELECT COUNT(c.comment_id)
FROM comment c
WHERE
- posts.post_id = c.post_id
+ post.post_id = c.post_id
@IF isset(:comment_status)
THEN
@@ -53,9 +56,9 @@
END @IF
- FROM post AS posts
+ FROM post
LEFT JOIN post_content pd ON (
- posts.post_id = pd.post_id
+ post.post_id = pd.post_id
@IF isset(:language_id)
THEN
@@ -63,12 +66,12 @@
END @IF
)
- LEFT JOIN post_to_site ps ON (posts.post_id = ps.post_id)
- LEFT JOIN admin ad ON (posts.admin_id = ad.admin_id)
+ LEFT JOIN post_to_site ps ON (post.post_id = ps.post_id)
+ LEFT JOIN admin ad ON (post.admin_id = ad.admin_id)
@IF isset(:taxonomy_item_id) || isset(:taxonomy_item_slug)
THEN
- LEFT JOIN post_to_taxonomy_item pt ON (posts.post_id = pt.post_id)
+ LEFT JOIN post_to_taxonomy_item pt ON (post.post_id = pt.post_id)
END @IF
@IF isset(:search)
@@ -79,26 +82,26 @@
@IF isset(:type) && !empty(:type)
THEN
- AND posts.type = :type
+ AND post.type = :type
END @IF
@IF isset(:status) && !empty(:status)
THEN
- AND posts.status = :status
+ AND post.status = :status
@ELSE
- AND posts.status = 'publish'
+ AND post.status = 'publish'
END @IF
-- username/author
@IF isset(:username)
THEN
- AND posts.admin_id = (SELECT admin_id FROM admin WHERE username = :username LIMIT 1)
+ AND post.admin_id = (SELECT admin_id FROM admin WHERE username = :username LIMIT 1)
END @IF
-- admin_id
@IF isset(:admin_id)
THEN
- AND posts.admin_id = :admin_id
+ AND post.admin_id = :admin_id
END @IF
-- search
@@ -120,7 +123,7 @@
@IF isset(:post_id) && count(:post_id) > 0
THEN
- AND posts.post_id IN (:post_id)
+ AND post.post_id IN (:post_id)
END @IF
@@ -150,21 +153,21 @@
-- month
@IF isset(:month) && !empty(:month)
THEN
- AND strftime('%M', posts.created_at) = :month
+ AND strftime('%M', post.created_at) = :month
END @IF
-- year
@IF isset(:year) && !empty(:year)
THEN
- AND strftime('%Y', posts.created_at) = :year
+ AND strftime('%Y', post.created_at) = :year
END @IF
- -- order by
+ -- 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 posts.$order_by $direction
+ ORDER BY post.$order_by $direction
@ELSE
- ORDER BY posts.post_id DESC
+ ORDER BY post.post_id DESC
END @IF
-- limit
@@ -177,7 +180,7 @@
-- SELECT FOUND_ROWS() as count;
SELECT count(*) FROM (
- @SQL_COUNT(posts.post_id, post) -- this takes previous query removes limit and replaces select columns with parameter product_id
+ @SQL_COUNT(post.post_id, post) -- this takes previous query removes limit and replaces select columns with parameter product_id
) as count;
@@ -259,7 +262,7 @@
-- content
SELECT *, language_id as array_key -- (underscore) _ column means that this column (language_id) value will be used as array key when adding row to result array
- FROM post_content AS post_content
+ FROM post_content
WHERE post_id = @result.post_id;
diff --git a/admin/sql/sqlite/post_content_revision.sql b/admin/sql/sqlite/post_content_revision.sql
index 77df20b..7e66382 100644
--- a/admin/sql/sqlite/post_content_revision.sql
+++ b/admin/sql/sqlite/post_content_revision.sql
@@ -14,34 +14,34 @@
)
BEGIN
-- post_content_revision
- SELECT revision.post_id, revision.language_id, revision.created_at, revision.admin_id, admin.display_name, admin.username
+ SELECT post_content_revision.post_id, post_content_revision.language_id, post_content_revision.created_at, post_content_revision.admin_id, admin.display_name, admin.username
@IF !empty(:content)
THEN
,content
END @IF
- FROM post_content_revision AS revision
- LEFT JOIN admin ON (admin.admin_id = revision.admin_id)
+ FROM post_content_revision
+ LEFT JOIN admin ON (admin.admin_id = post_content_revision.admin_id)
WHERE 1 = 1
@IF !empty(:post_id)
THEN
- AND revision.post_id = :post_id
+ AND post_content_revision.post_id = :post_id
END @IF
@IF !empty(:language_id)
THEN
- AND revision.language_id = :language_id
+ AND post_content_revision.language_id = :language_id
END @IF
@IF !empty(:created_at)
THEN
- AND revision.created_at = :created_at
+ AND post_content_revision.created_at = :created_at
END @IF
- ORDER BY revision.created_at DESC
+ ORDER BY post_content_revision.created_at DESC
@IF !empty(:limit)
THEN
@@ -51,7 +51,7 @@
SELECT count(*) FROM (
- @SQL_COUNT(revision.post_id, post_content_revision) -- this takes previous query removes limit and replaces select columns with parameter product_id
+ @SQL_COUNT(post_content_revision.post_id, post_content_revision) -- this takes previous query removes limit and replaces select columns with parameter product_id
) as count;
diff --git a/admin/sql/sqlite/product.sql b/admin/sql/sqlite/product.sql
index 8c1b5b6..d0f33ef 100755
--- a/admin/sql/sqlite/product.sql
+++ b/admin/sql/sqlite/product.sql
@@ -346,13 +346,13 @@
user_group.user_group_id as array_key, -- stock_status_id as key
name as array_value -- name as value
- FROM user_group as user_group
+ FROM user_group
INNER JOIN user_group_content ON user_group_content.user_group_id = user_group.user_group_id;
-- subscription plan
SELECT subscription_plan.subscription_plan_id as array_key,
subscription_plan_content.name as array_value
- FROM subscription_plan AS subscription_plan
+ FROM subscription_plan
INNER JOIN subscription_plan_content ON subscription_plan_content.subscription_plan_id = subscription_plan.subscription_plan_id
AND subscription_plan_content.language_id = :language_id
-- LIMIT 100
@@ -362,7 +362,7 @@
`option`.option_id as array_key, -- option_id as key
option_content.name,
`option`.type
- FROM `option` AS `option`
+ FROM `option`
INNER JOIN option_content
ON option_content.option_id = `option`.option_id AND option_content.language_id = :language_id
-- LIMIT 100
@@ -779,7 +779,7 @@
)
BEGIN
- SELECT pd.*,products.*, products.product_id as array_key
+ SELECT pd.*,product.*, product.product_id as array_key
@IF !empty(:manufacturer)
THEN
@@ -792,8 +792,8 @@
@IF !empty(:product_image)
THEN
-- uncomment the group concat version if you are using an older sqlite version
- -- ,(SELECT '[' || GROUP_CONCAT('{"id":"' || pi.product_image_id || '","image":"' || pi.image || '"}') || ']' FROM product_image as pi WHERE pi.product_id = products.product_id GROUP BY pi.product_id) as images
- ,(SELECT json_group_array(json_object('id',pi.product_image_id,'image',pi.image)) FROM product_image as pi WHERE pi.product_id = products.product_id GROUP BY pi.product_id) as images
+ -- ,(SELECT '[' || GROUP_CONCAT('{"id":"' || pi.product_image_id || '","image":"' || pi.image || '"}') || ']' FROM product_image as pi WHERE pi.product_id = product.product_id GROUP BY pi.product_id) as images
+ ,(SELECT json_group_array(json_object('id',pi.product_image_id,'image',pi.image)) FROM product_image as pi WHERE pi.product_id = product.product_id GROUP BY pi.product_id) as images
END @IF
-- include discount
@@ -802,7 +802,7 @@
,(SELECT price
FROM product_discount pd2
- WHERE pd2.product_id = products.product_id
+ WHERE pd2.product_id = product.product_id
AND pd2.user_group_id = :user_group_id
AND pd2.quantity = '1'
AND ((pd2.from_date = NULL
@@ -820,7 +820,7 @@
,(SELECT price
FROM product_promotion ps
- WHERE ps.product_id = products.product_id
+ WHERE ps.product_id = product.product_id
AND ps.user_group_id = :user_group_id
AND ((ps.from_date = NULL
OR ps.from_date < date('now'))
@@ -838,7 +838,7 @@
,(SELECT points
FROM product_points pp
- WHERE pp.product_id = products.product_id
+ WHERE pp.product_id = product.product_id
AND pp.user_group_id = :user_group_id
AS points
@@ -850,7 +850,7 @@
,(SELECT ss.name
FROM stock_status ss
- WHERE ss.stock_status_id = products.stock_status_id
+ WHERE ss.stock_status_id = product.stock_status_id
AND ss.language_id = :language_id)
AS stock_status
@@ -864,7 +864,7 @@
,(SELECT wcd.unit
FROM weight_type_content wcd
- WHERE products.weight_type_id = wcd.weight_type_id
+ WHERE product.weight_type_id = wcd.weight_type_id
AND wcd.language_id = :language_id)
AS weight_type
@@ -877,7 +877,7 @@
,(SELECT lcd.unit
FROM length_type_content lcd
- WHERE products.length_type_id = lcd.length_type_id
+ WHERE product.length_type_id = lcd.length_type_id
AND lcd.language_id = :language_id)
AS length_type
@@ -890,7 +890,7 @@
,(SELECT AVG(rating) AS total
FROM review r1
- WHERE r1.product_id = products.product_id
+ WHERE r1.product_id = product.product_id
AND r1.status = '1'
GROUP BY r1.product_id)
AS rating
@@ -904,18 +904,18 @@
,(SELECT COUNT(*) AS total
FROM review r2
- WHERE r2.product_id = products.product_id
+ WHERE r2.product_id = product.product_id
AND r2.status = '1'
GROUP BY r2.product_id) AS reviews
END @IF
- FROM product AS products
+ FROM product
- LEFT JOIN product_to_site p2s ON (products.product_id = p2s.product_id)
+ LEFT JOIN product_to_site p2s ON (product.product_id = p2s.product_id)
LEFT JOIN product_content pd ON (
- products.product_id = pd.product_id
+ product.product_id = pd.product_id
@IF isset(:language_id)
THEN
@@ -926,22 +926,22 @@
@IF !empty(:manufacturer)
THEN
- LEFT JOIN manufacturer m ON (products.manufacturer_id = m.manufacturer_id)
+ LEFT JOIN manufacturer m ON (product.manufacturer_id = m.manufacturer_id)
END @IF
@IF !empty(:taxonomy_item_id)
THEN
- INNER JOIN product_to_taxonomy_item pt ON (products.product_id = pt.product_id AND pt.taxonomy_item_id = :taxonomy_item_id)
+ INNER JOIN product_to_taxonomy_item pt ON (product.product_id = pt.product_id AND pt.taxonomy_item_id = :taxonomy_item_id)
END @IF
@IF !empty(:related)
THEN
- INNER JOIN product_related pr ON (pr.product_related_id = products.product_id)
+ INNER JOIN product_related pr ON (pr.product_related_id = product.product_id)
END @IF
@IF !empty(:variant)
THEN
- INNER JOIN product_variant pv ON (pv.product_variant_id = products.product_id)
+ INNER JOIN product_variant pv ON (pv.product_variant_id = product.product_id)
END @IF
@@ -971,75 +971,75 @@
@IF isset(:type) && !empty(:type)
THEN
- AND products.type = :type
+ AND product.type = :type
END @IF
@IF isset(:manufacturer_id) && !empty(:manufacturer_id)
THEN
- AND products.manufacturer_id IN (:manufacturer_id)
+ AND product.manufacturer_id IN (:manufacturer_id)
END @IF
@IF isset(:admin_id) && !empty(:admin_id)
THEN
- AND products.admin_id = :admin_id
+ AND product.admin_id = :admin_id
END @IF
@IF isset(:vendor_id) && !empty(:vendor_id)
THEN
- AND products.vendor_id IN (:vendor_id)
+ AND product.vendor_id IN (:vendor_id)
END @IF
@IF isset(:price) && :price !== ""
THEN
- AND products.price = :price
+ AND product.price = :price
END @IF
@IF isset(:quantity) && :quantity !== ""
THEN
- AND products.quantity = :quantity
+ AND product.quantity = :quantity
END @IF
@IF isset(:model) && :model !== ""
THEN
- AND products.model = :model
+ AND product.model = :model
END @IF
@IF isset(:sku) && :sku !== ""
THEN
- AND products.sku = :sku
+ AND product.sku = :sku
END @IF
@IF isset(:barcode) && :barcode !== ""
THEN
- AND products.barcode = :barcode
+ AND product.barcode = :barcode
END @IF
@IF isset(:upc) && :upc !== ""
THEN
- AND products.upc = :upc
+ AND product.upc = :upc
END @IF
@IF isset(:ean) && :ean !== ""
THEN
- AND products.ean = :ean
+ AND product.ean = :ean
END @IF
@IF isset(:isbn) && :isbn !== ""
THEN
- AND products.isbn = :isbn
+ AND product.isbn = :isbn
END @IF
@IF isset(:status) && :status !== ""
THEN
- AND products.status = :status
+ AND product.status = :status
END @IF
@IF isset(:product_id) && count(:product_id) > 0
THEN
- AND products.product_id IN (:product_id)
+ AND product.product_id IN (:product_id)
END @IF
@@ -1076,9 +1076,9 @@
-- 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 products.$order_by $direction
+ ORDER BY product.$order_by $direction
@ELSE
- ORDER BY products.product_id DESC
+ ORDER BY product.product_id DESC
END @IF
@@ -1091,7 +1091,7 @@
SELECT count(*) FROM (
- @SQL_COUNT(products.product_id, product) -- this takes previous query removes limit and replaces select columns with parameter product_id
+ @SQL_COUNT(product.product_id, product) -- this takes previous query removes limit and replaces select columns with parameter product_id
) as count;
diff --git a/admin/sql/sqlite/product_attribute.sql b/admin/sql/sqlite/product_attribute.sql
index 22331e7..68774de 100755
--- a/admin/sql/sqlite/product_attribute.sql
+++ b/admin/sql/sqlite/product_attribute.sql
@@ -12,7 +12,7 @@
BEGIN
-- product_attribute
SELECT product_attribute.*
- FROM product_attribute AS product_attribute
+ FROM product_attribute
WHERE 1 = 1
diff --git a/admin/sql/sqlite/product_content_revision.sql b/admin/sql/sqlite/product_content_revision.sql
index 1c4e99c..0f75ac1 100644
--- a/admin/sql/sqlite/product_content_revision.sql
+++ b/admin/sql/sqlite/product_content_revision.sql
@@ -14,34 +14,34 @@
)
BEGIN
-- product_content_revision
- SELECT revision.product_id, revision.language_id, revision.created_at, revision.admin_id, admin.display_name, admin.username
+ SELECT product_content_revision.product_id, product_content_revision.language_id, product_content_revision.created_at, product_content_revision.admin_id, admin.display_name, admin.username
@IF !empty(:content)
THEN
,content
END @IF
- FROM product_content_revision AS revision
- LEFT JOIN admin ON (admin.admin_id = revision.admin_id)
+ FROM product_content_revision
+ LEFT JOIN admin ON (admin.admin_id = product_content_revision.admin_id)
WHERE 1 = 1
@IF !empty(:product_id)
THEN
- AND revision.product_id = :product_id
+ AND product_content_revision.product_id = :product_id
END @IF
@IF !empty(:language_id)
THEN
- AND revision.language_id = :language_id
+ AND product_content_revision.language_id = :language_id
END @IF
@IF !empty(:created_at)
THEN
- AND revision.created_at = :created_at
+ AND product_content_revision.created_at = :created_at
END @IF
- ORDER BY revision.created_at DESC
+ ORDER BY product_content_revision.created_at DESC
@IF !empty(:limit)
THEN
@@ -51,9 +51,9 @@
SELECT count(*) FROM (
- @SQL_COUNT(revision.product_id, product_content_revision) -- this takes previous query removes limit and replaces select columns with parameter product_id
+ @SQL_COUNT(product_content_revision.product_id, product_content_revision) -- this takes previous query removes limit and replaces select columns with parameter product_id
- ) as count;
+ ) as count;
END
diff --git a/admin/sql/sqlite/product_option.sql b/admin/sql/sqlite/product_option.sql
index 982f469..a593ae6 100755
--- a/admin/sql/sqlite/product_option.sql
+++ b/admin/sql/sqlite/product_option.sql
@@ -13,7 +13,7 @@
BEGIN
-- product_option
SELECT product_option.*, oc.name, `option`.type, product_option.product_option_id as array_key
- FROM product_option AS product_option
+ FROM product_option
INNER JOIN `option` ON `option`.option_id = product_option.option_id
INNER JOIN option_content oc ON oc.option_id = product_option.option_id AND oc.language_id = :language_id
diff --git a/admin/sql/sqlite/product_option_value.sql b/admin/sql/sqlite/product_option_value.sql
index 6926db7..457e7dc 100644
--- a/admin/sql/sqlite/product_option_value.sql
+++ b/admin/sql/sqlite/product_option_value.sql
@@ -17,7 +17,7 @@
SELECT product_option_value.*,
option_value.image, ovc.name, oc.name as `option`,
product_option_value.product_option_value_id as array_key
- FROM product_option_value AS product_option_value
+ FROM product_option_value
INNER JOIN option_value ON option_value.option_value_id = product_option_value.option_value_id
INNER JOIN option_value_content ovc ON ovc.option_value_id = product_option_value.option_value_id AND ovc.language_id = :language_id
INNER JOIN option_content oc ON oc.option_id = product_option_value.option_id AND oc.language_id = :language_id
diff --git a/admin/sql/sqlite/product_question.sql b/admin/sql/sqlite/product_question.sql
index 8229afd..3faf9e5 100755
--- a/admin/sql/sqlite/product_question.sql
+++ b/admin/sql/sqlite/product_question.sql
@@ -19,7 +19,7 @@
BEGIN
SELECT user.username, user.email, user.first_name, user.last_name, user.display_name, user.avatar, user.bio, user.subscribe, product_question.*,user.user_id as user_id
- FROM product_question AS product_question
+ FROM product_question
LEFT JOIN user on user.user_id = product_question.user_id
WHERE 1 = 1
diff --git a/admin/sql/sqlite/product_subscription.sql b/admin/sql/sqlite/product_subscription.sql
index 84b6d82..bbf5778 100644
--- a/admin/sql/sqlite/product_subscription.sql
+++ b/admin/sql/sqlite/product_subscription.sql
@@ -24,7 +24,7 @@
product_subscription.price,
product_subscription.trial_price
- FROM product_subscription AS product_subscription
+ FROM product_subscription
-- product_id
@IF isset(:product_id)
diff --git a/admin/sql/sqlite/region.sql b/admin/sql/sqlite/region.sql
index 2061a3e..70ca26c 100755
--- a/admin/sql/sqlite/region.sql
+++ b/admin/sql/sqlite/region.sql
@@ -14,7 +14,7 @@
BEGIN
-- region
SELECT country.name as country,region.*
- FROM region AS region
+ FROM region
LEFT JOIN country ON country.country_id = region.country_id
WHERE 1 = 1
diff --git a/admin/sql/sqlite/region_group.sql b/admin/sql/sqlite/region_group.sql
index 5d57ad8..64ec5cd 100755
--- a/admin/sql/sqlite/region_group.sql
+++ b/admin/sql/sqlite/region_group.sql
@@ -12,7 +12,7 @@
BEGIN
-- region_group
SELECT *
- FROM region_group AS region_group WHERE 1 = 1
+ FROM region_group WHERE 1 = 1
@IF !empty(:limit)
THEN
diff --git a/admin/sql/sqlite/return.sql b/admin/sql/sqlite/return.sql
index 97abd34..b36d2aa 100755
--- a/admin/sql/sqlite/return.sql
+++ b/admin/sql/sqlite/return.sql
@@ -12,7 +12,7 @@
BEGIN
-- return
SELECT return.*, return_resolution.name as return_resolution, return_reason.name as return_reason, return_status.name as return_status
- FROM return AS return
+ FROM return
INNER JOIN return_resolution ON return_resolution.return_resolution_id = return.return_resolution_id AND return_resolution.language_id = :language_id
INNER JOIN return_reason ON return_reason.return_reason_id = return.return_reason_id AND return_reason.language_id = :language_id
INNER JOIN return_status ON return_status.return_status_id = return.return_status_id AND return_status.language_id = :language_id
diff --git a/admin/sql/sqlite/return_reason.sql b/admin/sql/sqlite/return_reason.sql
index 1624d4a..f05f6ac 100755
--- a/admin/sql/sqlite/return_reason.sql
+++ b/admin/sql/sqlite/return_reason.sql
@@ -12,7 +12,7 @@
BEGIN
-- return_reason
SELECT *
- FROM return_reason AS return_reason WHERE 1 = 1
+ FROM return_reason WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/sqlite/return_resolution.sql b/admin/sql/sqlite/return_resolution.sql
index 83f7f22..a58a3e7 100755
--- a/admin/sql/sqlite/return_resolution.sql
+++ b/admin/sql/sqlite/return_resolution.sql
@@ -12,7 +12,7 @@
BEGIN
-- return resolution
SELECT *
- FROM return_resolution AS return_resolution WHERE 1 = 1
+ FROM return_resolution WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/sqlite/return_status.sql b/admin/sql/sqlite/return_status.sql
index c8ed13c..1bd7981 100755
--- a/admin/sql/sqlite/return_status.sql
+++ b/admin/sql/sqlite/return_status.sql
@@ -12,7 +12,7 @@
BEGIN
-- return_status
SELECT *
- FROM return_status AS return_status WHERE 1 = 1
+ FROM return_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/sqlite/shipping_status.sql b/admin/sql/sqlite/shipping_status.sql
index d9ed4c9..dcdc489 100644
--- a/admin/sql/sqlite/shipping_status.sql
+++ b/admin/sql/sqlite/shipping_status.sql
@@ -12,7 +12,7 @@
BEGIN
SELECT *
- FROM shipping_status AS shipping_status WHERE 1 = 1
+ FROM shipping_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/sqlite/site.sql b/admin/sql/sqlite/site.sql
index dd7af9a..3b9375a 100755
--- a/admin/sql/sqlite/site.sql
+++ b/admin/sql/sqlite/site.sql
@@ -15,14 +15,14 @@
BEGIN
-- site
SELECT *, site_id as array_key
- FROM site as sites
+ FROM site
WHERE 1 = 1
-- site_id
@IF isset(:site_id) && !empty(:site_id)
THEN
- AND sites.site_id IN (:site_id)
+ AND site.site_id IN (:site_id)
END @IF
-- limit
@@ -34,7 +34,7 @@
-- SELECT FOUND_ROWS() as count;
SELECT count(*) FROM (
- @SQL_COUNT(sites.site_id, site) -- this takes previous query removes limit and replaces select columns with parameter product_id
+ @SQL_COUNT(site.site_id, site) -- this takes previous query removes limit and replaces select columns with parameter product_id
) as count;
END
diff --git a/admin/sql/sqlite/stock_status.sql b/admin/sql/sqlite/stock_status.sql
index 6e4437a..17ee521 100755
--- a/admin/sql/sqlite/stock_status.sql
+++ b/admin/sql/sqlite/stock_status.sql
@@ -12,7 +12,7 @@
BEGIN
-- stock_status
SELECT *
- FROM stock_status AS stock_status WHERE 1 = 1
+ FROM stock_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/sqlite/subscription.sql b/admin/sql/sqlite/subscription.sql
index 952bfeb..3ae76a8 100755
--- a/admin/sql/sqlite/subscription.sql
+++ b/admin/sql/sqlite/subscription.sql
@@ -12,7 +12,7 @@
BEGIN
-- subscription
SELECT *
- FROM subscription AS subscription WHERE 1 = 1
+ FROM subscription WHERE 1 = 1
-- limit
@IF isset(:limit)
diff --git a/admin/sql/sqlite/subscription_plan.sql b/admin/sql/sqlite/subscription_plan.sql
index 1ed732b..5ca3c81 100755
--- a/admin/sql/sqlite/subscription_plan.sql
+++ b/admin/sql/sqlite/subscription_plan.sql
@@ -13,7 +13,7 @@
BEGIN
-- subscription_plan
SELECT subscription_plan.*,subscription_plan_content.name,subscription_plan.subscription_plan_id as array_key
- FROM subscription_plan AS subscription_plan
+ FROM subscription_plan
INNER JOIN subscription_plan_content ON subscription_plan_content.subscription_plan_id = subscription_plan.subscription_plan_id
AND subscription_plan_content.language_id = :language_id
WHERE 1 = 1
diff --git a/admin/sql/sqlite/subscription_status.sql b/admin/sql/sqlite/subscription_status.sql
index c2597a0..84ffb93 100755
--- a/admin/sql/sqlite/subscription_status.sql
+++ b/admin/sql/sqlite/subscription_status.sql
@@ -12,7 +12,7 @@
BEGIN
-- subscription_status
SELECT *
- FROM subscription_status AS subscription_status WHERE 1 = 1
+ FROM subscription_status WHERE 1 = 1
@IF !empty(:language_id)
THEN
diff --git a/admin/sql/sqlite/tax_rate.sql b/admin/sql/sqlite/tax_rate.sql
index 8ab847c..6528240 100755
--- a/admin/sql/sqlite/tax_rate.sql
+++ b/admin/sql/sqlite/tax_rate.sql
@@ -12,7 +12,7 @@
BEGIN
-- tax_rate
SELECT *
- FROM tax_rate AS tax_rate WHERE 1 = 1
+ FROM tax_rate WHERE 1 = 1
@IF !empty(:limit)
diff --git a/admin/sql/sqlite/tax_rule.sql b/admin/sql/sqlite/tax_rule.sql
index 9c0c441..116139f 100755
--- a/admin/sql/sqlite/tax_rule.sql
+++ b/admin/sql/sqlite/tax_rule.sql
@@ -12,7 +12,7 @@
BEGIN
-- tax_rule
SELECT *
- FROM tax_rule AS tax_rule WHERE 1 = 1
+ FROM tax_rule WHERE 1 = 1
@IF !empty(:tax_type_id)
diff --git a/admin/sql/sqlite/tax_type.sql b/admin/sql/sqlite/tax_type.sql
index 2be0cc6..9dfe2ca 100755
--- a/admin/sql/sqlite/tax_type.sql
+++ b/admin/sql/sqlite/tax_type.sql
@@ -12,7 +12,7 @@
BEGIN
-- tax_type
SELECT *
- FROM tax_type AS tax_type WHERE 1 = 1
+ FROM tax_type WHERE 1 = 1
@SQL_LIMIT(:start, :limit);
diff --git a/admin/sql/sqlite/taxonomy.sql b/admin/sql/sqlite/taxonomy.sql
index 351c623..15314d2 100755
--- a/admin/sql/sqlite/taxonomy.sql
+++ b/admin/sql/sqlite/taxonomy.sql
@@ -19,7 +19,7 @@
BEGIN
-- taxonomy_item
SELECT *, taxonomy_id as array_key
- FROM taxonomy as taxonomy
+ FROM taxonomy
-- LEFT JOIN taxonomy_to_site t2s ON (taxonomy_item.taxonomy_item_id = t2s.taxonomy_item_id)
WHERE 1 = 1
diff --git a/admin/sql/sqlite/user.sql b/admin/sql/sqlite/user.sql
index 8522adf..203a14a 100755
--- a/admin/sql/sqlite/user.sql
+++ b/admin/sql/sqlite/user.sql
@@ -3,13 +3,17 @@
-- get all entries
CREATE PROCEDURE getAll(
- IN start INT,
- IN limit INT,
IN status INT,
IN search CHAR,
IN email CHAR,
IN phone_number CHAR,
+ -- pagination
+ IN start INT,
+ IN limit INT,
+ IN order_by CHAR,
+ IN direction CHAR,
+
-- return array of user
OUT fetch_all,
-- return user count for count query
@@ -43,6 +47,13 @@
user.last_name LIKE '%' || :search || '%'
END @IF
+ -- 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
+ @ELSE
+ ORDER BY user.user_id DESC
+ END @IF
-- limit
@IF isset(:limit)
diff --git a/admin/sql/sqlite/user_address.sql b/admin/sql/sqlite/user_address.sql
index 783d572..581b3bf 100755
--- a/admin/sql/sqlite/user_address.sql
+++ b/admin/sql/sqlite/user_address.sql
@@ -19,7 +19,7 @@
SELECT *
- FROM user_address AS user_address
+ FROM user_address
WHERE 1 = 1
-- user
diff --git a/admin/sql/sqlite/user_group.sql b/admin/sql/sqlite/user_group.sql
index a5e7c3b..93afb8c 100755
--- a/admin/sql/sqlite/user_group.sql
+++ b/admin/sql/sqlite/user_group.sql
@@ -12,7 +12,7 @@
BEGIN
-- user_group
SELECT user_group.*,user_group_content.name, user_group_content.content, user_group_content.language_id
- FROM user_group AS user_group
+ FROM user_group
INNER JOIN user_group_content ON user_group_content.user_group_id = user_group.user_group_id
WHERE 1 = 1
diff --git a/admin/sql/sqlite/vendor.sql b/admin/sql/sqlite/vendor.sql
index abb7718..a6c21a0 100755
--- a/admin/sql/sqlite/vendor.sql
+++ b/admin/sql/sqlite/vendor.sql
@@ -106,7 +106,7 @@
)
BEGIN
- SELECT * FROM vendor AS vendor
+ SELECT * FROM vendor
LEFT JOIN vendor_to_site p2s ON (vendor.vendor_id = p2s.vendor_id)
WHERE p2s.site_id = :site_id
diff --git a/admin/sql/sqlite/voucher.sql b/admin/sql/sqlite/voucher.sql
index e3c9a54..58d82f1 100755
--- a/admin/sql/sqlite/voucher.sql
+++ b/admin/sql/sqlite/voucher.sql
@@ -12,7 +12,7 @@
BEGIN
-- voucher
SELECT *
- FROM voucher AS voucher WHERE 1 = 1
+ FROM voucher WHERE 1 = 1
@SQL_LIMIT(:start, :limit);
diff --git a/admin/sql/sqlite/weight_type.sql b/admin/sql/sqlite/weight_type.sql
index 31a2b14..229fc2c 100755
--- a/admin/sql/sqlite/weight_type.sql
+++ b/admin/sql/sqlite/weight_type.sql
@@ -12,7 +12,7 @@
BEGIN
-- weight_type
SELECT *, weight_type.weight_type_id as array_key
- FROM weight_type AS weight_type
+ FROM weight_type
INNER JOIN weight_type_content ON weight_type_content.weight_type_id = weight_type.weight_type_id
WHERE 1 = 1
diff --git a/app/sql/mysqli/category.sql b/app/sql/mysqli/category.sql
index 61e4172..fdb46fb 100755
--- a/app/sql/mysqli/category.sql
+++ b/app/sql/mysqli/category.sql
@@ -26,13 +26,13 @@
)
BEGIN
- SELECT SQL_CALC_FOUND_ROWS *, posts.post_id as array_key
+ SELECT SQL_CALC_FOUND_ROWS *, post.post_id as array_key
- FROM post AS posts
+ FROM post
- LEFT JOIN post_content pd ON (posts.post_id = pd.post_id AND pd.language_id = :language_id)
- LEFT JOIN post_to_site ps ON (posts.post_id = ps.post_id)
- LEFT JOIN post_to_taxonomy_item pt ON (posts.post_id = pt.post_id)
+ LEFT JOIN post_content pd ON (post.post_id = pd.post_id AND pd.language_id = :language_id)
+ LEFT JOIN post_to_site ps ON (post.post_id = ps.post_id)
+ LEFT JOIN post_to_taxonomy_item pt ON (post.post_id = pt.post_id)
LEFT JOIN taxonomy_item categories ON (categories.taxonomy_item_id = pt.taxonomy_item_id)
LEFT JOIN taxonomy_to_site c2s ON (categories.taxonomy_item_id = c2s.taxonomy_item_id)
diff --git a/app/sql/pgsql/category.sql b/app/sql/pgsql/category.sql
index 52f10ae..41a41e3 100755
--- a/app/sql/pgsql/category.sql
+++ b/app/sql/pgsql/category.sql
@@ -26,13 +26,13 @@
)
BEGIN
- SELECT SQL_CALC_FOUND_ROWS *, posts.post_id as array_key
+ SELECT SQL_CALC_FOUND_ROWS *, post.post_id as array_key
- FROM post AS posts
+ FROM post
- LEFT JOIN post_content pd ON (posts.post_id = pd.post_id AND pd.language_id = :language_id)
- LEFT JOIN post_to_site ps ON (posts.post_id = ps.post_id)
- LEFT JOIN post_to_taxonomy_item pt ON (posts.post_id = pt.post_id)
+ LEFT JOIN post_content pd ON (post.post_id = pd.post_id AND pd.language_id = :language_id)
+ LEFT JOIN post_to_site ps ON (post.post_id = ps.post_id)
+ LEFT JOIN post_to_taxonomy_item pt ON (post.post_id = pt.post_id)
LEFT JOIN taxonomy_item categories ON (categories.taxonomy_item_id = pt.taxonomy_item_id)
LEFT JOIN taxonomy_to_site c2s ON (categories.taxonomy_item_id = c2s.taxonomy_item_id)
diff --git a/app/sql/sqlite/category.sql b/app/sql/sqlite/category.sql
index 52f10ae..41a41e3 100755
--- a/app/sql/sqlite/category.sql
+++ b/app/sql/sqlite/category.sql
@@ -26,13 +26,13 @@
)
BEGIN
- SELECT SQL_CALC_FOUND_ROWS *, posts.post_id as array_key
+ SELECT SQL_CALC_FOUND_ROWS *, post.post_id as array_key
- FROM post AS posts
+ FROM post
- LEFT JOIN post_content pd ON (posts.post_id = pd.post_id AND pd.language_id = :language_id)
- LEFT JOIN post_to_site ps ON (posts.post_id = ps.post_id)
- LEFT JOIN post_to_taxonomy_item pt ON (posts.post_id = pt.post_id)
+ LEFT JOIN post_content pd ON (post.post_id = pd.post_id AND pd.language_id = :language_id)
+ LEFT JOIN post_to_site ps ON (post.post_id = ps.post_id)
+ LEFT JOIN post_to_taxonomy_item pt ON (post.post_id = pt.post_id)
LEFT JOIN taxonomy_item categories ON (categories.taxonomy_item_id = pt.taxonomy_item_id)
LEFT JOIN taxonomy_to_site c2s ON (categories.taxonomy_item_id = c2s.taxonomy_item_id)