|
| 1 | +/* |
| 2 | + +----------------------------------------------------------------------+ |
| 3 | + | Copyright (c) The PHP Group | |
| 4 | + +----------------------------------------------------------------------+ |
| 5 | + | This source file is subject to version 3.01 of the PHP license, | |
| 6 | + | that is bundled with this package in the file LICENSE, and is | |
| 7 | + | available through the world-wide-web at the following url: | |
| 8 | + | https://www.php.net/license/3_01.txt | |
| 9 | + | If you did not receive a copy of the PHP license and are unable to | |
| 10 | + | obtain it through the world-wide-web, please send a note to | |
| 11 | + | [email protected] so we can mail you a copy immediately. | |
| 12 | + +----------------------------------------------------------------------+ |
| 13 | + | Author: Simonov Denis <[email protected]> | |
| 14 | + +----------------------------------------------------------------------+ |
| 15 | +*/ |
| 16 | + |
| 17 | +#include "pdo_firebird_utils.h" |
| 18 | +#include <firebird/Interface.h> |
| 19 | +#include <cstring> |
| 20 | + |
| 21 | +/* Returns the client version. 0 bytes are minor version, 1 bytes are major version. */ |
| 22 | +extern "C" unsigned fb_get_client_version(void) |
| 23 | +{ |
| 24 | + Firebird::IMaster* master = Firebird::fb_get_master_interface(); |
| 25 | + Firebird::IUtil* util = master->getUtilInterface(); |
| 26 | + return util->getClientVersion(); |
| 27 | +} |
| 28 | + |
| 29 | +extern "C" ISC_TIME fb_encode_time(unsigned hours, unsigned minutes, unsigned seconds, unsigned fractions) |
| 30 | +{ |
| 31 | + Firebird::IMaster* master = Firebird::fb_get_master_interface(); |
| 32 | + Firebird::IUtil* util = master->getUtilInterface(); |
| 33 | + return util->encodeTime(hours, minutes, seconds, fractions); |
| 34 | +} |
| 35 | + |
| 36 | +extern "C" ISC_DATE fb_encode_date(unsigned year, unsigned month, unsigned day) |
| 37 | +{ |
| 38 | + Firebird::IMaster* master = Firebird::fb_get_master_interface(); |
| 39 | + Firebird::IUtil* util = master->getUtilInterface(); |
| 40 | + return util->encodeDate(year, month, day); |
| 41 | +} |
| 42 | + |
| 43 | +#if FB_API_VER >= 40 |
| 44 | +static void fb_copy_status(const ISC_STATUS* from, ISC_STATUS* to, size_t maxLength) |
| 45 | +{ |
| 46 | + for(size_t i=0; i < maxLength; ++i) { |
| 47 | + memcpy(to + i, from + i, sizeof(ISC_STATUS)); |
| 48 | + if (from[i] == isc_arg_end) { |
| 49 | + break; |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +/* Decodes a time with time zone into its time components. */ |
| 55 | +extern "C" void fb_decode_time_tz(const ISC_TIME_TZ* timeTz, unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions, |
| 56 | + unsigned timeZoneBufferLength, char* timeZoneBuffer) |
| 57 | +{ |
| 58 | + Firebird::IMaster* master = Firebird::fb_get_master_interface(); |
| 59 | + Firebird::IUtil* util = master->getUtilInterface(); |
| 60 | + Firebird::IStatus* status = master->getStatus(); |
| 61 | + Firebird::CheckStatusWrapper st(status); |
| 62 | + util->decodeTimeTz(&st, timeTz, hours, minutes, seconds, fractions, |
| 63 | + timeZoneBufferLength, timeZoneBuffer); |
| 64 | +} |
| 65 | + |
| 66 | +/* Decodes a timestamp with time zone into its date and time components */ |
| 67 | +extern "C" void fb_decode_timestamp_tz(const ISC_TIMESTAMP_TZ* timestampTz, |
| 68 | + unsigned* year, unsigned* month, unsigned* day, |
| 69 | + unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions, |
| 70 | + unsigned timeZoneBufferLength, char* timeZoneBuffer) |
| 71 | +{ |
| 72 | + Firebird::IMaster* master = Firebird::fb_get_master_interface(); |
| 73 | + Firebird::IUtil* util = master->getUtilInterface(); |
| 74 | + Firebird::IStatus* status = master->getStatus(); |
| 75 | + Firebird::CheckStatusWrapper st(status); |
| 76 | + util->decodeTimeStampTz(&st, timestampTz, year, month, day, |
| 77 | + hours, minutes, seconds, fractions, |
| 78 | + timeZoneBufferLength, timeZoneBuffer); |
| 79 | +} |
| 80 | + |
| 81 | +#endif |
0 commit comments