-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirebird_utils.cpp
More file actions
804 lines (693 loc) · 23.5 KB
/
firebird_utils.cpp
File metadata and controls
804 lines (693 loc) · 23.5 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
/*
+----------------------------------------------------------------------+
| Authors: Martins Lazdans <marrtins@dqdp.net> |
+----------------------------------------------------------------------+
*/
#include <firebird/Interface.h>
#include <execinfo.h>
#include <iostream>
#include <cstdlib>
#include <string>
#include "fbp/base.hpp"
#include "fbp/database.hpp"
#include "fbp/service.hpp"
#include "fbp/statement.hpp"
#include "fbp/blob.hpp"
#include "firebird_php.hpp"
extern "C" {
#include "ibase.h"
#include "php.h"
#include "zend_exceptions.h"
#include "ext/spl/spl_exceptions.h"
#include "ext/date/php_date.h"
#include "firebird_utils.h"
}
using namespace Firebird;
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;
}
}
}
void fbu_handle_exception(const char *file, size_t line)
{
auto eptr = std::current_exception();
if (!eptr) return;
std::string error_msg;
char msg[1024] = {0};
zval ex;
object_init_ex(&ex, FireBird_Fb_Exception_ce);
zend_update_property_string(FireBird_Fb_Exception_ce,
Z_OBJ(ex), "file_ext", sizeof("file_ext") - 1, file);
zend_update_property_long(FireBird_Fb_Exception_ce,
Z_OBJ(ex), "line_ext", sizeof("line_ext") - 1, line);
try {
std::rethrow_exception(eptr);
} catch (const FbException& e) {
zval rv, errors, ferror_item;
HashTable *ht_errors;
array_init(&errors);
ht_errors = Z_ARRVAL(errors);
FB_SQLSTATE_STRING sqlstate;
ISC_LONG msg_len = 0;
auto status = e.getStatus();
unsigned state = status->getState();
unsigned states[] = {IStatus::STATE_ERRORS, IStatus::STATE_WARNINGS};
const ISC_STATUS* vectors[] = {status->getErrors(), status->getWarnings()};
ISC_LONG error_code = 0;
ISC_INT64 error_code_long = 0;
fb_sqlstate(sqlstate, status->getErrors());
zend_update_property_stringl(FireBird_Fb_Exception_ce,
Z_OBJ(ex), "sqlstate", sizeof("sqlstate") - 1, sqlstate, sizeof(sqlstate));
for (int i = 0; i < 2; ++i)
{
if (state & states[i])
{
const ISC_STATUS* vector = vectors[i];
error_code = isc_sqlcode(&vector[0]);
if (error_code != -999) {
error_code_long = isc_portable_integer((const ISC_UCHAR*)(&vector[1]), 4);
} else {
error_code_long = 0;
}
zend_update_property_long(FireBird_Fb_Exception_ce,
Z_OBJ(ex), "code", sizeof("code") - 1, error_code_long);
while((msg_len = fb_interpret(msg, sizeof(msg), &vector)) != 0) {
object_init_ex(&ferror_item, FireBird_Fb_Error_ce);
update_ferr_props(FireBird_Fb_Error_ce, Z_OBJ(ferror_item), msg, msg_len, error_code, error_code_long);
zend_hash_next_index_insert(ht_errors, &ferror_item);
if (!error_msg.empty())error_msg += "\n";
error_msg += msg;
error_code = isc_sqlcode(&vector[0]);
if (error_code != -999) {
error_code_long = isc_portable_integer((const ISC_UCHAR*)(&vector[1]), 4);
} else {
error_code_long = 0;
}
}
}
}
zend_update_property(FireBird_Fb_Exception_ce,
Z_OBJ(ex), "errors", sizeof("errors") - 1, &errors);
zval_ptr_dtor(&errors);
#if 0
void* buffer[50];
int nptrs = backtrace(buffer, 50);
char** symbols = backtrace_symbols(buffer, nptrs);
std::cerr << "Stack trace:\n";
for (int i = 0; i < nptrs; i++) {
std::cerr << symbols[i] << "\n";
}
free(symbols);
#endif
} catch (const Php_Firebird_Exception& error) {
// TODO: separate database exception from extension exception
error_msg = error.what();
} catch (...) {
error_msg = "Unhandled exception";
}
zend_update_property_stringl(FireBird_Fb_Exception_ce,
Z_OBJ(ex), "message", sizeof("message") - 1, error_msg.c_str(), error_msg.length());
zend_throw_exception_object(&ex);
}
#define fbu_ex_wrap_start() \
try \
{
#define fbu_ex_wrap_end() \
return SUCCESS; \
} \
catch (...) \
{ \
fbu_handle_exception(__FILE__, __LINE__); \
return FAILURE; \
}
// +-----------+------------------------+---------------------+
// | Precision | Data type | Dialect 3 |
// +-----------+------------------------+---------------------+
// | 1 - 4 | NUMERIC | SMALLINT |
// | 1 - 4 | DECIMAL | INTEGER |
// | 5 - 9 | NUMERIC or DECIMAL | INTEGER |
// | 10 - 18 | NUMERIC or DECIMAL | BIGINT |
// | 19 - 38 | NUMERIC or DECIMAL | INT128 |
// +-----------+------------------------+---------------------+
const char* fbu_get_sql_type_name(firebird_var *var, char *buf, size_t buf_size)
{
unsigned short precision = 0;
if (var->scale < 0) {
switch (var->type) {
case SQL_SHORT : precision = 4; break;
case SQL_LONG : precision = 9; break;
case SQL_INT64 : precision = 18; break;
case SQL_INT128 : precision = 38; break;
default: fbp_fatal("BUG: unhandled type: %d with scale: %d", var->type, var->scale);
}
slprintf(buf, buf_size, "NUMERIC(%d,%d)", precision, -var->scale);
return buf;
} else {
switch (var->type)
{
case SQL_TEXT: return "CHAR";
case SQL_VARYING: return "VARCHAR";
case SQL_SHORT: return "SMALLINT";
case SQL_LONG: return "INTEGER";
case SQL_INT64: return "BIGINT";
case SQL_FLOAT: return "FLOAT";
case SQL_DOUBLE: return "DOUBLE PRECISION";
case SQL_DEC16: return "DECFLOAT(16)";
case SQL_DEC34: return "DECFLOAT(34)";
case SQL_INT128: return "INT128";
case SQL_D_FLOAT: return "D_FLOAT";
case SQL_TIMESTAMP: return "TIMESTAMP";
case SQL_TIMESTAMP_TZ: return "TIMESTAMP WITH TIME ZONE";
case SQL_TIMESTAMP_TZ_EX: return "EXTENDED TIMESTAMP WITH TIME ZONE";
case SQL_TYPE_DATE: return "DATE";
case SQL_TYPE_TIME: return "TIME";
case SQL_TIME_TZ: return "TIME WITH TIME ZONE";
case SQL_TIME_TZ_EX: return "EXTENDED TIME WITH TIME ZONE";
case SQL_BLOB: return "BLOB";
case SQL_ARRAY: return "ARRAY";
case SQL_QUAD: return "QUAD";
case SQL_BOOLEAN: return "BOOLEAN";
case SQL_NULL: return "NULL";
default: return "UNKNOWN";
}
}
}
void fbu_xpb_insert_object(IXpbBuilder* xpb, zval *obj, zend_class_entry *ce,
const firebird_xpb_zmap *xpb_zmap)
{
zend_string *prop_name = NULL;
zend_property_info *prop_info = NULL;
zval rv, *val, *checkval;
int i;
ThrowStatusWrapper st(fb_get_master_interface()->getStatus());
for (int i = 0; i < xpb_zmap->count; i++) {
prop_name = zend_string_init(xpb_zmap->names[i], strlen(xpb_zmap->names[i]), 1);
#ifdef PHP_DEBUG
if (!zend_hash_exists(&ce->properties_info, prop_name)) {
fbp_fatal("BUG! Property %s does not exist for %s::%s. Verify xpb_zmap",
xpb_zmap->names[i], ZSTR_VAL(ce->name), xpb_zmap->names[i]);
zend_string_release(prop_name);
continue;
}
#endif
prop_info = zend_get_property_info(ce, prop_name, 0);
checkval = OBJ_PROP(Z_OBJ_P(obj), prop_info->offset);
if (Z_ISUNDEF_P(checkval)) {
FBDEBUG("property: %s is uninitialized", xpb_zmap->names[i]);
zend_string_release(prop_name);
continue;
}
val = zend_read_property_ex(ce, Z_OBJ_P(obj), prop_name, 0, &rv);
zend_string_release(prop_name);
switch (Z_TYPE_P(val)) {
case IS_STRING:
FBDEBUG("property: %s is string: `%s`", xpb_zmap->names[i], Z_STRVAL_P(val));
// (StatusType* status, unsigned char tag, const char* str)
xpb->insertString(&st, xpb_zmap->tags[i], Z_STRVAL_P(val));
break;
case IS_LONG:
FBDEBUG("property: %s is long: `%u`", xpb_zmap->names[i], Z_LVAL_P(val));
xpb->insertInt(&st, xpb_zmap->tags[i], (int)Z_LVAL_P(val));
break;
case IS_TRUE:
FBDEBUG("property: %s is true", xpb_zmap->names[i]);
xpb->insertInt(&st, xpb_zmap->tags[i], 1);
break;
case IS_FALSE:
FBDEBUG("property: %s is false", xpb_zmap->names[i]);
xpb->insertInt(&st, xpb_zmap->tags[i], 0);
break;
case IS_NULL:
FBDEBUG("property: %s is null", xpb_zmap->names[i]);
break;
default:
fbp_fatal("BUG! Unhandled: type %s for property %s::%s",
zend_get_type_by_const(Z_TYPE_P(val)), ZSTR_VAL(ce->name), xpb_zmap->names[i]);
break;
}
}
}
extern "C" {
// Parse NUMERIC() to signed int representation
int fbu_string_to_numeric(const char *s, size_t slen, int scale, uint64_t max,
int *sign, int *exp, uint64_t *res)
{
const char* p = s;
const char *end = s + slen;
*sign = *exp = *res = 0;
if (!slen) return STRNUM_PARSE_OK;
if (*p == '-') {
*sign = -1;
p++;
} else if (*p == '+') {
*sign = 1;
p++;
} else {
*sign = 1;
}
if (*sign == -1) max += 1;
int fraction = 0;
uint64_t &r = *res;
while (p < end) {
if (*p >= '0' && *p <= '9') {
r = r * 10 + (*p - '0');
p++;
if (fraction) {
scale++;
--*exp;
}
} else if (*p == '.') {
if (fraction) return STRNUM_PARSE_ERROR;
fraction = 1;
p++;
continue;
} else {
return STRNUM_PARSE_ERROR;
}
if (r > max) return STRNUM_PARSE_OVERFLOW;
}
while (scale < 0) {
r *= 10;
if (r > max) return STRNUM_PARSE_OVERFLOW;
scale++;
--*exp;
}
return STRNUM_PARSE_OK;
}
// Returns the client version. 0 bytes are minor version, 1 bytes are major version.
unsigned fbu_get_client_version(void)
{
IUtil* util = fb_get_master_interface()->getUtilInterface();
return util->getClientVersion();
}
void fbu_init_date_object(const char *tzbuff, zval *o)
{
zval tzo, tzo_arg;
php_date_instantiate(php_date_get_date_ce(), o);
if (tzbuff) {
ZVAL_STRING(&tzo_arg, tzbuff);
object_init_with_constructor(&tzo, php_date_get_timezone_ce(), 1, &tzo_arg, nullptr);
php_date_initialize(Z_PHPDATE_P(o), "", 0, NULL, &tzo, 0);
zval_ptr_dtor(&tzo_arg);
zval_ptr_dtor(&tzo);
} else {
php_date_initialize(Z_PHPDATE_P(o), "", 0, NULL, NULL, 0);
}
// zend_string *tt = php_format_date(ff, strlen(ff), ((ISC_TIME_TZ *)data)->utc_time, 0);
// php_date_time_set(&new_object, h, i, s, ms, return_value);
// php_date_initialize_from_ts_long(date_obj, 0, 0);
}
using namespace FBP;
int fbu_is_valid_dbh(size_t dbh)
{
return (dbh && dbh <= FBG(db_list).size() && FBG(db_list)[dbh - 1]);
}
static inline std::unique_ptr<Database>& get_db_ptr(std::size_t h, const char *file_name, size_t line_num)
{
if (fbu_is_valid_dbh(h)) {
return FBG(db_list)[h - 1];
} else {
throw Php_Firebird_Exception(zend_ce_error, "Invalid database handle");
}
}
int fbu_is_valid_svh(size_t svh)
{
return (svh && svh <= FBG(sv_list).size() && FBG(sv_list)[svh - 1]);
}
static inline std::unique_ptr<Service>& get_sv_ptr(std::size_t h, const char *file_name, size_t line_num)
{
if (fbu_is_valid_svh(h)) {
return FBG(sv_list)[h - 1];
} else {
throw Php_Firebird_Exception(zend_ce_error, "Invalid service manager handle");
}
}
#define get_db(h) get_db_ptr(h, __FILE__, __LINE__)
#define get_sv(h) get_sv_ptr(h, __FILE__, __LINE__)
int fbu_is_valid_trh(size_t dbh, size_t trh)
{
try {
get_db(dbh)->get_transaction(trh);
return 1;
} catch(...) {
return 0;
}
}
int fbu_is_valid_sth(size_t dbh, size_t sth)
{
try {
get_db(dbh)->get_statement(sth);
return 1;
} catch(...) {
return 0;
}
}
int fbu_database_init(size_t *dbh)
{
FBDEBUG("%s()", __func__);
fbu_ex_wrap_start();
FBG(db_list).emplace_back(new Database());
*dbh = FBG(db_list).size();
FBDEBUG(" dbh=%zu", *dbh);
fbu_ex_wrap_end();
}
int fbu_database_connect(size_t dbh, zval *args)
{
FBDEBUG("%s(dbh=%zu)", __func__, dbh);
fbu_ex_wrap_start();
get_db(dbh)->connect(args);
fbu_ex_wrap_end();
}
int fbu_database_create(size_t dbh, zval *args)
{
FBDEBUG("%s(dbh=%zu)", __func__, dbh);
fbu_ex_wrap_start();
get_db(dbh)->create(args);
fbu_ex_wrap_end();
}
int fbu_database_disconnect(size_t dbh)
{
FBDEBUG("%s(dbh=%zu)", __func__, dbh);
fbu_ex_wrap_start();
get_db(dbh)->disconnect();
get_db(dbh).reset();
fbu_ex_wrap_end();
}
int fbu_database_drop(size_t dbh)
{
FBDEBUG("%s(dbh=%zu)", __func__, dbh);
fbu_ex_wrap_start();
get_db(dbh)->drop();
get_db(dbh).reset();
fbu_ex_wrap_end();
}
int fbu_database_execute_create(size_t dbh, unsigned int len_sql, const char *sql)
{
FBDEBUG("%s(dbh=%zu)", __func__, dbh);
fbu_ex_wrap_start();
get_db(dbh)->execute_create(len_sql, sql);
fbu_ex_wrap_end();
}
int fbu_database_free(size_t dbh)
{
FBDEBUG("%s(dbh=%zu)", __func__, dbh);
fbu_ex_wrap_start();
get_db(dbh).reset();
fbu_ex_wrap_end();
}
int fbu_database_get_info(size_t dbh, zval *db_info)
{
FBDEBUG("%s(dbh=%zu)", __func__, dbh);
fbu_ex_wrap_start();
get_db(dbh)->get_info(db_info);
fbu_ex_wrap_end();
}
int fbu_transaction_init(size_t dbh, size_t *trh)
{
FBDEBUG("%s(dbh=%zu)", __func__, dbh);
fbu_ex_wrap_start();
*trh = get_db(dbh)->transaction_init();
fbu_ex_wrap_end();
}
int fbu_transaction_get_limbo(size_t dbh, zval *tr_arr, short max_count)
{
FBDEBUG("%s(dbh=%zu)", __func__, dbh);
fbu_ex_wrap_start();
get_db(dbh)->get_limbo_transactions(tr_arr, max_count);
fbu_ex_wrap_end();
}
int fbu_transaction_reconnect(size_t dbh, ISC_ULONG id, size_t *trh)
{
FBDEBUG("%s(dbh=%zu)", __func__, dbh);
fbu_ex_wrap_start();
*trh = get_db(dbh)->transaction_reconnect(id);
fbu_ex_wrap_end();
}
int fbu_transaction_get_info(size_t dbh, size_t trh, const firebird_trans_info **info)
{
FBDEBUG("%s(dbh=%zu, trh=%zu)", __func__, dbh, trh);
fbu_ex_wrap_start();
*info = get_db(dbh)->get_transaction(trh)->get_info();
fbu_ex_wrap_end();
}
int fbu_transaction_free(size_t dbh, size_t trh)
{
FBDEBUG("%s(dbh=%zu, trh=%zu)", __func__, dbh, trh);
fbu_ex_wrap_start();
get_db(dbh)->transaction_free(trh);
fbu_ex_wrap_end();
}
int fbu_transaction_finalize(size_t dbh, size_t trh, int mode)
{
FBDEBUG("%s(dbh=%zu, trh=%zu)", __func__, dbh, trh);
fbu_ex_wrap_start();
get_db(dbh)->get_transaction(trh)->finalize(mode);
fbu_ex_wrap_end();
}
int fbu_transaction_start(size_t dbh, size_t trh, const firebird_tbuilder *builder)
{
FBDEBUG("%s(dbh=%zu, trh=%zu)", __func__, dbh, trh);
fbu_ex_wrap_start();
get_db(dbh)->get_transaction(trh)->start(builder);
fbu_ex_wrap_end();
}
int fbu_transaction_execute(size_t dbh, size_t trh, size_t len_sql, const char *sql)
{
FBDEBUG("%s(dbh=%zu, trh=%zu)", __func__, dbh, trh);
fbu_ex_wrap_start();
get_db(dbh)->get_transaction(trh)->execute(len_sql, sql);
fbu_ex_wrap_end();
}
int fbu_transaction_prepare(size_t dbh, size_t trh)
{
FBDEBUG("%s(dbh=%zu, trh=%zu)", __func__, dbh, trh);
fbu_ex_wrap_start();
get_db(dbh)->get_transaction(trh)->prepare();
fbu_ex_wrap_end();
}
int fbu_statement_init(size_t dbh, size_t trh, size_t *sth)
{
FBDEBUG("%s(dbh=%zu, trh=%zu)", __func__, dbh, trh);
fbu_ex_wrap_start();
*sth = get_db(dbh)->statement_init(trh);
fbu_ex_wrap_end();
}
int fbu_statement_get_info(size_t dbh, size_t sth, const firebird_stmt_info **info)
{
FBDEBUG("%s(dbh=%zu, sth=%zu)", __func__, dbh, sth);
fbu_ex_wrap_start();
*info = get_db(dbh)->get_statement(sth)->get_info();
fbu_ex_wrap_end();
}
int fbu_statement_free(size_t dbh, size_t sth)
{
FBDEBUG("%s(dbh=%zu, sth=%zu)", __func__, dbh, sth);
fbu_ex_wrap_start();
get_db(dbh)->statement_free(sth);
fbu_ex_wrap_end();
}
int fbu_statement_prepare(size_t dbh, size_t sth, unsigned len_sql, const char *sql)
{
FBDEBUG("%s(dbh=%zu, sth=%zu)", __func__, dbh, sth);
fbu_ex_wrap_start();
get_db(dbh)->get_statement(sth)->prepare(len_sql, sql);
fbu_ex_wrap_end();
}
int fbu_statement_bind(size_t dbh, size_t sth, zval *b_vars, unsigned int num_bind_args)
{
FBDEBUG("%s(dbh=%zu, sth=%zu)", __func__, dbh, sth);
fbu_ex_wrap_start();
get_db(dbh)->get_statement(sth)->bind(b_vars, num_bind_args);
fbu_ex_wrap_end();
}
int fbu_statement_open_cursor(size_t dbh, size_t sth)
{
// TODO: check if already open
FBDEBUG("%s(dbh=%zu, sth=%zu)", __func__, dbh, sth);
fbu_ex_wrap_start();
get_db(dbh)->get_statement(sth)->open_cursor();
fbu_ex_wrap_end();
}
int fbu_statement_fetch_next(size_t dbh, size_t sth, int *istatus)
{
FBDEBUG("%s(dbh=%zu, sth=%zu)", __func__, dbh, sth);
fbu_ex_wrap_start();
*istatus = get_db(dbh)->get_statement(sth)->fetch_next();
fbu_ex_wrap_end();
}
int fbu_statement_output_buffer_to_array(size_t dbh, size_t sth, int flags, HashTable **ht)
{
FBDEBUG("%s(dbh=%zu, sth=%zu)", __func__, dbh, sth);
fbu_ex_wrap_start();
get_db(dbh)->get_statement(sth)->output_buffer_to_array(flags, ht);
fbu_ex_wrap_end();
}
int fbu_statement_execute(size_t dbh, size_t sth)
{
FBDEBUG("%s(dbh=%zu, sth=%zu)", __func__, dbh, sth);
fbu_ex_wrap_start();
get_db(dbh)->get_statement(sth)->execute();
fbu_ex_wrap_end();
}
int fbu_statement_close_cursor(size_t dbh, size_t sth)
{
FBDEBUG("%s(dbh=%zu, sth=%zu)", __func__, dbh, sth);
fbu_ex_wrap_start();
get_db(dbh)->get_statement(sth)->close_cursor();
fbu_ex_wrap_end();
}
int fbu_statement_get_var_info(size_t dbh, size_t sth, int in, unsigned int index, zval *var_info)
{
FBDEBUG("%s(dbh=%zu, sth=%zu)", __func__, dbh, sth);
fbu_ex_wrap_start();
get_db(dbh)->get_statement(sth)->get_var_info(in, index, var_info);
fbu_ex_wrap_end();
}
int fbu_blob_init(size_t dbh, size_t trh, size_t *blh)
{
FBDEBUG("%s(dbh=%zu, trh=%zu)", __func__, dbh, trh);
fbu_ex_wrap_start();
*blh = get_db(dbh)->blob_init(trh);
fbu_ex_wrap_end();
}
int fbu_blob_get_info(size_t dbh, size_t blh, const firebird_blob_info **info)
{
FBDEBUG("%s(dbh=%zu, blh=%zu)", __func__, dbh, blh);
fbu_ex_wrap_start();
*info = get_db(dbh)->get_blob(blh)->get_info();
fbu_ex_wrap_end();
}
int fbu_blob_create(size_t dbh, size_t blh)
{
FBDEBUG("%s(dbh=%zu, blh=%zu)", __func__, dbh, blh);
fbu_ex_wrap_start();
get_db(dbh)->get_blob(blh)->create();
fbu_ex_wrap_end();
}
int fbu_blob_open(size_t dbh, size_t blh, ISC_QUAD *bl_id)
{
FBDEBUG("%s(dbh=%zu, blh=%zu)", __func__, dbh, blh);
fbu_ex_wrap_start();
get_db(dbh)->get_blob(blh)->open(bl_id);
fbu_ex_wrap_end();
}
int fbu_blob_free(size_t dbh, size_t blh)
{
FBDEBUG("%s(dbh=%zu, blh=%zu)", __func__, dbh, blh);
fbu_ex_wrap_start();
get_db(dbh)->blob_free(blh);
fbu_ex_wrap_end();
}
int fbu_blob_put(size_t dbh, size_t blh, unsigned int buf_size, const char *buf)
{
FBDEBUG("%s(dbh=%zu, blh=%zu)", __func__, dbh, blh);
fbu_ex_wrap_start();
get_db(dbh)->get_blob(blh)->put_contents(buf_size, buf);
fbu_ex_wrap_end();
}
int fbu_blob_close(size_t dbh, size_t blh)
{
FBDEBUG("%s(dbh=%zu, blh=%zu)", __func__, dbh, blh);
fbu_ex_wrap_start();
get_db(dbh)->get_blob(blh)->close();
fbu_ex_wrap_end();
}
int fbu_blob_cancel(size_t dbh, size_t blh)
{
FBDEBUG("%s(dbh=%zu, blh=%zu)", __func__, dbh, blh);
fbu_ex_wrap_start();
get_db(dbh)->get_blob(blh)->cancel();
fbu_ex_wrap_end();
}
int fbu_blob_get(size_t dbh, size_t blh, int max_len, zend_string **buf)
{
FBDEBUG("%s(dbh=%zu, blh=%zu)", __func__, dbh, blh);
fbu_ex_wrap_start();
get_db(dbh)->get_blob(blh)->get_contents(max_len, buf);
fbu_ex_wrap_end();
}
int fbu_blob_seek(size_t dbh, size_t blh, int mode, int offset, int *new_offset)
{
FBDEBUG("%s(dbh=%zu, blh=%zu)", __func__, dbh, blh);
fbu_ex_wrap_start();
get_db(dbh)->get_blob(blh)->seek(mode, offset, new_offset);
fbu_ex_wrap_end();
}
int fbu_service_init(size_t *svh)
{
FBDEBUG("%s()", __func__);
fbu_ex_wrap_start();
FBG(sv_list).emplace_back(new Service());
*svh = FBG(sv_list).size();
FBDEBUG(" svh=%zu", *svh);
fbu_ex_wrap_end();
}
int fbu_service_free(size_t svh)
{
FBDEBUG("%s(svh=%zu)", __func__, svh);
fbu_ex_wrap_start();
get_sv(svh).reset();
fbu_ex_wrap_end();
}
int fbu_service_connect(size_t svh, zval *args)
{
FBDEBUG("%s(svh=%zu)", __func__, svh);
fbu_ex_wrap_start();
get_sv(svh)->connect(args);
fbu_ex_wrap_end();
}
int fbu_service_disconnect(size_t svh)
{
FBDEBUG("%s(svh=%zu)", __func__, svh);
fbu_ex_wrap_start();
get_sv(svh)->disconnect();
get_sv(svh).reset();
fbu_ex_wrap_end();
}
int fbu_service_get_server_info(size_t svh, zval *Server_Info)
{
FBDEBUG("%s(svh=%zu)", __func__, svh);
fbu_ex_wrap_start();
get_sv(svh)->get_info(Server_Info);
fbu_ex_wrap_end();
}
int fbu_service_get_users(size_t svh, zval *users)
{
FBDEBUG("%s(svh=%zu)", __func__, svh);
fbu_ex_wrap_start();
get_sv(svh)->get_users(users);
fbu_ex_wrap_end();
}
int fbu_service_add_user(size_t svh, zval *user_info)
{
FBDEBUG("%s(svh=%zu)", __func__, svh);
fbu_ex_wrap_start();
get_sv(svh)->add_user(user_info);
fbu_ex_wrap_end();
}
int fbu_service_modify_user(size_t svh, zval *user_info)
{
FBDEBUG("%s(svh=%zu)", __func__, svh);
fbu_ex_wrap_start();
get_sv(svh)->modify_user(user_info);
fbu_ex_wrap_end();
}
int fbu_service_delete_user(size_t svh, const char *username, size_t username_len)
{
FBDEBUG("%s(svh=%zu)", __func__, svh);
fbu_ex_wrap_start();
get_sv(svh)->delete_user(username, username_len);
fbu_ex_wrap_end();
}
int fbu_service_get_db_info(size_t svh, zval *server_db_info)
{
FBDEBUG("%s(svh=%zu)", __func__, svh);
fbu_ex_wrap_start();
get_sv(svh)->get_db_info(server_db_info);
fbu_ex_wrap_end();
}
} // extern "C"