-
Notifications
You must be signed in to change notification settings - Fork 2
/
ma_ansi.c
815 lines (698 loc) · 29.2 KB
/
ma_ansi.c
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
/*************************************************************************************
Copyright (c) 2021 SingleStore, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not see <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*************************************************************************************/
#include <ma_odbc.h>
#include <ma_parse.h>
#include <odbc_3_api.h>
/**
* Funcions SQL<something> are usually mapped to:
* - MADB_Stmt<something> from MADB_StmtMethods
* (e.g. SQLColumnPrivileges is implemented in MADB_StmtColumnPrivileges) or
* - MADB_Dbc<something> from MADB_Dbc_Methods
* (e.g. SQLDriverConnect is implemented in MADB_DbcDriverConnect)
*/
/* {{{ SQLColAttribute */
SQLRETURN SQL_API SQLColAttribute (SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber,
SQLUSMALLINT FieldIdentifier,
SQLPOINTER CharacterAttributePtr,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLengthPtr,
#ifdef SQLCOLATTRIB_SQLPOINTER
SQLPOINTER NumericAttributePtr
#else
SQLLEN *NumericAttributePtr
#endif
)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLColAttribute");
MDBUG_C_DUMP(Stmt->Connection, StatementHandle, 0x);
MDBUG_C_DUMP(Stmt->Connection, ColumnNumber, u);
MDBUG_C_DUMP(Stmt->Connection, FieldIdentifier, u);
MDBUG_C_DUMP(Stmt->Connection, CharacterAttributePtr, 0x);
MDBUG_C_DUMP(Stmt->Connection, BufferLength, d);
MDBUG_C_DUMP(Stmt->Connection, StringLengthPtr, 0x);
MDBUG_C_DUMP(Stmt->Connection, NumericAttributePtr, 0x);
ret= Stmt->Methods->ColAttribute(Stmt, ColumnNumber, FieldIdentifier, CharacterAttributePtr,
BufferLength, StringLengthPtr, NumericAttributePtr, FALSE);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLColAttributes */
SQLRETURN SQL_API SQLColAttributes(SQLHSTMT hstmt,
SQLUSMALLINT icol,
SQLUSMALLINT fDescType,
SQLPOINTER rgbDesc,
SQLSMALLINT cbDescMax,
SQLSMALLINT * pcbDesc,
SQLLEN * pfDesc)
{
MADB_Stmt *Stmt= (MADB_Stmt *)hstmt;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->ColAttribute(Stmt, icol, MapColAttributeDescType(fDescType), rgbDesc,
cbDescMax, pcbDesc, pfDesc, FALSE);
}
/* }}} */
/* {{{ SQLColumnPrivileges */
SQLRETURN SQL_API SQLColumnPrivileges(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *TableName,
SQLSMALLINT NameLength3,
SQLCHAR *ColumnName,
SQLSMALLINT NameLength4)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLColumnPrivileges");
ret= Stmt->Methods->ColumnPrivileges(Stmt, (char *)CatalogName, NameLength1, (char *)SchemaName, NameLength2,
(char *)TableName, NameLength3, (char *)ColumnName, NameLength4);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLColumns */
SQLRETURN SQL_API SQLColumns(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *TableName,
SQLSMALLINT NameLength3,
SQLCHAR *ColumnName,
SQLSMALLINT NameLength4)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLColumns");
ret= Stmt->Methods->Columns(Stmt, (char *)CatalogName,NameLength1, (char *)SchemaName, NameLength2,
(char *)TableName, NameLength3, (char *)ColumnName, NameLength4);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLConnect */
SQLRETURN SQL_API SQLConnect(SQLHDBC ConnectionHandle,
SQLCHAR *ServerName,
SQLSMALLINT NameLength1,
SQLCHAR *UserName,
SQLSMALLINT NameLength2,
SQLCHAR *Authentication,
SQLSMALLINT NameLength3)
{
MADB_Dbc *Dbc= (MADB_Dbc*)ConnectionHandle;
if (!Dbc)
return SQL_INVALID_HANDLE;
Dbc->IsAnsi = 1;
return SQLConnectCommon(ConnectionHandle, ServerName, NameLength1,
UserName, NameLength2, Authentication, NameLength3);
}
/* }}} */
/* {{{ SQLDataSources */
SQLRETURN SQL_API SQLDataSources(SQLHENV EnvironmentHandle,
SQLUSMALLINT Direction,
SQLCHAR *ServerName,
SQLSMALLINT BufferLength1,
SQLSMALLINT *NameLength1Ptr,
SQLCHAR *Description,
SQLSMALLINT BufferLength2,
SQLSMALLINT *NameLength2Ptr)
{
SQLRETURN ret= SQL_ERROR;
return ret;
}
/* }}} */
/* {{{ SQLDescribeCol */
SQLRETURN SQL_API SQLDescribeCol(SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber,
SQLCHAR *ColumnName,
SQLSMALLINT BufferLength,
SQLSMALLINT *NameLengthPtr,
SQLSMALLINT *DataTypePtr,
SQLULEN *ColumnSizePtr,
SQLSMALLINT *DecimalDigitsPtr,
SQLSMALLINT *NullablePtr)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLDescribeCol");
MDBUG_C_DUMP(Stmt->Connection, Stmt, 0x);
MDBUG_C_DUMP(Stmt->Connection, ColumnNumber, u);
ret= Stmt->Methods->DescribeCol(Stmt, ColumnNumber, (void *)ColumnName, BufferLength,
NameLengthPtr, DataTypePtr, ColumnSizePtr, DecimalDigitsPtr,
NullablePtr, FALSE);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLDriverConnect */
SQLRETURN SQL_API SQLDriverConnect(SQLHDBC ConnectionHandle,
SQLHWND WindowHandle,
SQLCHAR *InConnectionString,
SQLSMALLINT StringLength1,
SQLCHAR *OutConnectionString,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLength2Ptr,
SQLUSMALLINT DriverCompletion)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
SQLRETURN ret;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
Dbc->IsAnsi = 1;
MDBUG_C_ENTER(Dbc, "SQLDriverConnect");
MDBUG_C_DUMP(Dbc, Dbc, 0x);
MDBUG_C_DUMP(Dbc, InConnectionString, s);
MDBUG_C_DUMP(Dbc, StringLength1, d);
MDBUG_C_DUMP(Dbc, OutConnectionString, 0x);
MDBUG_C_DUMP(Dbc, BufferLength, d);
MDBUG_C_DUMP(Dbc, StringLength2Ptr, 0x);
MDBUG_C_DUMP(Dbc, DriverCompletion, d);
ret= Dbc->Methods->DriverConnect(Dbc, WindowHandle, InConnectionString, StringLength1, OutConnectionString,
BufferLength, StringLength2Ptr, DriverCompletion);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
/* }}} */
/* {{{ SQLDrivers */
SQLRETURN SQL_API SQLDrivers(SQLHENV EnvironmentHandle,
SQLUSMALLINT Direction,
SQLCHAR *DriverDescription,
SQLSMALLINT BufferLength1,
SQLSMALLINT *DescriptionLengthPtr,
SQLCHAR *DriverAttributes,
SQLSMALLINT BufferLength2,
SQLSMALLINT *AttributesLengthPtr)
{
SQLRETURN ret= SQL_ERROR;
return ret;
}
/* }}} */
/* {{{ SQLExecDirect */
SQLRETURN SQL_API SQLExecDirect(SQLHSTMT StatementHandle,
SQLCHAR *StatementText,
SQLINTEGER TextLength)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
if (!Stmt)
ret= SQL_INVALID_HANDLE;
else
ret= Stmt->Methods->ExecDirect(Stmt, (char *)StatementText, TextLength);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
SQLRETURN SQL_API SQLGetConnectAttr(SQLHDBC ConnectionHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER *StringLengthPtr)
{
if (ConnectionHandle == SQL_NULL_HDBC)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&((MADB_Dbc *)ConnectionHandle)->Error);
return MA_SQLGetConnectAttr(ConnectionHandle, Attribute, ValuePtr, BufferLength, StringLengthPtr);
}
/* }}} */
/* {{{ SQLGetConnectOption */
SQLRETURN SQL_API SQLGetConnectOption(SQLHDBC ConnectionHandle, SQLUSMALLINT Option, SQLPOINTER ValuePtr)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
return MA_SQLGetConnectAttr(ConnectionHandle, Option, ValuePtr,
Option == SQL_ATTR_CURRENT_CATALOG ? SQL_MAX_OPTION_STRING_LENGTH : 0, NULL);
}
/* }}} */
/* {{{ SQLGetCursorName */
SQLRETURN SQL_API SQLGetCursorName(
SQLHSTMT StatementHandle,
SQLCHAR * CursorName,
SQLSMALLINT BufferLength,
SQLSMALLINT * NameLengthPtr)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->GetCursorName(Stmt, CursorName, BufferLength, NameLengthPtr, FALSE);
}
/* }}} */
/* {{{ SQLGetDescField */
SQLRETURN SQL_API SQLGetDescField(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber,
SQLSMALLINT FieldIdentifier,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER *StringLengthPtr)
{
if (!DescriptorHandle)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&((MADB_Desc*)DescriptorHandle)->Error);
return MADB_DescGetField(DescriptorHandle, RecNumber, FieldIdentifier, ValuePtr, BufferLength, StringLengthPtr, FALSE);
}
/* }}} */
/* {{{ SQLGetDescRec */
SQLRETURN SQL_API SQLGetDescRec(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber,
SQLCHAR *Name,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLengthPtr,
SQLSMALLINT *TypePtr,
SQLSMALLINT *SubTypePtr,
SQLLEN *LengthPtr,
SQLSMALLINT *PrecisionPtr,
SQLSMALLINT *ScalePtr,
SQLSMALLINT *NullablePtr)
{
MADB_Desc *Desc= (MADB_Desc *)DescriptorHandle;
if (!Desc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Desc->Error);
return MADB_DescGetRec(Desc, RecNumber, Name, BufferLength, StringLengthPtr, TypePtr, SubTypePtr,
LengthPtr, PrecisionPtr, ScalePtr, NullablePtr, FALSE);
}
/* }}} */
/* {{{ SQLGetDiagField */
SQLRETURN SQL_API SQLGetDiagField(SQLSMALLINT HandleType,
SQLHANDLE Handle,
SQLSMALLINT RecNumber,
SQLSMALLINT DiagIdentifier,
SQLPOINTER DiagInfoPtr,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLengthPtr)
{
if (!Handle)
return SQL_INVALID_HANDLE;
return MADB_GetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, DiagInfoPtr, BufferLength, StringLengthPtr, FALSE);
}
/* }}} */
SQLRETURN SQL_API SQLGetDiagRec(SQLSMALLINT HandleType,
SQLHANDLE Handle,
SQLSMALLINT RecNumber,
SQLCHAR *SQLState,
SQLINTEGER *NativeErrorPtr,
SQLCHAR *MessageText,
SQLSMALLINT BufferLength,
SQLSMALLINT *TextLengthPtr)
{
return MA_SQLGetDiagRec(HandleType, Handle, RecNumber, SQLState, NativeErrorPtr,
MessageText, BufferLength, TextLengthPtr);
}
/* }}} */
/* {{{ SQLGetInfo */
SQLRETURN SQL_API SQLGetInfo(SQLHDBC ConnectionHandle,
SQLUSMALLINT InfoType,
SQLPOINTER InfoValuePtr,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLengthPtr)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
SQLRETURN ret;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
MDBUG_C_ENTER(Dbc, "SQLGetInfo");
MDBUG_C_DUMP(Dbc, InfoType, d);
/* Linux DM overflows output buffer when SQLGetInfoW() is called with ANSI driver.
* The DM thinks that BufferLength is in SQLWCHARs, not in bytes.
*/
ret= Dbc->Methods->GetInfo(Dbc, InfoType, InfoValuePtr, BufferLength, StringLengthPtr, FALSE);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
/* }}} */
SQLRETURN SQL_API SQLGetStmtAttr(SQLHSTMT StatementHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER *StringLengthPtr)
{
if (StatementHandle == SQL_NULL_HSTMT)
{
return SQL_INVALID_HANDLE;
}
MADB_CLEAR_ERROR(&((MADB_Stmt*)StatementHandle)->Error);
return MA_SQLGetStmtAttr(StatementHandle, Attribute, ValuePtr, BufferLength, StringLengthPtr);
}
/* }}} */
/* {{{ SQLGetTypeInfo */
SQLRETURN SQL_API SQLGetTypeInfo(SQLHSTMT StatementHandle,
SQLSMALLINT DataType)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return MADB_GetTypeInfo(Stmt, DataType);
}
/* }}} */
/* {{{ SQLNativeSql */
SQLRETURN SQL_API SQLNativeSql(SQLHDBC ConnectionHandle,
SQLCHAR *InStatementText,
SQLINTEGER TextLength1,
SQLCHAR *OutStatementText,
SQLINTEGER BufferLength,
SQLINTEGER *TextLength2Ptr)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
SQLINTEGER Length;
char *InStatementStart, *InStatementEnd;
char **InStatementIterator;
MADB_DynString res;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
if (!TextLength2Ptr && (!OutStatementText || !BufferLength))
{
MADB_SetError(&Dbc->Error, MADB_ERR_01004, NULL, 0);
return Dbc->Error.ReturnValue;
}
if ((TextLength1 < 0 && TextLength1 != SQL_NTS) || (BufferLength < 0 && OutStatementText != NULL)) {
MADB_SetError(&Dbc->Error, MADB_ERR_HY090, NULL, 0);
return Dbc->Error.ReturnValue;
}
InStatementStart = (char *)InStatementText;
ADJUST_LENGTH(InStatementStart, TextLength1);
InStatementEnd = InStatementStart + TextLength1;
InStatementIterator = &InStatementStart;
if (MADB_UnescapeQuery(Dbc, &Dbc->Error, &res, InStatementIterator, &InStatementEnd, 0)) {
return Dbc->Error.ReturnValue;
}
Length= (SQLINTEGER)MADB_SetString(0, OutStatementText, BufferLength, (char *)res.str, res.length, &Dbc->Error);
MADB_DynstrFree(&res);
if (TextLength2Ptr)
*TextLength2Ptr= Length;
return Dbc->Error.ReturnValue;
}
/* }}} */
SQLRETURN SQL_API SQLPrepare(SQLHSTMT StatementHandle,
SQLCHAR *StatementText,
SQLINTEGER TextLength)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (StatementHandle == SQL_NULL_HSTMT)
{
return SQL_INVALID_HANDLE;
}
MDBUG_C_ENTER(Stmt->Connection, "SQLPrepare");
MDBUG_C_DUMP(Stmt->Connection, Stmt, 0x);
MDBUG_C_DUMP(Stmt->Connection, StatementText, s);
MDBUG_C_DUMP(Stmt->Connection, TextLength, d);
/* Prepare method clears error */
return Stmt->Methods->Prepare(Stmt, (char *)StatementText, TextLength, FALSE);
}
/* }}} */
/* {{{ SQLPrimaryKeys */
SQLRETURN SQL_API SQLPrimaryKeys(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *TableName,
SQLSMALLINT NameLength3)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
MDBUG_C_ENTER(Stmt->Connection, "SQLPrimaryKeys");
MDBUG_C_DUMP(Stmt->Connection, StatementHandle, 0x);
MDBUG_C_DUMP(Stmt->Connection, CatalogName, s);
MDBUG_C_DUMP(Stmt->Connection, NameLength1, d);
MDBUG_C_DUMP(Stmt->Connection, SchemaName, s);
MDBUG_C_DUMP(Stmt->Connection, NameLength2, d);
MDBUG_C_DUMP(Stmt->Connection, TableName, s);
MDBUG_C_DUMP(Stmt->Connection, NameLength3, d);
if (!Stmt)
ret= SQL_INVALID_HANDLE;
else
{
MADB_CLEAR_ERROR(&Stmt->Error);
ret= Stmt->Methods->PrimaryKeys(Stmt, (char *)CatalogName, NameLength1, (char *)SchemaName, NameLength2,
(char *)TableName, NameLength3);
}
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLProcedureColumns */
SQLRETURN SQL_API SQLProcedureColumns(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *ProcName,
SQLSMALLINT NameLength3,
SQLCHAR *ColumnName,
SQLSMALLINT NameLength4)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->ProcedureColumns(Stmt, (char *)CatalogName,NameLength1, (char *)SchemaName, NameLength2,
(char *)ProcName, NameLength3, (char *)ColumnName, NameLength4);
}
/* }}} */
/* {{{ SQLProcedures */
SQLRETURN SQL_API SQLProcedures(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *ProcName,
SQLSMALLINT NameLength3)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->Procedures(Stmt, (char *)CatalogName, NameLength1, (char *)SchemaName,
NameLength2, (char *)ProcName, NameLength3);
}
/* }}} */
SQLRETURN SQL_API SQLSetConnectAttr(SQLHDBC ConnectionHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER StringLength)
{
if (ConnectionHandle == SQL_NULL_HDBC)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&((MADB_Dbc *)ConnectionHandle)->Error);
return MA_SQLSetConnectAttr(ConnectionHandle, Attribute, ValuePtr, StringLength);
}
/* {{{ SQLSetConnectOption */
SQLRETURN SQL_API SQLSetConnectOption(SQLHDBC Hdbc, SQLUSMALLINT Option, SQLULEN Param)
{
SQLINTEGER StringLength= 0;
SQLRETURN ret;
if (!Hdbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&((MADB_Dbc*)Hdbc)->Error);
/* todo: do we have more string options ? */
if (Option == SQL_ATTR_CURRENT_CATALOG)
StringLength= SQL_NTS;
ret= MA_SQLSetConnectAttr(Hdbc, Option, (SQLPOINTER)Param, StringLength);
return ret;
}
/* }}} */
/* {{{ SQLSetCursorName */
SQLRETURN SQL_API SQLSetCursorName(SQLHSTMT StatementHandle,
SQLCHAR *CursorName,
SQLSMALLINT NameLength)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->SetCursorName(Stmt, (char *)CursorName, NameLength);
}
/* }}} */
/* {{{ SQLSetDescField */
SQLRETURN SQL_API SQLSetDescField(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber,
SQLSMALLINT FieldIdentifier,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength)
{
MADB_Desc *Desc= (MADB_Desc *)DescriptorHandle;
if (!Desc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Desc->Error);
return MADB_DescSetField(DescriptorHandle, RecNumber, FieldIdentifier, ValuePtr, BufferLength, FALSE);
}
/* }}} */
/* {{{ SQLSetDescRec */
// TODO PLAT-5516
SQLRETURN SQL_API SQLSetDescRec(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber,
SQLSMALLINT Type,
SQLSMALLINT SubType,
SQLLEN Length,
SQLSMALLINT Precision,
SQLSMALLINT Scale,
SQLPOINTER DataPtr,
SQLLEN *StringLengthPtr,
SQLLEN *IndicatorPtr)
{
MADB_Desc *Desc= (MADB_Desc *)DescriptorHandle;
MADB_NOT_IMPLEMENTED(Desc);
}
/* }}} */
/* {{{ SQLSetStmtAttr */
SQLRETURN SQL_API SQLSetStmtAttr(SQLHSTMT StatementHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER StringLength)
{
if (StatementHandle == SQL_NULL_HSTMT)
{
return SQL_INVALID_HANDLE;
}
MADB_CLEAR_ERROR(&((MADB_Stmt*)StatementHandle)->Error);
return MA_SQLSetStmtAttr(StatementHandle, Attribute, ValuePtr, StringLength);
}
/* }}} */
/* {{{ SQLSpecialColumns */
SQLRETURN SQL_API SQLSpecialColumns(SQLHSTMT StatementHandle,
SQLUSMALLINT IdentifierType,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *TableName,
SQLSMALLINT NameLength3,
SQLUSMALLINT Scope,
SQLUSMALLINT Nullable)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->SpecialColumns(Stmt,IdentifierType, (char *)CatalogName, NameLength1,
(char *)SchemaName, NameLength2,
(char *)TableName, NameLength3, Scope, Nullable);
}
/* }}} */
/* {{{ SQLStatistics */
SQLRETURN SQL_API SQLStatistics(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *TableName,
SQLSMALLINT NameLength3,
SQLUSMALLINT Unique,
SQLUSMALLINT Reserved)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->Statistics(Stmt, (char *)CatalogName, NameLength1, (char *)SchemaName, NameLength2,
(char *)TableName, NameLength3, Unique, Reserved);
}
/* }}} */
/* {{{ SQLTablePrivileges */
SQLRETURN SQL_API SQLTablePrivileges(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *TableName,
SQLSMALLINT NameLength3)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->TablePrivileges(Stmt, (char *)CatalogName, NameLength1, (char *)SchemaName, NameLength2,
(char *)TableName, NameLength3);
}
/* }}} */
/* {{{ SQLTables */
SQLRETURN SQL_API SQLTables(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *TableName,
SQLSMALLINT NameLength3,
SQLCHAR *TableType,
SQLSMALLINT NameLength4)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->Tables(Stmt, (char *)CatalogName, NameLength1, (char *)SchemaName, NameLength2,
(char *)TableName,NameLength3, (char *)TableType, NameLength4);
}
/* }}} */
/* {{{ SQLError */
SQLRETURN SQL_API SQLError(SQLHENV Env, SQLHDBC Dbc, SQLHSTMT Stmt,
SQLCHAR *Sqlstate, SQLINTEGER *NativeError,
SQLCHAR *Message, SQLSMALLINT MessageMax,
SQLSMALLINT *MessageLen)
{
SQLSMALLINT HandleType= 0;
SQLHANDLE Handle= NULL;
MADB_Error *error;
if (Stmt)
{
MDBUG_C_ENTER(((MADB_Stmt*)Stmt)->Connection, "SQLError->SQLGetDiagRec");
MDBUG_C_DUMP(((MADB_Stmt*)Stmt)->Connection, Env, 0x);
MDBUG_C_DUMP(((MADB_Stmt*)Stmt)->Connection, Dbc, 0x);
MDBUG_C_DUMP(((MADB_Stmt*)Stmt)->Connection, Stmt, 0x);
Handle= Stmt;
HandleType= SQL_HANDLE_STMT;
error= &((MADB_Stmt*)Stmt)->Error;
}
else if (Dbc)
{
MDBUG_C_ENTER((MADB_Dbc*)Dbc, "SQLError->SQLGetDiagRec");
MDBUG_C_DUMP((MADB_Dbc*)Dbc, Env, 0x);
MDBUG_C_DUMP((MADB_Dbc*)Dbc, Dbc, 0x);
MDBUG_C_DUMP((MADB_Dbc*)Dbc, Stmt, 0x);
Handle= Dbc;
HandleType= SQL_HANDLE_DBC;
error= &((MADB_Dbc*)Dbc)->Error;
}
else
{
MDBUG_ENTER("SQLError->SQLGetDiagRec");
MDBUG_DUMP(Env, 0x);
MDBUG_DUMP(Dbc, 0x);
MDBUG_DUMP(Stmt, 0x);
Handle= Env;
HandleType= SQL_HANDLE_ENV;
error= &((MADB_Env*)Env)->Error;
}
return MA_SQLGetDiagRec(HandleType, Handle, ++error->ErrorNum, Sqlstate, NativeError, Message, MessageMax, MessageLen);
}
/* }}} */