Skip to content

Commit

Permalink
Feature 1255 : improve sql
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nikrou committed Nov 21, 2009
1 parent 8c17d36 commit f0d0a09
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion admin/cat_perm.php
Expand Up @@ -59,7 +59,7 @@
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));
Expand Down
2 changes: 1 addition & 1 deletion admin/element_set_global.php
Expand Up @@ -474,7 +474,7 @@
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);
Expand Down
2 changes: 1 addition & 1 deletion admin/element_set_unit.php
Expand Up @@ -196,7 +196,7 @@
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);

Expand Down
4 changes: 2 additions & 2 deletions admin/include/functions.php
Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion admin/include/functions_history.inc.php
Expand Up @@ -161,7 +161,7 @@ function get_history($data, $search, $types)
WHERE '.$where_separator.'
;';

// LIMIT '.$page['start'].', '.$conf['nb_logs_page'].'
// LIMIT '.$page['start'].' OFFSET '.$conf['nb_logs_page'].'

$result = pwg_query($query);

Expand Down
2 changes: 1 addition & 1 deletion admin/rating.php
Expand Up @@ -176,7 +176,7 @@
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();
Expand Down
2 changes: 1 addition & 1 deletion comments.php
Expand Up @@ -326,7 +326,7 @@
if ('all' != $page['items_number'])
{
$query.= '
LIMIT '.$start.','.$page['items_number'];
LIMIT '.$start.' OFFSET '.$page['items_number'];
}
$query.= '
;';
Expand Down
2 changes: 1 addition & 1 deletion include/calendar_monthly.class.php
Expand Up @@ -348,7 +348,7 @@ function build_month_calendar(&$tpl_var)
$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));
Expand Down
6 changes: 3 additions & 3 deletions include/functions_notification.inc.php
Expand Up @@ -444,7 +444,7 @@ function get_recent_post_dates($max_dates, $max_elements, $max_cats)
'.$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();
Expand All @@ -464,7 +464,7 @@ function get_recent_post_dates($max_dates, $max_elements, $max_cats)
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);
Expand All @@ -484,7 +484,7 @@ function get_recent_post_dates($max_dates, $max_elements, $max_cats)
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);
Expand Down
2 changes: 1 addition & 1 deletion include/picture_comment.inc.php
Expand Up @@ -136,7 +136,7 @@
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 );

Expand Down
6 changes: 3 additions & 3 deletions include/ws_functions.inc.php
Expand Up @@ -292,7 +292,7 @@ function ws_categories_getImages($params, &$service)
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))
Expand Down Expand Up @@ -683,7 +683,7 @@ function ws_images_getInfo($params, &$service)
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))
Expand Down Expand Up @@ -1398,7 +1398,7 @@ function ws_tags_getImages($params, &$service)
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))
Expand Down

0 comments on commit f0d0a09

Please sign in to comment.