Menu

#437 fix for modulo error with sqlite at get_anniversary_events

Normal Version
closed-fixed
nobody
5
2008-02-21
2008-01-07
No

I use sqlite, and got this at the main page at get_anniversary_events box:

ERROR:-1 DB Error: unknown error
SQL:1 ** SELECT d_gid, i_gedcom, 'INDI', d_type, d_day, d_month, d_year, d_fact FROM pgv_dates, pgv_individuals WHERE d_type='@#DHEBREW@' AND d_day<=1 AND (d_mon=6 AND MOD(7*d_year+1,19)<7) AND d_year<=5768 AND d_fact NOT IN ('CHAN','BAPL','SLGC','SLGS','ENDL','CENS','RESI','NOTE','ADDR','OBJE','SOUR','PAGE','DATA','TEXT') AND d_file=1 AND d_gid=i_id AND d_file=i_file ORDER BY d_day ASC, d_year DESC [nativecode=sqlite_query() [function.sqlite-query]: no such function: MOD]

my patch use % as modulo in case of sqlite

Discussion

  • Hrotkó Gábor

    Hrotkó Gábor - 2008-01-07

    use with "patch -p5 < sqlite_mod_patch"

     
  • Hrotkó Gábor

    Hrotkó Gábor - 2008-01-07

    Logged In: YES
    user_id=897340
    Originator: YES

    against 4.1.3

     
  • Greg Roach

    Greg Roach - 2008-02-21

    Logged In: YES
    user_id=1466942
    Originator: NO

    I recently coded a far-less elegant patch for sqlite:
    MOD($x,$y)=(($x)-ROUND(($x)/($y)-0.5)*($y))

    I didn't realise sqlite used %. Your solution will be somewhat faster than mine!

    I've just incorporated your suggestion in SVN2604. This will be released as 4.1.4.

    Thanks for your contribution.

     
  • Greg Roach

    Greg Roach - 2008-02-21
    • status: open --> closed-fixed
     
  • Herman

    Herman - 2008-03-23

    Logged In: YES
    user_id=2043408
    Originator: NO

    MySQL, PostGreSQL and SQLserver also use % as the modulo operator (although it's not ANSI and for instance Oracle doesn't know it), so why not make that the standard in phpgedview and try to loose the mod()?

     
  • Greg Roach

    Greg Roach - 2008-03-23

    Logged In: YES
    user_id=1466942
    Originator: NO

    The patch uses the long/workaround function - it was just a quick fix while we investigated alternatives for different DBs.

    4.1.4 uses the % operator. The code used is:

    switch ($DBTYPE) {
    case 'sqlite':
    return "(($x)%($y))";
    default:
    return "MOD($x,$y)";
    }

     

Log in to post a comment.