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 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: Simonov Denis <sim-mail@list.ru> |
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. */
fb_get_client_version(void)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
fb_encode_time(unsigned hours,unsigned minutes,unsigned seconds,unsigned fractions)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
fb_encode_date(unsigned year,unsigned month,unsigned day)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
fb_copy_status(const ISC_STATUS * from,ISC_STATUS * to,size_t maxLength)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. */
fb_decode_time_tz(ISC_STATUS * isc_status,const ISC_TIME_TZ * timeTz,unsigned * hours,unsigned * minutes,unsigned * seconds,unsigned * fractions,unsigned timeZoneBufferLength,char * timeZoneBuffer)55 extern "C" ISC_STATUS fb_decode_time_tz(ISC_STATUS* isc_status, 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 if (st.hasData()) {
65 fb_copy_status((const ISC_STATUS*)st.getErrors(), isc_status, 20);
66 }
67 status->dispose();
68 return isc_status[1];
69 }
70
71 /* Decodes a timestamp with time zone into its date and time components */
fb_decode_timestamp_tz(ISC_STATUS * isc_status,const ISC_TIMESTAMP_TZ * timestampTz,unsigned * year,unsigned * month,unsigned * day,unsigned * hours,unsigned * minutes,unsigned * seconds,unsigned * fractions,unsigned timeZoneBufferLength,char * timeZoneBuffer)72 extern "C" ISC_STATUS fb_decode_timestamp_tz(ISC_STATUS* isc_status, const ISC_TIMESTAMP_TZ* timestampTz,
73 unsigned* year, unsigned* month, unsigned* day,
74 unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions,
75 unsigned timeZoneBufferLength, char* timeZoneBuffer)
76 {
77 Firebird::IMaster* master = Firebird::fb_get_master_interface();
78 Firebird::IUtil* util = master->getUtilInterface();
79 Firebird::IStatus* status = master->getStatus();
80 Firebird::CheckStatusWrapper st(status);
81 util->decodeTimeStampTz(&st, timestampTz, year, month, day,
82 hours, minutes, seconds, fractions,
83 timeZoneBufferLength, timeZoneBuffer);
84 if (st.hasData()) {
85 fb_copy_status((const ISC_STATUS*)st.getErrors(), isc_status, 20);
86 }
87 status->dispose();
88 return isc_status[1];
89 }
90
91 #endif
92