- Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathuser_dsql.cpp
1327 lines (1113 loc) · 32.4 KB
/
user_dsql.cpp
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
/*
* PROGRAM: Dynamic SQL runtime support
* MODULE: user_dsql.cpp
* DESCRIPTION: Above the Y-valve entrypoints for DSQL
*
*
* This module contains DSQL related routines that sit on top
* of the Y-valve. This includes the original (pre-version 4)
* DSQL routines as well as the alternate VMS and Ada entrypoints
* of the new DSQL routines. The pre-version 4 entrypoints
* retain their "gds__" prefix while the new routines are prefixed
* with "isc_dsql_".
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*
* 2002.10.28 Sean Leyne - Code cleanup, removed obsolete "MPEXL" port
*
* 2002.10.29 Sean Leyne - Removed obsolete "Netware" port
*
* 2003.01.12 Alex Peshkoff - Code cleanup, bad level of indirection
*
*/
#include"firebird.h"
#include"../dsql/chars.h"
#include"firebird/impl/sqlda_pub.h"
#include"../yvalve/gds_proto.h"
#include"../yvalve/why_proto.h"
#include"../yvalve/user__proto.h"
#include"../yvalve/utl_proto.h"
#include"iberror.h"
#include"../common/classes/init.h"
#include"../common/classes/rwlock.h"
#include"../common/StatusArg.h"
#include"../common/SimpleStatusVector.h"
#include<stdio.h>
#include<stdlib.h>
// SQLDA dialects
const USHORT DIALECT_sqlda = 0;
//const USHORT DIALECT_xsqlda = 1; // meaning is same as SQL_DIALECT_V5
usingnamespaceFirebird;
enum name_type {
NAME_statement = 1,
NAME_cursor = 2
};
// declare a structure which enables us to associate a cursor with a
// statement and vice versa
structdsql_dbb
{
dsql_dbb* dbb_next;
FB_API_HANDLE dbb_handle;
};
structdsql_name; // fwd. decl.
structdsql_stmt
{
dsql_stmt* stmt_next; // next in chain
dsql_name* stmt_stmt; // symbol table entry for statement name
dsql_name* stmt_cursor; // symbol table entry for cursor name
FB_API_HANDLE stmt_handle; // stmt handle returned by dsql_xxx
FB_API_HANDLE stmt_db_handle; // database handle for this statement
};
// declare a structure to hold the cursor and statement names
structdsql_name
{
dsql_name* name_next;
dsql_name* name_prev;
dsql_stmt* name_stmt;
USHORT name_length;
SCHAR name_symbol[1];
};
// error block
structdsql_err_stblock
{
ISC_STATUS* dsql_status;
ISC_STATUS* dsql_user_status;
};
staticvoidcleanup(void*);
staticvoidcleanup_database(FB_API_HANDLE*, void*);
static ISC_STATUS error(const Firebird::Exception& ex);
static ISC_STATUS error();
staticvoiderror_post(const Arg::StatusVector& v);
static dsql_name* lookup_name(const SCHAR*, dsql_name*);
static dsql_stmt* lookup_stmt(const SCHAR*, dsql_name*, name_type);
staticvoidinit(FB_API_HANDLE*);
static dsql_name* insert_name(const SCHAR*, dsql_name**, dsql_stmt*);
static USHORT name_length(const SCHAR*);
staticvoidremove_name(dsql_name*, dsql_name**);
staticboolscompare(const SCHAR*, USHORT, const SCHAR*, USHORT);
// declare the private data
staticbool init_flag = false; // whether we've been initialized
static dsql_err_stblock* UDSQL_error = NULL;
static dsql_stmt* statements = NULL;
static dsql_name* statement_names = NULL;
static dsql_name* cursor_names = NULL;
static dsql_dbb* databases = NULL;
Firebird::GlobalPtr<Firebird::RWLock> global_sync;
staticinlinevoidset_global_private_status(ISC_STATUS* user_status, ISC_STATUS* local_status)
{
UDSQL_error->dsql_user_status = user_status;
UDSQL_error->dsql_status = user_status ? user_status : local_status;
}
staticinlinevoidINIT_DSQL(ISC_STATUS* user_status, ISC_STATUS* local_status)
{
init(0);
set_global_private_status(user_status, local_status);
}
//____________________________________________________________
//
// Close a dynamic SQL cursor.
//
ISC_STATUS API_ROUTINE isc_embed_dsql_close(ISC_STATUS* user_status, const SCHAR* name)
{
ISC_STATUS_ARRAY local_status;
INIT_DSQL(user_status, local_status);
try
{
// get the symbol table entry
dsql_stmt* statement = lookup_stmt(name, cursor_names, NAME_cursor);
returnisc_dsql_free_statement(user_status, &statement->stmt_handle, DSQL_close);
}
catch (const Firebird::Exception& ex)
{
returnerror(ex);
}
}
//____________________________________________________________
//
// Declare a cursor for a dynamic request.
//
ISC_STATUS API_ROUTINE isc_embed_dsql_declare(ISC_STATUS* user_status,
const SCHAR* stmt_name,
const SCHAR* cursor)
{
ISC_STATUS_ARRAY local_status;
INIT_DSQL(user_status, local_status);
try
{
// get the symbol table entry
dsql_stmt* statement = lookup_stmt(stmt_name, statement_names, NAME_statement);
const ISC_STATUS s = isc_dsql_set_cursor_name(user_status, &statement->stmt_handle, cursor, 0);
if (s) {
return s;
}
Firebird::WriteLockGuard guard(global_sync, FB_FUNCTION);
statement->stmt_cursor = insert_name(cursor, &cursor_names, statement);
return s;
}
catch (const Firebird::Exception& ex)
{
returnerror(ex);
}
}
//____________________________________________________________
//
// Describe output parameters for a prepared statement.
//
ISC_STATUS API_ROUTINE isc_embed_dsql_describe(ISC_STATUS* user_status,
const SCHAR* stmt_name,
USHORT dialect, XSQLDA* sqlda)
{
ISC_STATUS_ARRAY local_status;
INIT_DSQL(user_status, local_status);
try
{
// get the symbol table entry
dsql_stmt* statement = lookup_stmt(stmt_name, statement_names, NAME_statement);
returnisc_dsql_describe(user_status, &statement->stmt_handle, dialect, sqlda);
}
catch (const Firebird::Exception& ex)
{
returnerror(ex);
}
}
//____________________________________________________________
//
// isc_embed_dsql_descr_bind
//
ISC_STATUS API_ROUTINE isc_embed_dsql_descr_bind(ISC_STATUS* user_status,
const SCHAR* stmt_name,
USHORT dialect,
XSQLDA* sqlda)
{
returnisc_embed_dsql_describe_bind(user_status, stmt_name, dialect, sqlda);
}
//____________________________________________________________
//
// Describe input parameters for a prepared statement.
//
ISC_STATUS API_ROUTINE isc_embed_dsql_describe_bind(ISC_STATUS* user_status,
const SCHAR* stmt_name,
USHORT dialect,
XSQLDA* sqlda)
{
ISC_STATUS_ARRAY local_status;
INIT_DSQL(user_status, local_status);
try
{
// get the symbol table entry
dsql_stmt* statement = lookup_stmt(stmt_name, statement_names, NAME_statement);
returnisc_dsql_describe_bind(user_status, &statement->stmt_handle, dialect, sqlda);
}
catch (const Firebird::Exception& ex)
{
returnerror(ex);
}
}
//____________________________________________________________
//
// Execute a non-SELECT dynamic SQL statement.
//
ISC_STATUS API_ROUTINE isc_embed_dsql_execute(ISC_STATUS* user_status,
FB_API_HANDLE* trans_handle,
const SCHAR* stmt_name,
USHORT dialect,
XSQLDA* sqlda)
{
returnisc_embed_dsql_execute2(user_status, trans_handle, stmt_name, dialect, sqlda, NULL);
}
//____________________________________________________________
//
// Execute a non-SELECT dynamic SQL statement.
//
ISC_STATUS API_ROUTINE isc_embed_dsql_execute2(ISC_STATUS* user_status,
FB_API_HANDLE* trans_handle,
const SCHAR* stmt_name,
USHORT dialect,
XSQLDA* in_sqlda,
XSQLDA* out_sqlda)
{
ISC_STATUS_ARRAY local_status;
INIT_DSQL(user_status, local_status);
try
{
// get the symbol table entry
dsql_stmt* statement = lookup_stmt(stmt_name, statement_names, NAME_statement);
returnisc_dsql_execute2(user_status, trans_handle, &statement->stmt_handle,
dialect, in_sqlda, out_sqlda);
}
catch (const Firebird::Exception& ex)
{
returnerror(ex);
}
}
//____________________________________________________________
//
// isc_embed_dsql_exec_immed
//
ISC_STATUS API_ROUTINE isc_embed_dsql_exec_immed(ISC_STATUS* user_status,
FB_API_HANDLE* db_handle,
FB_API_HANDLE* trans_handle,
USHORT length,
const SCHAR* string,
USHORT dialect,
XSQLDA* sqlda)
{
returnisc_embed_dsql_execute_immed(user_status, db_handle, trans_handle,
length, string, dialect, sqlda);
}
//____________________________________________________________
//
// Prepare a statement for execution.
//
ISC_STATUS API_ROUTINE isc_embed_dsql_execute_immed(ISC_STATUS* user_status,
FB_API_HANDLE* db_handle,
FB_API_HANDLE* trans_handle,
USHORT length,
const SCHAR* string,
USHORT dialect,
XSQLDA* sqlda)
{
returnisc_embed_dsql_exec_immed2(user_status, db_handle, trans_handle,
length, string, dialect, sqlda, NULL);
}
//____________________________________________________________
//
// Prepare a statement for execution.
//
ISC_STATUS API_ROUTINE isc_embed_dsql_exec_immed2(ISC_STATUS* user_status,
FB_API_HANDLE* db_handle,
FB_API_HANDLE* trans_handle,
USHORT length,
const SCHAR* string,
USHORT dialect,
XSQLDA* in_sqlda,
XSQLDA* out_sqlda)
{
returnisc_dsql_exec_immed2(user_status, db_handle, trans_handle,
length, string, dialect, in_sqlda, out_sqlda);
}
//____________________________________________________________
//
// Fetch next record from a dynamic SQL cursor
//
ISC_STATUS API_ROUTINE isc_embed_dsql_fetch(ISC_STATUS* user_status,
const SCHAR* cursor_name,
USHORT dialect, XSQLDA* sqlda)
{
ISC_STATUS_ARRAY local_status;
INIT_DSQL(user_status, local_status);
try
{
dsql_stmt* statement = lookup_stmt(cursor_name, cursor_names, NAME_cursor);
returnisc_dsql_fetch(user_status, &statement->stmt_handle, dialect, sqlda);
}
catch (const Firebird::Exception& ex)
{
returnerror(ex);
}
}
//____________________________________________________________
//
// Fetch next record from a dynamic SQL cursor (ADA version)
//
ISC_STATUS API_ROUTINE isc_embed_dsql_fetch_a(ISC_STATUS* user_status,
int* sqlcode,
const SCHAR* cursor_name,
USHORT dialect,
XSQLDA* sqlda)
{
*sqlcode = 0;
ISC_STATUS s = isc_embed_dsql_fetch(user_status, cursor_name, dialect, sqlda);
if (s == 100) {
*sqlcode = 100;
}
return FB_SUCCESS;
}
ISC_STATUS API_ROUTINE isc_embed_dsql_insert(ISC_STATUS* user_status,
const SCHAR* cursor_name,
USHORT dialect, XSQLDA* sqlda)
{
/**************************************
*
* i s c _ e m b e d _ d s q l _ i n s e r t
*
**************************************
*
* Functional description
* Insert next record into a dynamic SQL cursor
*
**************************************/
ISC_STATUS_ARRAY local_status;
INIT_DSQL(user_status, local_status);
try
{
// get the symbol table entry
dsql_stmt* statement = lookup_stmt(cursor_name, cursor_names, NAME_cursor);
returnisc_dsql_insert(user_status, &statement->stmt_handle, dialect, sqlda);
}
catch (const Firebird::Exception& ex)
{
returnerror(ex);
}
}
void API_ROUTINE isc_embed_dsql_length(const UCHAR* string, USHORT* length)
{
/**************************************
*
* i s c _ e m b e d _ d s q l _ l e n g t h
*
**************************************
*
* Functional description
* Determine length of a ';' or null terminated string
*
**************************************/
const UCHAR* p;
for (p = string; *p && *p != ';'; p++)
{
if (classes(*p) & CHR_QUOTE)
{
for (UCHAR prev = 0, quote = *p++; *p == quote || prev == quote;)
prev = *p++;
p--;
}
}
*length = p - string + 1;
}
ISC_STATUS API_ROUTINE isc_embed_dsql_open(ISC_STATUS* user_status,
FB_API_HANDLE* trans_handle,
const SCHAR* cursor_name,
USHORT dialect, XSQLDA* sqlda)
{
/**************************************
*
* i s c _ e m b e d _ d s q l _ o p e n
*
**************************************
*
* Functional description
* Open a dynamic SQL cursor.
*
**************************************/
returnisc_embed_dsql_open2(user_status, trans_handle, cursor_name, dialect, sqlda, NULL);
}
ISC_STATUS API_ROUTINE isc_embed_dsql_open2(ISC_STATUS* user_status,
FB_API_HANDLE* trans_handle,
const SCHAR* cursor_name,
USHORT dialect,
XSQLDA* in_sqlda, XSQLDA* out_sqlda)
{
/**************************************
*
* i s c _ e m b e d _ d s q l _ o p e n 2
*
**************************************
*
* Functional description
* Open a dynamic SQL cursor.
*
**************************************/
ISC_STATUS_ARRAY local_status;
INIT_DSQL(user_status, local_status);
try
{
// get the symbol table entry
dsql_stmt* statement = lookup_stmt(cursor_name, cursor_names, NAME_cursor);
returnisc_dsql_execute2(user_status, trans_handle, &statement->stmt_handle,
dialect, in_sqlda, out_sqlda);
}
catch (const Firebird::Exception& ex)
{
returnerror(ex);
}
}
ISC_STATUS API_ROUTINE isc_embed_dsql_prepare(ISC_STATUS* user_status,
FB_API_HANDLE* db_handle,
FB_API_HANDLE* trans_handle,
const SCHAR* stmt_name,
USHORT length,
const SCHAR* string,
USHORT dialect,
XSQLDA* sqlda)
{
/**************************************
*
* i s c _ e m b e d _ d s q l _ p r e p a r e
*
**************************************
*
* Functional description
* Prepare a statement for execution.
*
**************************************/
ISC_STATUS s;
ISC_STATUS_ARRAY local_status;
dsql_stmt* statement;
FB_API_HANDLE stmt_handle;
init(db_handle);
set_global_private_status(user_status, local_status);
try {
dsql_name* name = lookup_name(stmt_name, statement_names);
if (name && name->name_stmt->stmt_db_handle == *db_handle)
{
// The statement name already exists for this database.
// Re-use its statement handle.
statement = name->name_stmt;
stmt_handle = statement->stmt_handle;
}
else
{
// This is a new statement name for this database.
// Allocate a statement handle for it.
if (name) {
isc_embed_dsql_release(user_status, stmt_name);
}
statement = NULL;
stmt_handle = 0;
s = isc_dsql_allocate_statement(user_status, db_handle, &stmt_handle);
if (s)
{
return s;
}
}
s = isc_dsql_prepare(user_status, trans_handle, &stmt_handle, length, string, dialect, sqlda);
if (s)
{
// An error occurred. Free any newly allocated statement handle.
if (!statement)
{
ISC_STATUS_ARRAY local_status2;
isc_dsql_free_statement(local_status2, &stmt_handle, DSQL_drop);
}
returnerror();
}
// If a new statement was allocated, add it to the symbol table and insert it
// into the list of statements
Firebird::WriteLockGuard guard(global_sync, FB_FUNCTION);
if (!statement)
{
statement = (dsql_stmt*) gds__alloc((SLONG) sizeof(dsql_stmt));
// FREE: by user calling isc_embed_dsql_release()
if (!statement) // NOMEM:
error_post(Arg::Gds(isc_virmemexh));
#ifdef DEBUG_GDS_ALLOC
gds_alloc_flag_unfreed((void *) statement);
#endif// DEBUG_GDS_ALLOC
statement->stmt_next = statements;
statements = statement;
statement->stmt_db_handle = (FB_API_HANDLE) * db_handle;
statement->stmt_stmt = insert_name(stmt_name, &statement_names, statement);
}
elseif (statement->stmt_cursor)
{
remove_name(statement->stmt_cursor, &cursor_names);
}
statement->stmt_handle = stmt_handle;
statement->stmt_cursor = NULL;
return s;
} // try
catch (const Firebird::Exception& ex)
{
returnerror(ex);
}
}
ISC_STATUS API_ROUTINE isc_embed_dsql_release(ISC_STATUS* user_status, const SCHAR* stmt_name)
{
/**************************************
*
* i s c _ e m b e d _ d s q l _ r e l e a s e
*
**************************************
*
* Functional description
* Release request for a dsql statement
*
**************************************/
ISC_STATUS_ARRAY local_status;
INIT_DSQL(user_status, local_status);
try
{
// If a request already exists under that name, purge it out
dsql_stmt* statement = lookup_stmt(stmt_name, statement_names, NAME_statement);
ISC_STATUS s = isc_dsql_free_statement(user_status, &statement->stmt_handle, DSQL_drop);
if (s) {
return s;
}
// remove the statement from the symbol tables
Firebird::WriteLockGuard guard(global_sync, FB_FUNCTION);
if (statement->stmt_stmt)
remove_name(statement->stmt_stmt, &statement_names);
if (statement->stmt_cursor)
remove_name(statement->stmt_cursor, &cursor_names);
// and remove this statement from the local list
dsql_stmt* p;
for (dsql_stmt** stmt_ptr = &statements; (p = *stmt_ptr); stmt_ptr = &p->stmt_next)
{
if (p == statement)
{
*stmt_ptr = statement->stmt_next;
gds__free(statement);
break;
}
}
return s;
}
catch (const Firebird::Exception& ex)
{
returnerror(ex);
}
}
ISC_STATUS API_ROUTINE isc_dsql_fetch_a(ISC_STATUS* user_status,
int* sqlcode,
int* stmt_handle,
USHORT dialect, XSQLDA* sqlda)
{
/**************************************
*
* i s c _ d s q l _ f e t c h _ a
*
**************************************
*
* Functional description
* Fetch next record from a dynamic SQL cursor (ADA version)
*
**************************************/
*sqlcode = 0;
const ISC_STATUS s = isc_dsql_fetch(user_status, reinterpret_cast<FB_API_HANDLE*>(stmt_handle),
dialect, sqlda);
if (s == 100)
*sqlcode = 100;
return FB_SUCCESS;
}
/**************************************
*
* i s c _ . . .
*
**************************************
*
* Functional description
* The following routines define the
* old isc_ entrypoints.
*
**************************************/
ISC_STATUS API_ROUTINE isc_close(ISC_STATUS* status_vector, const SCHAR* statement_name)
{
returnisc_embed_dsql_close(status_vector, statement_name);
}
ISC_STATUS API_ROUTINE isc_declare(ISC_STATUS* status_vector,
const SCHAR* statement_name,
const SCHAR* cursor_name)
{
returnisc_embed_dsql_declare(status_vector, statement_name, cursor_name);
}
ISC_STATUS API_ROUTINE isc_describe(ISC_STATUS* status_vector,
const SCHAR* statement_name, XSQLDA* sqlda)
{
returnisc_embed_dsql_describe(status_vector, statement_name,
DIALECT_sqlda, sqlda);
}
ISC_STATUS API_ROUTINE isc_describe_bind(ISC_STATUS* status_vector,
const SCHAR* statement_name,
XSQLDA* sqlda)
{
returnisc_embed_dsql_describe_bind(status_vector, statement_name,
DIALECT_sqlda, sqlda);
}
ISC_STATUS API_ROUTINE isc_dsql_finish(FB_API_HANDLE* /*db_handle*/)
{
return0;
}
ISC_STATUS API_ROUTINE isc_execute(ISC_STATUS* status_vector, FB_API_HANDLE* tra_handle,
const SCHAR* statement_name, XSQLDA* sqlda)
{
returnisc_embed_dsql_execute(status_vector, tra_handle, statement_name,
DIALECT_sqlda, sqlda);
}
ISC_STATUS API_ROUTINE isc_execute_immediate(ISC_STATUS* status_vector,
FB_API_HANDLE* db_handle,
FB_API_HANDLE* tra_handle,
SSHORT* sql_length, const SCHAR* sql)
{
returnisc_embed_dsql_execute_immed(status_vector, db_handle, tra_handle,
(USHORT) (sql_length ? *sql_length : 0),
sql, DIALECT_sqlda, NULL);
}
ISC_STATUS API_ROUTINE isc_fetch(ISC_STATUS* status_vector,
const SCHAR* cursor_name, XSQLDA* sqlda)
{
returnisc_embed_dsql_fetch(status_vector, cursor_name,
DIALECT_sqlda, sqlda);
}
ISC_STATUS API_ROUTINE isc_fetch_a(ISC_STATUS* status_vector,
int *sqlcode,
const SCHAR* cursor_name, XSQLDA* sqlda)
{
returnisc_embed_dsql_fetch_a(status_vector, sqlcode, cursor_name, DIALECT_sqlda,
sqlda);
}
ISC_STATUS API_ROUTINE isc_open(ISC_STATUS* status_vector,
FB_API_HANDLE* tra_handle,
const SCHAR* cursor_name, XSQLDA* sqlda)
{
returnisc_embed_dsql_open(status_vector, tra_handle, cursor_name, DIALECT_sqlda, sqlda);
}
ISC_STATUS API_ROUTINE isc_prepare(ISC_STATUS* status_vector,
FB_API_HANDLE* db_handle,
FB_API_HANDLE* tra_handle,
const SCHAR* statement_name,
const SSHORT* sql_length,
const SCHAR* sql,
XSQLDA* sqlda)
{
returnisc_embed_dsql_prepare(status_vector, db_handle, tra_handle, statement_name,
(USHORT) (sql_length ? *sql_length : 0), sql,
DIALECT_sqlda, sqlda);
}
ISC_STATUS API_ROUTINE isc_dsql_release(ISC_STATUS* status_vector, const SCHAR* statement_name)
{
returnisc_embed_dsql_release(status_vector, statement_name);
}
int API_ROUTINE isc_to_sqlda(XSQLDA* , // sqlda
int , // number
SCHAR* , // host_var
int , // host_var_size
SCHAR* ) // name
{
// no longer supported
return0;
}
//____________________________________________________________
//
// gds_...
//
// The following routines define the gds__ style names for isc_ entrypoints.
//
// Please note that these names - strictly speaking - are illegal C++
// identifiers, and as such should probably be moved into a C file.
//
ISC_STATUS API_ROUTINE gds__close(ISC_STATUS* status_vector, const SCHAR* statement_name)
{
returnisc_close(status_vector, statement_name);
}
ISC_STATUS API_ROUTINE gds__declare(ISC_STATUS* status_vector,
const SCHAR* statement_name,
const SCHAR* cursor_name)
{
returnisc_declare(status_vector, statement_name, cursor_name);
}
ISC_STATUS API_ROUTINE gds__describe(ISC_STATUS* status_vector,
const SCHAR* statement_name,
XSQLDA* sqlda)
{
returnisc_describe(status_vector, statement_name, sqlda);
}
ISC_STATUS API_ROUTINE gds__describe_bind(ISC_STATUS* status_vector,
const SCHAR* statement_name,
XSQLDA* sqlda)
{
returnisc_describe_bind(status_vector, statement_name, sqlda);
}
ISC_STATUS API_ROUTINE gds__dsql_finish(FB_API_HANDLE* db_handle)
{
returnisc_dsql_finish(db_handle);
}
ISC_STATUS API_ROUTINE gds__execute(ISC_STATUS* status_vector,
FB_API_HANDLE* tra_handle,
const SCHAR* statement_name,
XSQLDA* sqlda)
{
returnisc_execute(status_vector, tra_handle, statement_name, sqlda);
}
ISC_STATUS API_ROUTINE gds__execute_immediate(ISC_STATUS* status_vector,
FB_API_HANDLE* db_handle,
FB_API_HANDLE* tra_handle,
SSHORT* sql_length,
const SCHAR* sql)
{
returnisc_execute_immediate(status_vector, db_handle, tra_handle, sql_length, sql);
}
ISC_STATUS API_ROUTINE gds__fetch(ISC_STATUS* status_vector,
const SCHAR* statement_name,
XSQLDA* sqlda)
{
returnisc_fetch(status_vector, statement_name, sqlda);
}
ISC_STATUS API_ROUTINE gds__fetch_a(ISC_STATUS* status_vector,
int* sqlcode,
const SCHAR* statement_name,
XSQLDA* sqlda)
{
returnisc_fetch_a(status_vector, sqlcode, statement_name, sqlda);
}
ISC_STATUS API_ROUTINE gds__open(ISC_STATUS* status_vector,
FB_API_HANDLE* tra_handle,
const SCHAR* cursor_name,
XSQLDA* sqlda)
{
returnisc_open(status_vector, tra_handle, cursor_name, sqlda);
}
ISC_STATUS API_ROUTINE gds__prepare(ISC_STATUS* status_vector,
FB_API_HANDLE* db_handle,
FB_API_HANDLE* tra_handle,
const SCHAR* statement_name,
const SSHORT* sql_length,
const SCHAR* sql,
XSQLDA* sqlda)
{
returnisc_prepare(status_vector, db_handle, tra_handle, statement_name,
sql_length, sql, sqlda);
}
ISC_STATUS API_ROUTINE gds__to_sqlda(XSQLDA* sqlda, int number,
SCHAR* host_variable, int host_variable_size,
SCHAR* host_variable_name)
{
returnisc_to_sqlda(sqlda, number, host_variable, host_variable_size, host_variable_name);
}
//____________________________________________________________
//
// Helper functions for cleanup().
//
staticvoidfree_all_databases(dsql_dbb*& databasesL)
{
while (databasesL)
{
dsql_dbb* database = databasesL;
databasesL = database->dbb_next;
gds__free(database);
}
}
staticvoidfree_all_statements(dsql_stmt*& statementsL)
{
while (statementsL)
{
dsql_stmt* statement = statementsL;
statementsL = statement->stmt_next;
gds__free(statement);
}
}
staticvoidfree_all_names(dsql_name*& names)
{
while (names)
{
dsql_name* name = names;
names = name->name_next;
gds__free(name);
}
}
//____________________________________________________________
//
// Cleanup handler to free all dynamically allocated memory.
//
staticvoidcleanup(void*)
{
if (!init_flag) {
return;
}
init_flag = false;
gds__free(UDSQL_error);
UDSQL_error = NULL;
{ // scope
Firebird::WriteLockGuard guard(global_sync, FB_FUNCTION);
free_all_databases(databases);
free_all_statements(statements);
free_all_names(statement_names);
free_all_names(cursor_names);
}
gds__unregister_cleanup(cleanup, 0);
}
//____________________________________________________________
//
// the cleanup handler called when a database is closed
//
staticvoidcleanup_database(FB_API_HANDLE* db_handle, void* /*dummy*/)
{
if (!db_handle || !databases) {
return;
}