-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathfirebird_utils.cpp
More file actions
169 lines (143 loc) · 5.78 KB
/
firebird_utils.cpp
File metadata and controls
169 lines (143 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Simonov Denis <sim-mail@list.ru> |
| Author: Martins Lazdans <marrtins@dqdp.net> |
+----------------------------------------------------------------------+
*/
#include <ibase.h>
#if FB_API_VER >= 30
#include <firebird/Interface.h>
#include <cstring>
#include "php.h"
#include "firebird_utils.h"
#include "php_ibase_includes.h"
/* Returns the client version. 0 bytes are minor version, 1 bytes are major version. */
extern "C" unsigned fbu_get_client_version(void *master_ptr)
{
Firebird::IMaster* master = (Firebird::IMaster*)master_ptr;
Firebird::IUtil* util = master->getUtilInterface();
return util->getClientVersion();
}
extern "C" ISC_TIME fbu_encode_time(void *master_ptr, unsigned hours, unsigned minutes, unsigned seconds, unsigned fractions)
{
Firebird::IMaster* master = (Firebird::IMaster*)master_ptr;
Firebird::IUtil* util = master->getUtilInterface();
return util->encodeTime(hours, minutes, seconds, fractions);
}
extern "C" ISC_DATE fbu_encode_date(void *master_ptr, unsigned year, unsigned month, unsigned day)
{
Firebird::IMaster* master = (Firebird::IMaster*)master_ptr;
Firebird::IUtil* util = master->getUtilInterface();
return util->encodeDate(year, month, day);
}
static void fbu_copy_status(const ISC_STATUS* from, ISC_STATUS* to, size_t maxLength)
{
for(size_t i=0; i < maxLength; ++i) {
memcpy(to + i, from + i, sizeof(ISC_STATUS));
if (from[i] == isc_arg_end) {
break;
}
}
}
#endif // FB_API_VER >= 30
#if FB_API_VER >= 40
/* Decodes a time with time zone into its time components. */
extern "C" void fbu_decode_time_tz(void *master_ptr, const ISC_TIME_TZ* timeTz, unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions,
unsigned timeZoneBufferLength, char* timeZoneBuffer)
{
Firebird::IMaster* master = (Firebird::IMaster*)master_ptr;
Firebird::IUtil* util = master->getUtilInterface();
Firebird::IStatus* status = master->getStatus();
Firebird::CheckStatusWrapper st(status);
util->decodeTimeTz(&st, timeTz, hours, minutes, seconds, fractions,
timeZoneBufferLength, timeZoneBuffer);
}
/* Decodes a timestamp with time zone into its date and time components */
extern "C" void fbu_decode_timestamp_tz(void *master_ptr, const ISC_TIMESTAMP_TZ* timestampTz,
unsigned* year, unsigned* month, unsigned* day,
unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions,
unsigned timeZoneBufferLength, char* timeZoneBuffer)
{
Firebird::IMaster* master = (Firebird::IMaster*)master_ptr;
Firebird::IUtil* util = master->getUtilInterface();
Firebird::IStatus* status = master->getStatus();
Firebird::CheckStatusWrapper st(status);
util->decodeTimeStampTz(&st, timestampTz, year, month, day,
hours, minutes, seconds, fractions,
timeZoneBufferLength, timeZoneBuffer);
}
extern "C" void fbu_release_statement(void *statement_ptr)
{
Firebird::IStatement* statement = (Firebird::IStatement *)statement_ptr;
if (statement) statement->release();
}
extern "C" int fbu_insert_aliases(void *master_ptr, ISC_STATUS* st, ibase_query *ib_query, void *statement_ptr)
{
Firebird::IMaster* master = (Firebird::IMaster*)master_ptr;
Firebird::ThrowStatusWrapper status(master->getStatus());
Firebird::IStatement* statement = (Firebird::IStatement *)statement_ptr;
Firebird::IMessageMetadata* meta = NULL;
ISC_STATUS res;
try {
meta = statement->getOutputMetadata(&status);
unsigned cols = meta->getCount(&status);
assert(cols == ib_query->out_fields_count);
for (unsigned i = 0; i < cols; ++i)
{
_php_ibase_insert_alias(ib_query->ht_aliases, meta->getAlias(&status, i));
}
meta->release();
}
catch (const Firebird::FbException& error)
{
if (status.hasData()) {
fbu_copy_status((const ISC_STATUS*)status.getErrors(), st, 20);
return st[1];
}
}
status.dispose();
return 0;
}
extern "C" int fbu_insert_field_info(void *master_ptr, ISC_STATUS* st, int is_outvar, int num,
zval *into_array, void *statement_ptr)
{
Firebird::IMaster* master = (Firebird::IMaster*)master_ptr;
Firebird::ThrowStatusWrapper status(master->getStatus());
Firebird::IStatement* statement = (Firebird::IStatement *)statement_ptr;
Firebird::IMessageMetadata* meta = NULL;
ISC_STATUS res;
try {
if(is_outvar) {
meta = statement->getOutputMetadata(&status);
} else {
meta = statement->getInputMetadata(&status);
}
add_index_string(into_array, 0, meta->getField(&status, num));
add_assoc_string(into_array, "name", meta->getField(&status, num));
add_index_string(into_array, 1, meta->getAlias(&status, num));
add_assoc_string(into_array, "alias", meta->getAlias(&status, num));
add_index_string(into_array, 2, meta->getRelation(&status, num));
add_assoc_string(into_array, "relation", meta->getRelation(&status, num));
meta->release();
}
catch (const Firebird::FbException& error)
{
if (status.hasData()) {
fbu_copy_status((const ISC_STATUS*)status.getErrors(), st, 20);
return st[1];
}
}
status.dispose();
return 0;
}
#endif // FB_API_VER >= 40