Skip to content

Commit

Permalink
Feature 1255 : limit params in sql queries were in wrong order (LIMIT…
Browse files Browse the repository at this point in the history
… count OFFSET offset)

git-svn-id: http://piwigo.org/svn/trunk@4334 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
nikrou committed Nov 21, 2009
1 parent daa877a commit ce3fe0d
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 23 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 OFFSET 1
LIMIT 1
;';

list($page['cat']) = pwg_db_fetch_row(pwg_query($query));
Expand Down
4 changes: 1 addition & 3 deletions admin/element_set_global.php
Expand Up @@ -474,13 +474,11 @@
FROM '.IMAGES_TABLE.'
WHERE id IN ('.implode(',', $page['cat_elements_id']).')
'.$conf['order_by'].'
LIMIT '.$page['start'].' OFFSET '.$page['nb_images'].'
LIMIT '.$page['nb_images'].' OFFSET '.$page['start'].'
;';
//echo '<pre>'.$query.'</pre>';
$result = pwg_query($query);

// template thumbnail initialization

while ($row = pwg_db_fetch_assoc($result))
{
$src = get_thumbnail_url($row);
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'].' OFFSET '.$page['nb_images'].'
LIMIT '.$page['nb_images'].' OFFSET '.$page['start'].'
;';
$result = pwg_query($query);

Expand Down
2 changes: 1 addition & 1 deletion admin/include/functions.php
Expand Up @@ -597,7 +597,7 @@ function set_random_representant($categories)
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE category_id = '.$category_id.'
ORDER BY '.DB_RANDOM_FUNCTION.'()
LIMIT 0 OFFSET 1
LIMIT 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'].' OFFSET '.$conf['nb_logs_page'].'
// LIMIT '.$conf['nb_logs_page'].' OFFSET '.$page['start'].'

$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.' OFFSET '.$elements_per_page.'
LIMIT '.$elements_per_page.' OFFSET '.$start.'
;';

$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.' OFFSET '.$page['items_number'];
LIMIT '.$page['items_number'].' OFFSET '.$start;
}
$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 OFFSET 1';
LIMIT 1';
unset ( $page['chronology_date'][CDAY] );

$row = pwg_db_fetch_assoc(pwg_query($query));
Expand Down
4 changes: 2 additions & 2 deletions include/category_cats.inc.php
Expand Up @@ -105,7 +105,7 @@
"\n AND"
).'
ORDER BY RAND()
LIMIT 0,1
LIMIT 1
;';
$subresult = pwg_query($query);
if (pwg_db_num_rows($subresult) > 0)
Expand Down Expand Up @@ -133,7 +133,7 @@
"\n AND"
).'
ORDER BY RAND()
LIMIT 0,1
LIMIT 1
;';
$subresult = pwg_query($query);
if (pwg_db_num_rows($subresult) > 0)
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 OFFSET '.$max_dates.'
LIMIT '.$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 OFFSET '.$max_elements.'
LIMIT '.$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 OFFSET '.$max_cats.'
LIMIT '.$max_cats.'
;';
$dates[$i]['categories'] = array();
$result = pwg_query($query);
Expand Down
2 changes: 1 addition & 1 deletion include/functions_tag.inc.php
Expand Up @@ -239,7 +239,7 @@ function get_common_tags($items, $max_tags, $excluded_tag_ids=null)
{
$query .= '
ORDER BY counter DESC
LIMIT 0,'.$max_tags;
LIMIT '.$max_tags;
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions include/section_init.inc.php
Expand Up @@ -490,7 +490,7 @@
WHERE hit > 0
'.$forbidden.'
'.$conf['order_by'].'
LIMIT 0, '.$conf['top_number'].'
LIMIT '.$conf['top_number'].'
;';

$page = array_merge(
Expand All @@ -517,7 +517,7 @@
WHERE average_rate IS NOT NULL
'.$forbidden.'
'.$conf['order_by'].'
LIMIT 0, '.$conf['top_number'].'
LIMIT '.$conf['top_number'].'
;';
$page = array_merge(
$page,
Expand Down
8 changes: 4 additions & 4 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']).' OFFSET '.(int)$params['per_page'];
LIMIT '.(int)$params['per_page'].' OFFSET '.(int)($params['per_page']*$params['page']);

$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result))
Expand Down Expand Up @@ -682,8 +682,8 @@ function ws_images_getInfo($params, &$service)
FROM '.COMMENTS_TABLE.'
WHERE '.$where_comments.'
ORDER BY date
LIMIT '.(int)($params['comments_per_page']*$params['comments_page']).
' OFFSET '.(int)$params['comments_per_page'];
LIMIT '.(int)$params['comments_per_page'].
' OFFSET '.(int)($params['comments_per_page']*$params['comments_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']).' OFFSET '.(int)$params['per_page'];
LIMIT '.(int)$params['per_page'].' OFFSET '.(int)($params['per_page']*$params['page']);

$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result))
Expand Down
2 changes: 1 addition & 1 deletion random.php
Expand Up @@ -52,7 +52,7 @@
'WHERE'
).'
ORDER BY RAND(NOW())
LIMIT 0, '.min(50, $conf['top_number'],$user['nb_image_page']).'
LIMIT '.min(50, $conf['top_number'],$user['nb_image_page']).'
;';

// +-----------------------------------------------------------------------+
Expand Down

0 comments on commit ce3fe0d

Please sign in to comment.