[aur-dev] [PATCH 1/1] convert mysql specific offset/limit syntax to more standardized format

elij elij.mx at gmail.com
Tue Apr 26 01:03:02 EDT 2011


On Mon, Apr 25, 2011 at 9:31 PM, Dan McGee <dpmcgee at gmail.com> wrote:
> On Mon, Apr 25, 2011 at 11:17 PM, elij <elij.mx at gmail.com> wrote:
>> ---
>>  web/html/rss.php      |    2 +-
>>  web/html/tu.php       |    2 +-
>>  web/lib/acctfuncs.inc |    2 +-
>>  web/lib/pkgfuncs.inc  |    2 +-
>>  4 files changed, 4 insertions(+), 4 deletions(-)
>
> Haha, patch war!

:P

> We have nearly identical patches here; the only thing different is
> string concatenation/variable replacement. It appears we went opposite
> directions. I did concatenation rather than replacement as it seemed
> to be the standard in the codebase, and looking at
>> +       $q_limit = "LIMIT {$_GET["PP"]} OFFSET {$_GET["O"]}";
> made me puke a little in my mouth first before I went the way I did.

Ha! I feel like that looking at php code in general!

I saw a mess of . " ' . and did a bit of a lolwut myself. I don't
think either mechanism looks good honestly. Too bad php doesn't have
decent string formatting. :/ I am tempted to use sprintf!

Note that I failboated a bit and used double-quote inside the
substitution elements. I just used what existed, but single quote
would have been better.

That said, using string catenation is probably better for code
uniformity sake (since everything else does it _most of the time_.

> I also saw things referencing memory leaks with variable substitution,
> but that is likely old. It does appear concatenation is slightly
> faster [1], however, not that we are anywhere near the point where
> this matters. :)

lol.

> -Dan
>
> [1] http://www.webmasterworld.com/forum88/3253.htm (benchmarks from
> post-2004 welcome!)
>
>> diff --git a/web/html/rss.php b/web/html/rss.php
>> index cb0bf40..0547815 100644
>> --- a/web/html/rss.php
>> +++ b/web/html/rss.php
>> @@ -32,7 +32,7 @@ $rss->image = $image;
>>  $dbh = db_connect();
>>  $q = "SELECT * FROM Packages ";
>>  $q.= "ORDER BY SubmittedTS DESC ";
>> -$q.= "LIMIT 0 , 20";
>> +$q.= "LIMIT 20";
>>  $result = db_query($q, $dbh);
>>
>>  while ($row = mysql_fetch_assoc($result)) {
>> diff --git a/web/html/tu.php b/web/html/tu.php
>> index 941e6ed..dc1c5e3 100644
>> --- a/web/html/tu.php
>> +++ b/web/html/tu.php
>> @@ -119,7 +119,7 @@ if ($atype == "Trusted User" OR $atype == "Developer") {
>>                }
>>
>>                $order = ($by == 'asc') ? 'ASC' : 'DESC';
>> -               $lim = ($limit > 0) ? " LIMIT $off, $limit" : "";
>> +               $lim = ($limit > 0) ? " LIMIT $limit OFFSET $off" : "";
>>                $by_next = ($by == 'desc') ? 'asc' : 'desc';
>>
>>                $q = "SELECT * FROM TU_VoteInfo WHERE End > " . time() . " ORDER BY Submitted " . $order;
>> diff --git a/web/lib/acctfuncs.inc b/web/lib/acctfuncs.inc
>> index fe1cfb1..f07c1fc 100644
>> --- a/web/lib/acctfuncs.inc
>> +++ b/web/lib/acctfuncs.inc
>> @@ -405,7 +405,7 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="",
>>                        break;
>>        }
>>        $search_vars[] = "SB";
>> -       $q.= "LIMIT ". $OFFSET . ", " . $HITS_PER_PAGE;
>> +       $q.= "LIMIT {$HITS_PER_PAGE} OFFSET {$OFFSET}";
>>
>>        $dbh = db_connect();
>>
>> diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc
>> index 8f90d0e..25a09c4 100644
>> --- a/web/lib/pkgfuncs.inc
>> +++ b/web/lib/pkgfuncs.inc
>> @@ -501,7 +501,7 @@ function pkg_search_page($SID="") {
>>                break;
>>        }
>>
>> -       $q_limit = "LIMIT ".$_GET["O"].", ".$_GET["PP"];
>> +       $q_limit = "LIMIT {$_GET["PP"]} OFFSET {$_GET["O"]}";
>>
>>        $q = $q_select . $q_from . $q_from_extra . $q_where . $q_sort . $q_limit;
>>        $q_total = "SELECT COUNT(*) " . $q_from . $q_where;
>> --
>> 1.7.4.1
>>
>>
>


More information about the aur-dev mailing list