|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pike __REAL_VERSION__ |
|
#if constant(Mysql.mysql) |
|
inherit Mysql.mysql; |
|
|
|
|
string quote(string s) |
{ |
return(replace(s, |
({ "\\", "\"", "\0", "\'", "\n", "\r" }), |
({ "\\\\", "\\\"", "\\0", "\\\'", "\\n", "\\r" }))); |
} |
|
|
|
|
|
private constant timezone = localtime (0)->timezone; |
|
|
|
|
|
|
|
|
string encode_time (int time, void|int date) |
{ |
if (date) { |
if (!time) return "000000"; |
mapping(string:int) ct = localtime (time); |
return sprintf ("%02d%02d%02d", ct->hour, ct->min, ct->sec); |
} |
else return sprintf ("%02d%02d%02d", time / 3600 % 24, time / 60 % 60, time % 60); |
} |
|
|
|
|
|
string encode_date (int time) |
{ |
if (!time) return "00000000"; |
mapping(string:int) ct = localtime (time); |
return sprintf ("%04d%02d%02d", ct->year + 1900, ct->mon + 1, ct->mday); |
} |
|
|
|
|
|
string encode_datetime (int time) |
{ |
if (!time) return "00000000000000"; |
mapping(string:int) ct = localtime (time); |
return sprintf ("%04d%02d%02d%02d%02d%02d", |
ct->year + 1900, ct->mon + 1, ct->mday, |
ct->hour, ct->min, ct->sec); |
} |
|
|
|
|
|
|
int decode_time (string timestr, void|int date) |
{ |
int hour = 0, min = 0, sec = 0; |
if (sscanf (timestr, "%d:%d:%d", hour, min, sec) <= 1) |
sscanf (timestr, "%2d%2d%2d", hour, min, sec); |
if (date && (hour || min || sec)) { |
mapping(string:int) ct = localtime (date); |
return mktime (sec, min, hour, ct->mday, ct->mon, ct->year, ct->isdst, ct->timezone); |
} |
else return (hour * 60 + min) * 60 + sec; |
} |
|
|
|
|
|
int decode_date (string datestr) |
{ |
int year = 0, mon = 0, mday = 0, n; |
n = sscanf (datestr, "%d-%d-%d", year, mon, mday); |
if (n <= 1) n = sscanf (datestr, "%4d%2d%2d", year, mon, mday); |
if (year || mon || mday) |
return mktime (0, 0, 0, n == 3 ? mday : 1, n >= 2 && mon - 1, year - 1900, |
-1, timezone); |
else return 0; |
} |
|
|
|
|
|
int decode_datetime (string timestr) |
{ |
array(string) a = timestr / " "; |
if (sizeof (a) == 2) |
return decode_date (a[0]) + decode_time (a[1]); |
else { |
int n = sizeof (timestr); |
if (n >= 12) |
return decode_date (timestr[..n-7]) + decode_time (timestr[n-6..n-1]); |
else |
return decode_date (timestr); |
} |
} |
|
int|object big_query(string q, mapping(string|int:mixed)|void bindings) |
{ |
if (!bindings) |
return ::big_query(q); |
return ::big_query(.sql_util.emulate_bindings(q,bindings,this_object())); |
} |
|
#else /* !constant(Mysql.mysql) */ |
#error "Mysql support not available.\n" |
#endif /* constant(Mysql.mysql) */ |
|
|