forked from FirebirdSQL/php-firebird
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirebird_utils.h
More file actions
executable file
·1623 lines (1478 loc) · 51.6 KB
/
firebird_utils.h
File metadata and controls
executable file
·1623 lines (1478 loc) · 51.6 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
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* SPDX-License-Identifier: PHP-3.01
* SPDX-FileCopyrightText: The PHP Group and contributors (see CREDITS) */
#ifndef FIREBIRD_UTILS_H
#define FIREBIRD_UTILS_H
#ifdef __cplusplus
extern "C" {
#endif
/* Firebird 3.0+ OO API required; FB_API_VER >= 30 enforced at configure time via config.m4. */
#include <ibase.h>
#include "php_fbird_includes.h"
unsigned fbu_get_client_version(void *master_ptr);
ISC_TIME fbu_encode_time(void *master_ptr, unsigned hours, unsigned minutes,
unsigned seconds, unsigned fractions);
ISC_DATE fbu_encode_date(void *master_ptr, unsigned year, unsigned month, unsigned day);
/**
* Extract SQLCODE from a Firebird status vector.
* Wraps isc_sqlcode() to isolate the legacy isc_* call in firebird_utils.cpp.
*
* @param status_vector ISC_STATUS array (typically IB_STATUS)
* @return SQLCODE value (negative for errors, 0 for success)
*/
long fbu_sqlcode(const ISC_STATUS *status_vector);
/**
* Look up array bounds for a named array column.
* Wraps isc_array_lookup_bounds() to isolate the legacy call.
*
* @param status_vector Output status vector
* @param db_handle Pointer to isc_db_handle
* @param tr_handle Pointer to isc_tr_handle
* @param relation_name Table name (null-terminated)
* @param field_name Column name (null-terminated)
* @param desc Output ISC_ARRAY_DESC
* @return 0 on success, non-zero on failure
*/
ISC_STATUS fba_array_lookup_bounds(ISC_STATUS *status_vector,
isc_db_handle *db_handle, isc_tr_handle *tr_handle,
const char *relation_name, const char *field_name,
ISC_ARRAY_DESC *desc);
/* Type Encoding/Decoding Functions (OO API via IUtil interface) */
/**
* Encode timestamp from components using OO API.
*
* @param master_ptr IMaster interface pointer
* @param year Year (1-9999)
* @param month Month (1-12)
* @param day Day (1-31)
* @param hours Hours (0-23)
* @param minutes Minutes (0-59)
* @param seconds Seconds (0-59)
* @param fractions Fractions of second (0-9999, tenths of milliseconds)
* @return Encoded ISC_TIMESTAMP, or {0,0} on error
*/
ISC_TIMESTAMP fbu_encode_timestamp(void *master_ptr, unsigned year, unsigned month, unsigned day,
unsigned hours, unsigned minutes, unsigned seconds, unsigned fractions);
/**
* Decode ISC_TIME to time components using OO API.
* Replaces legacy isc_decode_sql_time().
*
* @param master_ptr IMaster interface pointer
* @param time ISC_TIME value to decode
* @param hours Output: hours (0-23)
* @param minutes Output: minutes (0-59)
* @param seconds Output: seconds (0-59)
* @param fractions Output: fractions of second (0-9999)
*/
void fbu_decode_time(void *master_ptr, ISC_TIME time,
unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions);
/**
* Decode ISC_DATE to date components using OO API.
* Replaces legacy isc_decode_sql_date().
*
* @param master_ptr IMaster interface pointer
* @param date ISC_DATE value to decode
* @param year Output: year (1-9999)
* @param month Output: month (1-12)
* @param day Output: day (1-31)
*/
void fbu_decode_date(void *master_ptr, ISC_DATE date,
unsigned* year, unsigned* month, unsigned* day);
/**
* Decode ISC_TIMESTAMP to date and time components using OO API.
* Replaces legacy isc_decode_timestamp().
*
* @param master_ptr IMaster interface pointer
* @param timestamp ISC_TIMESTAMP value to decode
* @param year Output: year (1-9999)
* @param month Output: month (1-12)
* @param day Output: day (1-31)
* @param hours Output: hours (0-23)
* @param minutes Output: minutes (0-59)
* @param seconds Output: seconds (0-59)
* @param fractions Output: fractions of second (0-9999)
*/
void fbu_decode_timestamp(void *master_ptr, const ISC_TIMESTAMP* timestamp,
unsigned* year, unsigned* month, unsigned* day,
unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions);
/* Firebird OO API Connection Functions */
/**
* Create a database connection using the Firebird OO API.
*
* @param master_ptr Pointer to IMaster interface (from IBG(master_instance))
* @param database Database path (null-terminated)
* @param db_len Length of database path
* @param user Username (null-terminated, may be NULL)
* @param user_len Length of username
* @param password Password (null-terminated, may be NULL)
* @param password_len Length of password
* @param charset Character set (null-terminated, may be NULL)
* @param charset_len Length of charset
* @param role SQL role (null-terminated, may be NULL)
* @param role_len Length of role
* @param num_buffers Number of page buffers (0 for default)
* @param dialect SQL dialect (1, 2, or 3)
* @param force_write Force write flag (-1 = not set, 0 = async, 1 = sync)
* @param status_vector Output status vector for errors
* @return Pointer to connection object, or NULL on failure
*/
void* fbc_connect(
void* master_ptr,
const char* database, size_t db_len,
const char* user, size_t user_len,
const char* password, size_t password_len,
const char* charset, size_t charset_len,
const char* role, size_t role_len,
int num_buffers,
int dialect,
int force_write,
ISC_STATUS* status_vector
);
/**
* Detach a connection created with fbc_connect().
*
* @param connection Pointer returned by fbc_connect()
* @param status_vector Output status vector for errors
* @return 0 on success, non-zero on failure
*/
int fbc_disconnect(void* connection, ISC_STATUS* status_vector);
/**
* Drop a database (destructive operation).
*
* @param connection Pointer returned by fbc_connect()
* @param status_vector Output status vector for errors
* @return 0 on success, non-zero on failure
*/
int fbc_drop_database(void* connection, ISC_STATUS* status_vector);
/**
* Create a new database using CREATE DATABASE SQL statement.
* Uses OO API IUtil::executeCreateDatabase() internally.
*
* @param master_ptr Pointer to IMaster interface
* @param create_sql Complete CREATE DATABASE SQL statement
* @param dialect SQL dialect (typically 3)
* @param status_vector Output status vector for errors
* @return Pointer to fb::Connection object for the new database, or NULL on failure
*/
void* fbc_create_database(
void* master_ptr,
const char* create_sql,
unsigned dialect,
ISC_STATUS* status_vector
);
/**
* Check if a connection is valid.
*
* @param connection Pointer returned by fbc_connect()
* @return 1 if connected, 0 if not
*/
int fbc_is_connected(void* connection);
/**
* Ping the server to verify the connection is alive.
* Executes a lightweight query (SELECT 1 FROM RDB$DATABASE) to confirm
* the server is reachable and the connection is valid.
*
* @param master_ptr IMaster interface pointer
* @param connection Pointer returned by fbc_connect()
* @param status_vector Output status vector for errors
* @return 1 if alive, 0 if dead or error
*/
int fbc_ping(void* master_ptr, void* connection, ISC_STATUS* status_vector);
/**
* Get the IAttachment pointer from a connection.
*
* @param connection Pointer returned by fbc_connect()
* @return Raw IAttachment pointer, or NULL
*/
void* fbc_get_attachment(void* connection);
/**
* Get the server version from a connection.
*
* @param connection Pointer returned by fbc_connect()
* @return Version code (FB30=30, FB40=40, FB50=50), or 0 if invalid
*/
unsigned fbc_get_server_version(void* connection);
/**
* Retrieve database/connection information via the OO API.
* Wraps Firebird::IAttachment::getInfo().
*
* @param master_ptr IMaster interface pointer
* @param attachment_ptr IAttachment pointer (from fbc_get_attachment())
* @param items_length Info items length
* @param items Info items to request (isc_info_* constants)
* @param buffer_length Output buffer length
* @param buffer Output buffer
* @param status_vector Output status vector
* @return 1 on success, 0 on error
*/
int fbc_get_info(
void* master_ptr,
void* attachment_ptr,
unsigned items_length,
const unsigned char* items,
unsigned buffer_length,
unsigned char* buffer,
ISC_STATUS* status_vector
);
/* Firebird OO API Transaction Functions */
/**
* Start a transaction using the OO API.
*
* @param master_ptr Pointer to IMaster interface
* @param attachment_ptr Pointer to IAttachment interface (from fbc_get_attachment())
* @param tpb_len Length of TPB buffer
* @param tpb Transaction parameter buffer (may be NULL for defaults)
* @param status_vector Output status vector for errors
* @return Pointer to transaction object, or NULL on failure
*/
void* fbt_start(
void* master_ptr,
void* attachment_ptr,
unsigned tpb_len,
const unsigned char* tpb,
ISC_STATUS* status_vector
);
/**
* Commit a transaction created with fbt_start().
*
* @param transaction Pointer returned by fbt_start()
* @param status_vector Output status vector for errors
* @return 0 on success, non-zero on failure
*/
int fbt_commit(void* transaction, ISC_STATUS* status_vector);
/**
* Rollback a transaction created with fbt_start().
*
* @param transaction Pointer returned by fbt_start()
* @param status_vector Output status vector for errors
* @return 0 on success, non-zero on failure
*/
int fbt_rollback(void* transaction, ISC_STATUS* status_vector);
/**
* Commit with retaining (keeps transaction context).
*
* @param transaction Pointer returned by fbt_start()
* @param status_vector Output status vector for errors
* @return 0 on success, non-zero on failure
*/
int fbt_commit_retaining(void* transaction, ISC_STATUS* status_vector);
/**
* Rollback with retaining (keeps transaction context).
*
* @param transaction Pointer returned by fbt_start()
* @param status_vector Output status vector for errors
* @return 0 on success, non-zero on failure
*/
int fbt_rollback_retaining(void* transaction, ISC_STATUS* status_vector);
/**
* Check if a transaction is active.
*
* @param transaction Pointer returned by fbt_start()
* @return 1 if active, 0 if not
*/
int fbt_is_active(void* transaction);
/**
* Get the ITransaction pointer from a transaction wrapper.
*
* @param transaction Pointer returned by fbt_start()
* @return Raw ITransaction pointer, or NULL
*/
void* fbt_get_handle(void* transaction);
/**
* Free a transaction wrapper without commit/rollback.
* Use only when the transaction was already ended via other means.
*
* @param transaction Pointer returned by fbt_start()
*/
void fbt_free(void* transaction);
/**
* Retrieve transaction information via the OO API.
* Wraps Firebird::ITransaction::getInfo().
*
* @param master_ptr IMaster interface pointer
* @param transaction_ptr ITransaction pointer (from fbt_get_handle())
* @param items_length Info items length
* @param items Info items to request
* @param buffer_length Output buffer length
* @param buffer Output buffer
* @param status_vector Output status vector
* @return 1 on success, 0 on error
*/
int fbt_get_info(
void* master_ptr,
void* transaction_ptr,
unsigned items_length,
const unsigned char* items,
unsigned buffer_length,
unsigned char* buffer,
ISC_STATUS* status_vector
);
/* Firebird OO API Statement Functions */
/**
* Prepare a statement using OO API.
*
* @param master_ptr IMaster interface pointer (from IBG(master_instance))
* @param attachment_ptr IAttachment pointer (from fbc_get_attachment())
* @param transaction_ptr ITransaction pointer (from fbt_get_handle())
* @param sql SQL statement text
* @param sql_length Length of SQL text (0 = null-terminated)
* @param dialect SQL dialect (1, 2, or 3)
* @param status_vector Output ISC_STATUS array
* @return Opaque StatementWrapper pointer or NULL on error
*/
void* fbs_prepare(
void* master_ptr,
void* attachment_ptr,
void* transaction_ptr,
const char* sql,
unsigned sql_length,
unsigned dialect,
ISC_STATUS* status_vector
);
/**
* Execute a non-SELECT statement.
*
* @param master_ptr IMaster interface pointer
* @param statement_ptr StatementWrapper pointer (from fbs_prepare())
* @param transaction_ptr ITransaction pointer
* @param in_msg Input message buffer
* @param in_metadata IMessageMetadata for input
* @param out_msg Output message buffer
* @param out_metadata IMessageMetadata for output
* @param status_vector Output ISC_STATUS array
* @return 1 on success, 0 on error
*/
int fbs_execute(
void* master_ptr,
void* statement_ptr,
void* transaction_ptr,
void* in_msg,
void* in_metadata,
void* out_msg,
void* out_metadata,
ISC_STATUS* status_vector
);
/**
* Open cursor for SELECT statement.
*
* @param master_ptr IMaster interface pointer
* @param statement_ptr StatementWrapper pointer
* @param transaction_ptr ITransaction pointer
* @param in_msg Input message buffer
* @param in_metadata IMessageMetadata for input
* @param cursor_flags Cursor flags
* @param status_vector Output ISC_STATUS array
* @return 1 on success, 0 on error
*/
int fbs_open_cursor(
void* master_ptr,
void* statement_ptr,
void* transaction_ptr,
void* in_msg,
void* in_metadata,
unsigned cursor_flags,
ISC_STATUS* status_vector
);
/**
* Fetch next row from cursor.
*
* @param master_ptr IMaster interface pointer
* @param statement_ptr StatementWrapper pointer
* @param out_msg Output message buffer
* @param status_vector Output ISC_STATUS array
* @return 1 = row fetched, 0 = end of data, -1 = error
*/
int fbs_fetch(
void* master_ptr,
void* statement_ptr,
void* out_msg,
ISC_STATUS* status_vector
);
/**
* Fetch previous row from scrollable cursor.
* @return 1 = row fetched, 0 = end of data, -1 = error
*/
int fbs_fetch_prior(void* master_ptr, void* statement_ptr, void* out_msg, ISC_STATUS* status_vector);
/**
* Fetch first row from scrollable cursor.
* @return 1 = row fetched, 0 = end of data, -1 = error
*/
int fbs_fetch_first(void* master_ptr, void* statement_ptr, void* out_msg, ISC_STATUS* status_vector);
/**
* Fetch last row from scrollable cursor.
* @return 1 = row fetched, 0 = end of data, -1 = error
*/
int fbs_fetch_last(void* master_ptr, void* statement_ptr, void* out_msg, ISC_STATUS* status_vector);
/**
* Fetch row at absolute position from scrollable cursor.
* @return 1 = row fetched, 0 = end of data, -1 = error
*/
int fbs_fetch_absolute(void* master_ptr, void* statement_ptr, int position, void* out_msg, ISC_STATUS* status_vector);
/**
* Fetch row at relative offset from scrollable cursor.
* @return 1 = row fetched, 0 = end of data, -1 = error
*/
int fbs_fetch_relative(void* master_ptr, void* statement_ptr, int offset, void* out_msg, ISC_STATUS* status_vector);
/**
* Close cursor.
*
* @param statement_ptr StatementWrapper pointer
* @param status_vector Output ISC_STATUS array
* @return 1 on success, 0 on error
*/
int fbs_close_cursor(void* statement_ptr, ISC_STATUS* status_vector);
/**
* Free/unprepare statement.
*
* @param statement_ptr StatementWrapper pointer
* @param status_vector Output ISC_STATUS array
* @return 1 on success, 0 on error
*/
int fbs_free(void* statement_ptr, ISC_STATUS* status_vector);
/**
* Get statement type.
*
* @param master_ptr IMaster interface pointer
* @param statement_ptr StatementWrapper pointer
* @param status_vector Output ISC_STATUS array
* @return Statement type constant
*/
unsigned fbs_get_type(void* master_ptr, void* statement_ptr, ISC_STATUS* status_vector);
/**
* Get affected rows count.
*
* @param master_ptr IMaster interface pointer
* @param statement_ptr StatementWrapper pointer
* @param status_vector Output ISC_STATUS array
* @return Affected rows count
*/
ISC_UINT64 fbs_get_affected_records(void* master_ptr, void* statement_ptr, ISC_STATUS* status_vector);
/**
* Get input metadata.
*
* @param master_ptr IMaster interface pointer
* @param statement_ptr StatementWrapper pointer
* @param status_vector Output ISC_STATUS array
* @return IMessageMetadata pointer or NULL
*/
void* fbs_get_input_metadata(void* master_ptr, void* statement_ptr, ISC_STATUS* status_vector);
/**
* Get output metadata.
*
* @param master_ptr IMaster interface pointer
* @param statement_ptr StatementWrapper pointer
* @param status_vector Output ISC_STATUS array
* @return IMessageMetadata pointer or NULL
*/
void* fbs_get_output_metadata(void* master_ptr, void* statement_ptr, ISC_STATUS* status_vector);
/**
* Get input parameter count from statement.
*
* @param master_ptr IMaster interface pointer
* @param statement_ptr StatementWrapper pointer
* @param status_vector Output ISC_STATUS array
* @return Number of input parameters (0 if none or error)
*/
unsigned fbs_get_input_count(void* master_ptr, void* statement_ptr, ISC_STATUS* status_vector);
/**
* Get output field count from statement.
*
* @param master_ptr IMaster interface pointer
* @param statement_ptr StatementWrapper pointer
* @param status_vector Output ISC_STATUS array
* @return Number of output fields (0 if none or error)
*/
unsigned fbs_get_output_count(void* master_ptr, void* statement_ptr, ISC_STATUS* status_vector);
/**
* Get raw IStatement pointer.
*
* @param statement_ptr StatementWrapper pointer
* @return Raw IStatement pointer or NULL
*/
void* fbs_get_statement(void* statement_ptr);
/**
* Check if statement is prepared.
*
* @param statement_ptr StatementWrapper pointer
* @return 1 if prepared, 0 otherwise
*/
int fbs_is_prepared(void* statement_ptr);
/**
* Check if cursor is open.
*
* @param statement_ptr StatementWrapper pointer
* @return 1 if cursor open, 0 otherwise
*/
int fbs_is_cursor_open(void* statement_ptr);
/**
* Set cursor name for positioned updates (WHERE CURRENT OF).
*
* @param master_ptr IMaster interface pointer
* @param statement_ptr StatementWrapper pointer
* @param cursor_name Cursor name string
* @param status_vector Output ISC_STATUS array
* @return 1 on success, 0 on error
*/
int fbs_set_cursor_name(void* master_ptr, void* statement_ptr, const char* cursor_name, ISC_STATUS* status_vector);
/**
* Execute a statement that returns a single INT64 value (e.g., GEN_ID()).
* This is a convenience function that opens a cursor, fetches one row,
* extracts the first INT64 column, and closes the cursor.
*
* @param master_ptr IMaster interface pointer
* @param statement_ptr StatementWrapper pointer (from fbs_prepare())
* @param transaction_ptr ITransaction pointer
* @param status_vector Output ISC_STATUS array
* @return The INT64 value from the first column, or 0 on error
*/
ISC_INT64 fbs_execute_singleton_int64(
void* master_ptr,
void* statement_ptr,
void* transaction_ptr,
ISC_STATUS* status_vector
);
/* Firebird OO API Blob Functions */
/**
* Create a new blob for writing.
*
* @param master_ptr IMaster interface pointer
* @param attachment_ptr IAttachment pointer (from fbc_get_attachment())
* @param transaction_ptr ITransaction pointer (from fbt_get_handle())
* @param blob_id Output: blob ID after creation
* @param bpb_length BPB (Blob Parameter Block) length
* @param bpb BPB data
* @param status_vector Output status vector
* @return Opaque blob wrapper pointer, or NULL on error
*/
void* fbb_create(void* master_ptr,
void* attachment_ptr,
void* transaction_ptr,
ISC_QUAD* blob_id,
unsigned bpb_length,
const unsigned char* bpb,
ISC_STATUS* status_vector);
/**
* Open an existing blob for reading.
*
* @param master_ptr IMaster interface pointer
* @param attachment_ptr IAttachment pointer
* @param transaction_ptr ITransaction pointer
* @param blob_id Blob ID to open
* @param bpb_length BPB length
* @param bpb BPB data
* @param status_vector Output status vector
* @return Opaque blob wrapper pointer, or NULL on error
*/
void* fbb_open(void* master_ptr,
void* attachment_ptr,
void* transaction_ptr,
const ISC_QUAD* blob_id,
unsigned bpb_length,
const unsigned char* bpb,
ISC_STATUS* status_vector);
/**
* Write a segment to the blob.
*
* @param master_ptr IMaster interface pointer
* @param blob_wrapper Blob wrapper pointer
* @param length Segment length
* @param buffer Data to write
* @param status_vector Output status vector
* @return 1 on success, 0 on error
*/
int fbb_put_segment(void* master_ptr,
void* blob_wrapper,
unsigned length,
const void* buffer,
ISC_STATUS* status_vector);
/**
* Read a segment from the blob.
*
* @param master_ptr IMaster interface pointer
* @param blob_wrapper Blob wrapper pointer
* @param buffer_length Buffer size
* @param buffer Output buffer
* @param actual_length Output: actual bytes read
* @param status_vector Output status vector
* @return 0 on success with more data, 1 on EOF, 2 on segment, -1 on error
*/
int fbb_get_segment(void* master_ptr,
void* blob_wrapper,
unsigned buffer_length,
void* buffer,
unsigned* actual_length,
ISC_STATUS* status_vector);
/**
* Close the blob (commit writes).
*
* @param master_ptr IMaster interface pointer
* @param blob_wrapper Blob wrapper pointer
* @param status_vector Output status vector
* @return 1 on success, 0 on error
*/
int fbb_close(void* master_ptr, void* blob_wrapper, ISC_STATUS* status_vector);
/**
* Seek within an open stream BLOB.
*
* @param master_ptr IMaster interface (from fb_get_master_interface)
* @param blob_wrapper BlobWrapper pointer from fbb_open or fbb_create
* @param whence Seek mode: 0=SEEK_SET, 1=SEEK_CUR, 2=SEEK_END
* @param offset Byte offset relative to whence
* @param result_position Output: New absolute position after seek
* @param status_vector ISC status vector for error reporting
*
* @return 1 on success, 0 on failure
*/
int fbb_seek(void* master_ptr,
void* blob_wrapper,
int whence,
int offset,
int* result_position,
ISC_STATUS* status_vector);
/**
* Cancel the blob (discard writes).
*
* @param master_ptr IMaster interface pointer
* @param blob_wrapper Blob wrapper pointer
* @param status_vector Output status vector
* @return 1 on success, 0 on error
*/
int fbb_cancel(void* master_ptr, void* blob_wrapper, ISC_STATUS* status_vector);
/**
* Get blob info.
*
* @param master_ptr IMaster interface pointer
* @param blob_wrapper Blob wrapper pointer
* @param items_length Info items length
* @param items Info items to request
* @param buffer_length Output buffer length
* @param buffer Output buffer
* @param status_vector Output status vector
* @return 1 on success, 0 on error
*/
int fbb_get_info(void* master_ptr,
void* blob_wrapper,
unsigned items_length,
const unsigned char* items,
unsigned buffer_length,
unsigned char* buffer,
ISC_STATUS* status_vector);
/**
* Get blob ID from wrapper.
*
* @param blob_wrapper Blob wrapper pointer
* @param blob_id Output: blob ID
*/
void fbb_get_blob_id(void* blob_wrapper, ISC_QUAD* blob_id);
/**
* Check if blob is open.
*
* @param blob_wrapper Blob wrapper pointer
* @return 1 if open, 0 if closed or invalid
*/
int fbb_is_open(void* blob_wrapper);
/**
* Get the raw IBlob handle from wrapper.
*
* @param blob_wrapper Blob wrapper pointer
* @return Raw IBlob pointer, or NULL if invalid
*/
void* fbb_get_handle(void* blob_wrapper);
/**
* Free blob wrapper (without closing - blob must be closed first).
*
* @param blob_wrapper Blob wrapper pointer
*/
void fbb_free(void* blob_wrapper);
/* Firebird OO API Event Functions */
/**
* Queue events for notification using OO API.
*
* @param master_ptr IMaster interface pointer
* @param attachment_ptr IAttachment pointer (from fbc_get_attachment())
* @param length Event buffer length
* @param events Event buffer (from isc_event_block())
* @param status_vector Output status vector
* @return Opaque events wrapper pointer, or NULL on error
*/
void* fbe_queue(void* master_ptr,
void* attachment_ptr,
unsigned length,
const unsigned char* events,
ISC_STATUS* status_vector);
/**
* Cancel queued events.
*
* @param master_ptr IMaster interface pointer
* @param events_wrapper Events wrapper pointer (from fbe_queue())
* @param status_vector Output status vector
* @return 1 on success, 0 on error
*/
int fbe_cancel(void* master_ptr, void* events_wrapper, ISC_STATUS* status_vector);
/**
* Check if an event has fired (non-blocking).
*
* @param events_wrapper Events wrapper pointer
* @return 1 if event fired, 0 otherwise
*/
int fbe_has_event_fired(void* events_wrapper);
/**
* Reset the event fired flag.
*
* @param events_wrapper Events wrapper pointer
*/
void fbe_reset_event_fired(void* events_wrapper);
/**
* Get event data from the last fired event.
*
* @param events_wrapper Events wrapper pointer
* @param length Output: length of event data
* @return Pointer to event data, or NULL if no event
*/
const unsigned char* fbe_get_event_data(void* events_wrapper, unsigned* length);
/**
* Check if events are queued.
*
* @param events_wrapper Events wrapper pointer
* @return 1 if queued, 0 otherwise
*/
int fbe_is_queued(void* events_wrapper);
/**
* Free events wrapper.
*
* @param events_wrapper Events wrapper pointer
*/
void fbe_free(void* events_wrapper);
/**
* Free an event buffer allocated by fbe_event_block() / isc_event_block().
*
* @param buf Buffer to free (may be NULL)
*/
void fbe_event_free(unsigned char* buf);
/**
* Build event parameter block (EPB) for up to 15 events.
* Replacement for isc_event_block().
*
* @param event_buf Output: allocated event buffer
* @param result_buf Output: allocated result buffer
* @param count Number of event names
* @return Length of the event buffer
*/
unsigned short fbe_event_block(unsigned char** event_buf, unsigned char** result_buf,
unsigned short count, ...);
/**
* Wait synchronously for any of the registered events.
* Replacement for isc_wait_for_event().
*
* @param status_vector Output status vector
* @param db_handle_ptr Pointer to isc_db_handle
* @param buffer_length Length of event buffer
* @param event_buffer Event buffer (from fbe_event_block())
* @param result_buffer Result buffer (from fbe_event_block())
* @return 0 on success, non-zero on error
*/
ISC_STATUS fbe_wait_for_event(ISC_STATUS* status_vector, void* db_handle_ptr,
unsigned short buffer_length,
unsigned char* event_buffer,
unsigned char* result_buffer);
/**
* Wait synchronously for events using OO API attachment pointer.
* Uses fb_get_database_handle() to obtain a legacy handle from IAttachment*.
*
* @param status_vector Output status vector
* @param attachment_ptr IAttachment pointer (from fbc_get_attachment())
* @param buffer_length Length of event buffer
* @param event_buffer Event buffer (from fbe_event_block())
* @param result_buffer Result buffer (from fbe_event_block())
* @return 0 on success, non-zero on error
*/
ISC_STATUS fbe_wait_for_event_oo(ISC_STATUS* status_vector, void* attachment_ptr,
unsigned short buffer_length,
unsigned char* event_buffer,
unsigned char* result_buffer);
/**
* Decode event counts from result buffer.
* Replacement for isc_event_counts().
*
* @param result_counts Output: array of event counts
* @param buffer_length Length of event buffer
* @param event_buffer Event buffer (from fbe_event_block())
* @param result_buffer Result buffer (filled by fbe_wait_for_event())
*/
void fbe_event_counts(ISC_ULONG* result_counts, unsigned short buffer_length,
unsigned char* event_buffer, unsigned char* result_buffer);
/* Firebird OO API Service Functions */
/**
* Attach to the service manager using OO API.
*
* @param master_ptr IMaster interface pointer
* @param service_name Service name (e.g., "localhost:service_mgr")
* @param spb_length Service parameter buffer length
* @param spb Service parameter buffer
* @param status_vector Output status vector
* @return Opaque service wrapper pointer, or NULL on error
*/
void* fbsvc_attach(void* master_ptr,
const char* service_name,
unsigned spb_length,
const unsigned char* spb,
ISC_STATUS* status_vector);
/**
* Detach from the service manager.
*
* @param master_ptr IMaster interface pointer (unused, for API consistency)
* @param service_wrapper Service wrapper pointer (from fbsvc_attach())
* @param status_vector Output status vector
* @return 1 on success, 0 on error
*/
int fbsvc_detach(void* master_ptr, void* service_wrapper, ISC_STATUS* status_vector);
/**
* Start a service task.
*
* @param master_ptr IMaster interface pointer (unused, for API consistency)
* @param service_wrapper Service wrapper pointer
* @param spb_length Service parameter buffer length
* @param spb Service parameter buffer
* @param status_vector Output status vector
* @return 1 on success, 0 on error
*/
int fbsvc_start(void* master_ptr,
void* service_wrapper,
unsigned spb_length,
const unsigned char* spb,
ISC_STATUS* status_vector);
/**
* Query service status/results.
*
* @param master_ptr IMaster interface pointer (unused, for API consistency)
* @param service_wrapper Service wrapper pointer
* @param send_length Send buffer length
* @param send_items Send buffer
* @param recv_length Receive items length
* @param recv_items Receive items
* @param buffer_length Output buffer length
* @param buffer Output buffer
* @param status_vector Output status vector
* @return 1 on success, 0 on error
*/
int fbsvc_query(void* master_ptr,
void* service_wrapper,
unsigned send_length,
const unsigned char* send_items,
unsigned recv_length,
const unsigned char* recv_items,
unsigned buffer_length,
unsigned char* buffer,
ISC_STATUS* status_vector);
/**
* Check if attached to service manager.
*
* @param service_wrapper Service wrapper pointer
* @return 1 if attached, 0 otherwise
*/
int fbsvc_is_attached(void* service_wrapper);
/**
* Free service wrapper (without detach - service must be detached first).
*
* @param service_wrapper Service wrapper pointer
*/
void fbsvc_free(void* service_wrapper);
/* Firebird OO API Array Functions */
/**
* Get an array slice from the database using OO API.
*
* @param master_ptr IMaster interface pointer
* @param attachment_ptr IAttachment pointer (from fbc_get_attachment())
* @param transaction_ptr ITransaction pointer (from fbt_get_handle())
* @param array_id The ISC_QUAD array identifier
* @param desc Array descriptor (ISC_ARRAY_DESC)
* @param buffer Output buffer to receive array data
* @param buffer_length Buffer length (updated with actual bytes read)
* @param status_vector Output status vector
* @return 0 on success, non-zero on failure
*/
int fba_get_slice(void* master_ptr,
void* attachment_ptr,
void* transaction_ptr,
ISC_QUAD* array_id,
const ISC_ARRAY_DESC* desc,
void* buffer,
ISC_LONG* buffer_length,
ISC_STATUS* status_vector);
/**
* Lookup array descriptor/bounds using OO API.
*
* This replaces isc_array_lookup_bounds() by querying system tables
* via IStatement/IResultSet.
*
* @param master_ptr IMaster interface pointer
* @param attachment_ptr IAttachment pointer (from fbc_get_attachment())
* @param transaction_ptr ITransaction pointer (from fbt_get_handle())