fix for modulo error with sqlite at get_anniversary_events
Brought to you by:
canajun2eh,
yalnifj
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
use with "patch -p5 < sqlite_mod_patch"
Logged In: YES
user_id=897340
Originator: YES
against 4.1.3
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.
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()?
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)";
}