aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornikrou <nikrou@piwigo.org>2009-11-21 12:15:22 +0000
committernikrou <nikrou@piwigo.org>2009-11-21 12:15:22 +0000
commitf0d0a0952c9889323d60bec249df0fccf286d1a6 (patch)
treecc35359a725297c7995827e0961e270186142c03
parent8c17d369fadc03d649213f0fbbad625ab285a13a (diff)
Feature 1255 : improve sql
Replace in queries LIMIT N,M by LIMIT N OFFSET M git-svn-id: http://piwigo.org/svn/trunk@4331 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--admin/cat_perm.php2
-rw-r--r--admin/element_set_global.php2
-rw-r--r--admin/element_set_unit.php2
-rw-r--r--admin/include/functions.php4
-rw-r--r--admin/include/functions_history.inc.php2
-rw-r--r--admin/rating.php2
-rw-r--r--comments.php2
-rw-r--r--include/calendar_monthly.class.php2
-rw-r--r--include/functions_notification.inc.php6
-rw-r--r--include/picture_comment.inc.php2
-rw-r--r--include/ws_functions.inc.php6
11 files changed, 16 insertions, 16 deletions
diff --git a/admin/cat_perm.php b/admin/cat_perm.php
index 91711ddf1..5ef886e1d 100644
--- a/admin/cat_perm.php
+++ b/admin/cat_perm.php
@@ -59,7 +59,7 @@ if (!isset($page['cat']))
SELECT id
FROM '.CATEGORIES_TABLE.'
WHERE status = \'private\'
- LIMIT 0,1
+ LIMIT 0 OFFSET 1
;';
list($page['cat']) = pwg_db_fetch_row(pwg_query($query));
diff --git a/admin/element_set_global.php b/admin/element_set_global.php
index 3676309e5..79e78e8a2 100644
--- a/admin/element_set_global.php
+++ b/admin/element_set_global.php
@@ -474,7 +474,7 @@ SELECT id,path,tn_ext,file,filesize,level
FROM '.IMAGES_TABLE.'
WHERE id IN ('.implode(',', $page['cat_elements_id']).')
'.$conf['order_by'].'
- LIMIT '.$page['start'].', '.$page['nb_images'].'
+ LIMIT '.$page['start'].' OFFSET '.$page['nb_images'].'
;';
//echo '<pre>'.$query.'</pre>';
$result = pwg_query($query);
diff --git a/admin/element_set_unit.php b/admin/element_set_unit.php
index 65206aba4..cf5409296 100644
--- a/admin/element_set_unit.php
+++ b/admin/element_set_unit.php
@@ -196,7 +196,7 @@ SELECT id,path,tn_ext,name,date_creation,comment,author,file
FROM '.IMAGES_TABLE.'
WHERE id IN ('.implode(',', $page['cat_elements_id']).')
'.$conf['order_by'].'
- LIMIT '.$page['start'].', '.$page['nb_images'].'
+ LIMIT '.$page['start'].' OFFSET '.$page['nb_images'].'
;';
$result = pwg_query($query);
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 2b6bffa98..16928e9ab 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -596,8 +596,8 @@ function set_random_representant($categories)
SELECT image_id
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE category_id = '.$category_id.'
- ORDER BY RAND()
- LIMIT 0,1
+ ORDER BY '.DB_RANDOM_FUNCTION.'()
+ LIMIT 0 OFFSET 1
;';
list($representative) = pwg_db_fetch_row(pwg_query($query));
diff --git a/admin/include/functions_history.inc.php b/admin/include/functions_history.inc.php
index 824caed42..38d3950eb 100644
--- a/admin/include/functions_history.inc.php
+++ b/admin/include/functions_history.inc.php
@@ -161,7 +161,7 @@ SELECT
WHERE '.$where_separator.'
;';
- // LIMIT '.$page['start'].', '.$conf['nb_logs_page'].'
+ // LIMIT '.$page['start'].' OFFSET '.$conf['nb_logs_page'].'
$result = pwg_query($query);
diff --git a/admin/rating.php b/admin/rating.php
index 5f3f93fa3..e5fe48d03 100644
--- a/admin/rating.php
+++ b/admin/rating.php
@@ -176,7 +176,7 @@ SELECT i.id,
WHERE 1 = 1 ' . $page['user_filter'] . '
GROUP BY r.element_id
ORDER BY ' . $available_order_by[$order_by_index][1] .'
- LIMIT '.$start.','.$elements_per_page.'
+ LIMIT '.$start.' OFFSET '.$elements_per_page.'
;';
$images = array();
diff --git a/comments.php b/comments.php
index 3300bc6aa..182f673a0 100644
--- a/comments.php
+++ b/comments.php
@@ -326,7 +326,7 @@ SELECT com.id AS comment_id
if ('all' != $page['items_number'])
{
$query.= '
- LIMIT '.$start.','.$page['items_number'];
+ LIMIT '.$start.' OFFSET '.$page['items_number'];
}
$query.= '
;';
diff --git a/include/calendar_monthly.class.php b/include/calendar_monthly.class.php
index e78824617..1a4e70ce3 100644
--- a/include/calendar_monthly.class.php
+++ b/include/calendar_monthly.class.php
@@ -348,7 +348,7 @@ SELECT id, file,tn_ext,path, width, height, DAYOFWEEK('.$this->date_field.')-1 a
$query.= $this->get_date_where();
$query.= '
ORDER BY RAND()
- LIMIT 0,1';
+ LIMIT 0 OFFSET 1';
unset ( $page['chronology_date'][CDAY] );
$row = pwg_db_fetch_assoc(pwg_query($query));
diff --git a/include/functions_notification.inc.php b/include/functions_notification.inc.php
index b9789ee02..b48fd35be 100644
--- a/include/functions_notification.inc.php
+++ b/include/functions_notification.inc.php
@@ -444,7 +444,7 @@ SELECT date_available,
'.$where_sql.'
GROUP BY date_available
ORDER BY date_available DESC
- LIMIT 0,'.$max_dates.'
+ LIMIT 0 OFFSET '.$max_dates.'
;';
$result = pwg_query($query);
$dates = array();
@@ -464,7 +464,7 @@ SELECT DISTINCT id, path, name, tn_ext, file
AND date_available="'.$dates[$i]['date_available'].'"
AND tn_ext IS NOT NULL
ORDER BY RAND(NOW())
- LIMIT 0,'.$max_elements.'
+ LIMIT 0 OFFSET '.$max_elements.'
;';
$dates[$i]['elements'] = array();
$result = pwg_query($query);
@@ -484,7 +484,7 @@ SELECT DISTINCT c.uppercats, COUNT(DISTINCT i.id) img_count
AND date_available="'.$dates[$i]['date_available'].'"
GROUP BY category_id
ORDER BY img_count DESC
- LIMIT 0,'.$max_cats.'
+ LIMIT 0 OFFSET '.$max_cats.'
;';
$dates[$i]['categories'] = array();
$result = pwg_query($query);
diff --git a/include/picture_comment.inc.php b/include/picture_comment.inc.php
index c8891493e..4e980a8c6 100644
--- a/include/picture_comment.inc.php
+++ b/include/picture_comment.inc.php
@@ -136,7 +136,7 @@ SELECT com.id,author,author_id,'.$conf['user_fields']['username'].' AS username,
WHERE image_id = '.$page['image_id'].
$validated_clause.'
ORDER BY date ASC
- LIMIT '.$page['start'].', '.$conf['nb_comment_page'].'
+ LIMIT '.$page['start'].' OFFSET '.$conf['nb_comment_page'].'
;';
$result = pwg_query( $query );
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index 49dfdc47e..da1d7e06f 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -292,7 +292,7 @@ SELECT i.*, GROUP_CONCAT(category_id) cat_ids
AND ', $where_clauses).'
GROUP BY i.id
'.$order_by.'
-LIMIT '.(int)($params['per_page']*$params['page']).','.(int)$params['per_page'];
+LIMIT '.(int)($params['per_page']*$params['page']).' OFFSET '.(int)$params['per_page'];
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result))
@@ -683,7 +683,7 @@ SELECT id, date, author, content
WHERE '.$where_comments.'
ORDER BY date
LIMIT '.(int)($params['comments_per_page']*$params['comments_page']).
- ','.(int)$params['comments_per_page'];
+ ' OFFSET '.(int)$params['comments_per_page'];
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result))
@@ -1398,7 +1398,7 @@ SELECT DISTINCT i.* FROM '.IMAGES_TABLE.' i
WHERE '. implode('
AND ', $where_clauses).'
'.$order_by.'
-LIMIT '.(int)($params['per_page']*$params['page']).','.(int)$params['per_page'];
+LIMIT '.(int)($params['per_page']*$params['page']).' OFFSET '.(int)$params['per_page'];
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result))