Skip to content

Commit 6ccbde7

Browse files
committed
Borrow pdo_firebird_utils.cpp from PDO_Firebird
1 parent f15b98d commit 6ccbde7

File tree

4 files changed

+147
-2
lines changed

4 files changed

+147
-2
lines changed

config.m4

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ if test "$PHP_INTERBASE" != "no"; then
5454
fi
5555

5656
AC_DEFINE(HAVE_IBASE,1,[ ])
57-
PHP_NEW_EXTENSION(interbase, interbase.c ibase_query.c ibase_service.c ibase_events.c ibase_blobs.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
57+
PHP_NEW_EXTENSION(interbase, interbase.c ibase_query.c ibase_service.c ibase_events.c ibase_blobs.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1,[cxx])
5858
PHP_SUBST(INTERBASE_SHARED_LIBADD)
59+
60+
PHP_REQUIRE_CXX()
61+
PHP_CXX_COMPILE_STDCXX([11], [mandatory], [PHP_INTERBASE_STDCXX])
62+
63+
PHP_INTERBASE_CXX_SOURCES="pdo_firebird_utils.cpp"
64+
65+
AS_VAR_IF([ext_shared], [no],
66+
[PHP_ADD_SOURCES([$ext_dir],
67+
[$PHP_INTERBASE_CXX_SOURCES],
68+
[$PHP_INTERBASE_STDCXX])],
69+
[PHP_ADD_SOURCES_X([$ext_dir],
70+
[$PHP_INTERBASE_CXX_SOURCES],
71+
[$PHP_INTERBASE_STDCXX],
72+
[shared_objects_interbase],
73+
[yes])])
74+
5975
fi

config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if (PHP_INTERBASE != "no") {
99
(CHECK_LIB("fbclient_ms.lib", "interbase", PHP_PHP_BUILD + "\\interbase\\lib_ms;" + PHP_INTERBASE) ||
1010
CHECK_LIB("gds32_ms.lib", "interbase", PHP_PHP_BUILD + "\\interbase\\lib_ms;" + PHP_INTERBASE))) {
1111

12-
EXTENSION("interbase", "interbase.c ibase_query.c ibase_service.c ibase_events.c ibase_blobs.c", PHP_INTERBASE_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
12+
EXTENSION("interbase", "interbase.c ibase_query.c ibase_service.c ibase_events.c ibase_blobs.c pdo_firebird_utils.cpp", PHP_INTERBASE_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
1313
AC_DEFINE('HAVE_IBASE', 1, 'Have interbase library');
1414
} else {
1515
WARNING("interbase not enabled; libraries and headers not found");

pdo_firebird_utils.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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

pdo_firebird_utils.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
#ifndef PDO_FIREBIRD_UTILS_H
18+
#define PDO_FIREBIRD_UTILS_H
19+
20+
#include <ibase.h>
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
unsigned fb_get_client_version(void);
27+
28+
ISC_TIME fb_encode_time(unsigned hours, unsigned minutes, unsigned seconds, unsigned fractions);
29+
30+
ISC_DATE fb_encode_date(unsigned year, unsigned month, unsigned day);
31+
32+
#if FB_API_VER >= 40
33+
34+
void fb_decode_time_tz(const ISC_TIME_TZ* timeTz, unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions,
35+
unsigned timeZoneBufferLength, char* timeZoneBuffer);
36+
37+
void fb_decode_timestamp_tz(const ISC_TIMESTAMP_TZ* timestampTz,
38+
unsigned* year, unsigned* month, unsigned* day,
39+
unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions,
40+
unsigned timeZoneBufferLength, char* timeZoneBuffer);
41+
42+
#endif
43+
44+
#ifdef __cplusplus
45+
}
46+
#endif
47+
48+
#endif /* PDO_FIREBIRD_UTILS_H */

0 commit comments

Comments
 (0)