-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathma_unicode.c
1166 lines (1013 loc) · 41.2 KB
/
ma_unicode.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
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
/*************************************************************************************
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>
extern Client_Charset utf8;
/**
* Funcions SQL<something>W 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)
*/
/* {{{ SQLColAttributeW */
SQLRETURN SQL_API SQLColAttributeW (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, "SQLColAttributeW");
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, TRUE);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLColAttributesW */
SQLRETURN SQL_API SQLColAttributesW(SQLHSTMT hstmt,
SQLUSMALLINT icol,
SQLUSMALLINT fDescType,
SQLPOINTER rgbDesc,
SQLSMALLINT cbDescMax,
SQLSMALLINT * pcbDesc,
SQLLEN * pfDesc)
{
/* TODO: use internal function, not api */
return SQLColAttributeW(hstmt, icol, MapColAttributeDescType(fDescType), rgbDesc, cbDescMax, pcbDesc, pfDesc);
}
/* }}} */
/* {{{ SQLColumnPrivilegesW */
SQLRETURN SQL_API SQLColumnPrivilegesW(SQLHSTMT StatementHandle,
SQLWCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLWCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLWCHAR *TableName,
SQLSMALLINT NameLength3,
SQLWCHAR *ColumnName,
SQLSMALLINT NameLength4)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLULEN CpLength1, CpLength2, CpLength3, CpLength4;
char *CpCatalog= NULL,
*CpSchema= NULL,
*CpTable= NULL,
*CpColumn= NULL;
SQLRETURN ret;
if (!StatementHandle)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLColumnPrivilegesW");
CpCatalog= MADB_ConvertFromWChar(CatalogName, NameLength1, &CpLength1, Stmt->Connection->ConnOrSrcCharset, NULL);
CpSchema= MADB_ConvertFromWChar(SchemaName, NameLength2, &CpLength2, Stmt->Connection->ConnOrSrcCharset, NULL);
CpTable= MADB_ConvertFromWChar(TableName, NameLength3, &CpLength3, Stmt->Connection->ConnOrSrcCharset, NULL);
CpColumn= MADB_ConvertFromWChar(ColumnName, NameLength4, &CpLength4, Stmt->Connection->ConnOrSrcCharset, NULL);
ret= Stmt->Methods->ColumnPrivileges(Stmt, CpCatalog, (SQLSMALLINT)CpLength1, CpSchema, (SQLSMALLINT)CpLength2,
CpTable, (SQLSMALLINT)CpLength3, CpColumn, (SQLSMALLINT)CpLength4);
MADB_FREE(CpCatalog);
MADB_FREE(CpSchema);
MADB_FREE(CpTable);
MADB_FREE(CpColumn);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLColumnsW */
SQLRETURN SQL_API SQLColumnsW(SQLHSTMT StatementHandle,
SQLWCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLWCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLWCHAR *TableName,
SQLSMALLINT NameLength3,
SQLWCHAR *ColumnName,
SQLSMALLINT NameLength4)
{
char *CpCatalog= NULL,
*CpSchema= NULL,
*CpTable= NULL,
*CpColumn= NULL;
SQLULEN CpLength1= 0, CpLength2= 0, CpLength3= 0, CpLength4= 0;
SQLRETURN ret;
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLColumns");
if (CatalogName != NULL)
{
CpCatalog= MADB_ConvertFromWChar(CatalogName, NameLength1, &CpLength1, Stmt->Connection->ConnOrSrcCharset, NULL);
}
if (SchemaName != NULL)
{
CpSchema= MADB_ConvertFromWChar(SchemaName, NameLength2, &CpLength2, Stmt->Connection->ConnOrSrcCharset, NULL);
}
if (TableName != NULL)
{
CpTable= MADB_ConvertFromWChar(TableName, NameLength3, &CpLength3, Stmt->Connection->ConnOrSrcCharset, NULL);
}
if (ColumnName != NULL)
{
CpColumn= MADB_ConvertFromWChar(ColumnName, NameLength4, &CpLength4, Stmt->Connection->ConnOrSrcCharset, NULL);
}
ret= Stmt->Methods->Columns(Stmt, CpCatalog, (SQLSMALLINT)CpLength1, CpSchema, (SQLSMALLINT)CpLength2,
CpTable, (SQLSMALLINT)CpLength3, CpColumn, (SQLSMALLINT)CpLength4);
MADB_FREE(CpCatalog);
MADB_FREE(CpSchema);
MADB_FREE(CpTable);
MADB_FREE(CpColumn);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLConnectW */
SQLRETURN SQL_API SQLConnectW(SQLHDBC ConnectionHandle,
SQLWCHAR *ServerName,
SQLSMALLINT NameLength1,
SQLWCHAR *UserName,
SQLSMALLINT NameLength2,
SQLWCHAR *Authentication,
SQLSMALLINT NameLength3)
{
char *MBServerName= NULL, *MBUserName= NULL, *MBAuthentication= NULL;
SQLRETURN ret;
MADB_Dbc *Dbc= (MADB_Dbc*)ConnectionHandle;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
Dbc->IsAnsi = 0;
/* Convert parameters to Cp */
if (ServerName)
MBServerName= MADB_ConvertFromWChar(ServerName, NameLength1, 0, &utf8, NULL);
if (UserName)
{
MBUserName= MADB_ConvertFromWChar(UserName, NameLength2, 0, &utf8, NULL);
}
if (Authentication)
{
MBAuthentication= MADB_ConvertFromWChar(Authentication, NameLength3, 0, &utf8, NULL);
}
ret= SQLConnectCommon(ConnectionHandle, (SQLCHAR *)MBServerName, SQL_NTS, (SQLCHAR *)MBUserName, SQL_NTS,
(SQLCHAR *)MBAuthentication, SQL_NTS);
MADB_FREE(MBServerName);
MADB_FREE(MBUserName);
MADB_FREE(MBAuthentication);
return ret;
}
/* }}} */
/* {{{ SQLDataSourcesW */
SQLRETURN SQL_API SQLDataSourcesW(SQLHENV EnvironmentHandle,
SQLUSMALLINT Direction,
SQLWCHAR *ServerName,
SQLSMALLINT BufferLength1,
SQLSMALLINT *NameLength1Ptr,
SQLWCHAR *Description,
SQLSMALLINT BufferLength2,
SQLSMALLINT *NameLength2Ptr)
{
SQLRETURN ret= SQL_ERROR;
return ret;
}
/* }}} */
/* {{{ SQLDescribeColW */
SQLRETURN SQL_API SQLDescribeColW(SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber,
SQLWCHAR *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, "SQLDescribeColW");
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, TRUE);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLDriverConnectW */
SQLRETURN SQL_API SQLDriverConnectW(SQLHDBC ConnectionHandle,
SQLHWND WindowHandle,
SQLWCHAR *InConnectionString,
SQLSMALLINT StringLength1,
SQLWCHAR *OutConnectionString,
SQLSMALLINT BufferLength,
SQLSMALLINT *StringLength2Ptr,
SQLUSMALLINT DriverCompletion)
{
SQLRETURN ret= SQL_ERROR;
SQLULEN Length= 0; /* Since we need bigger(in bytes) buffer for utf8 string, the length may be > max SQLSMALLINT */
char *InConnStrA= NULL;
SQLULEN InStrAOctLen= 0;
char *OutConnStrA= NULL;
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
if (!ConnectionHandle)
{
return SQL_INVALID_HANDLE;
}
MDBUG_C_ENTER(Dbc, "SQLDriverConnectW");
MADB_CLEAR_ERROR(&Dbc->Error);
Dbc->IsAnsi = 0;
InConnStrA= MADB_ConvertFromWChar(InConnectionString, StringLength1, &InStrAOctLen, &utf8, NULL);
MDBUG_C_DUMP(Dbc, Dbc, 0x);
MDBUG_C_DUMP(Dbc, InConnStrA, 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);
/* Allocate buffer for Asc OutConnectionString */
if (OutConnectionString && BufferLength)
{
Length= BufferLength*4 /*Max bytes per utf8 character */;
OutConnStrA= (char *)MADB_CALLOC(Length);
if (OutConnStrA == NULL)
{
ret= MADB_SetError(&Dbc->Error, MADB_ERR_HY001, NULL, 0);
goto end;
}
}
ret= Dbc->Methods->DriverConnect(Dbc, WindowHandle, (SQLCHAR *)InConnStrA, InStrAOctLen, (SQLCHAR *)OutConnStrA,
Length, StringLength2Ptr, DriverCompletion);
MDBUG_C_DUMP(Dbc, ret, d);
if (!SQL_SUCCEEDED(ret))
goto end;
if (OutConnectionString)
{
Length= MADB_SetString(&utf8, OutConnectionString, BufferLength,
OutConnStrA, SQL_NTS, &((MADB_Dbc *)ConnectionHandle)->Error);
if (StringLength2Ptr)
*StringLength2Ptr= (SQLSMALLINT)Length;
}
end:
MADB_FREE(OutConnStrA);
MADB_FREE(InConnStrA);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
/* }}} */
/* {{{ SQLDriversW */
SQLRETURN SQL_API SQLDriversW(SQLHENV EnvironmentHandle,
SQLUSMALLINT Direction,
SQLWCHAR *DriverDescription,
SQLSMALLINT BufferLength1,
SQLSMALLINT *DescriptionLengthPtr,
SQLWCHAR *DriverAttributes,
SQLSMALLINT BufferLength2,
SQLSMALLINT *AttributesLengthPtr)
{
SQLRETURN ret= SQL_ERROR;
return ret;
}
/* }}} */
/* {{{ SQLExecDirectW */
SQLRETURN SQL_API SQLExecDirectW(SQLHSTMT StatementHandle,
SQLWCHAR *StatementText,
SQLINTEGER TextLength)
{
char *CpStmt;
SQLULEN StmtLength;
SQLRETURN ret;
BOOL ConversionError;
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLExecDirectW");
MDBUG_C_DUMP(Stmt->Connection, Stmt, 0x);
CpStmt= MADB_ConvertFromWChar(StatementText, TextLength, &StmtLength, Stmt->Connection->ConnOrSrcCharset, &ConversionError);
MDBUG_C_DUMP(Stmt->Connection, CpStmt, s);
if (ConversionError)
{
MADB_SetError(&Stmt->Error, MADB_ERR_22018, NULL, 0);
ret= Stmt->Error.ReturnValue;
}
else
ret= Stmt->Methods->ExecDirect(Stmt, CpStmt, (SQLINTEGER)StmtLength);
MADB_FREE(CpStmt);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLGetConnectAttrW */
SQLRETURN SQL_API SQLGetConnectAttrW(SQLHDBC ConnectionHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER *StringLengthPtr)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
SQLRETURN ret;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
MDBUG_C_ENTER(Dbc, "SQLGetConnectAttr");
MDBUG_C_DUMP(Dbc, Attribute, d);
MDBUG_C_DUMP(Dbc, ValuePtr, 0x);
MDBUG_C_DUMP(Dbc, BufferLength, d);
MDBUG_C_DUMP(Dbc, StringLengthPtr, 0x);
ret= Dbc->Methods->GetConnectAttr(Dbc, Attribute, ValuePtr, BufferLength, StringLengthPtr, TRUE);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
/* }}} */
/* {{{ SQLGetConnectOptionW */
SQLRETURN SQL_API SQLGetConnectOptionW(SQLHDBC ConnectionHandle, SQLUSMALLINT Option, SQLPOINTER ValuePtr)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
return SQLGetConnectAttrW(ConnectionHandle, Option, ValuePtr,
Option == SQL_ATTR_CURRENT_CATALOG ? SQL_MAX_OPTION_STRING_LENGTH : 0, NULL);
}
/* }}} */
/* {{{ SQLGetCursorNameW */
SQLRETURN SQL_API SQLGetCursorNameW(
SQLHSTMT StatementHandle,
SQLWCHAR * 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, TRUE);
}
/* }}} */
/* {{{ SQLGetDescFieldW */
SQLRETURN SQL_API SQLGetDescFieldW(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, TRUE);
}
/* }}} */
/* {{{ SQLGetDescRecW */
SQLRETURN SQL_API SQLGetDescRecW(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber,
SQLWCHAR *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, (SQLCHAR *)Name, BufferLength, StringLengthPtr, TypePtr, SubTypePtr,
LengthPtr, PrecisionPtr, ScalePtr, NullablePtr, TRUE);
}
/* }}} */
/* {{{ SQLGetDiagFieldW */
SQLRETURN SQL_API SQLGetDiagFieldW(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, TRUE);
}
/* }}} */
/* {{{ MA_SQLGetDiagRecW */
SQLRETURN SQL_API MA_SQLGetDiagRecW(SQLSMALLINT HandleType,
SQLHANDLE Handle,
SQLSMALLINT RecNumber,
SQLWCHAR *SQLState,
SQLINTEGER *NativeErrorPtr,
SQLWCHAR *MessageText,
SQLSMALLINT BufferLength,
SQLSMALLINT *TextLengthPtr)
{
if (!Handle)
return SQL_INVALID_HANDLE;
/* Maria ODBC driver doesn't support error lists, so only the first record can be retrieved */
if (RecNumber != 1)
return SQL_NO_DATA_FOUND;
switch (HandleType) {
case SQL_HANDLE_DBC:
{
MADB_Dbc *Dbc= (MADB_Dbc *)Handle;
return MADB_GetDiagRec(&Dbc->Error, RecNumber, (void *)SQLState, NativeErrorPtr,
(void *)MessageText, BufferLength, TextLengthPtr, TRUE,
Dbc->Environment->OdbcVersion);
}
break;
case SQL_HANDLE_STMT:
{
MADB_Stmt *Stmt= (MADB_Stmt *)Handle;
return MADB_GetDiagRec(&Stmt->Error, RecNumber, (void *)SQLState, NativeErrorPtr,
(void *)MessageText, BufferLength, TextLengthPtr, TRUE,
Stmt->Connection->Environment->OdbcVersion);
}
break;
case SQL_HANDLE_DESC:
{
MADB_Desc *Desc= (MADB_Desc *)Handle;
return MADB_GetDiagRec(&Desc->Error, RecNumber, (void *)SQLState, NativeErrorPtr,
(void *)MessageText, BufferLength, TextLengthPtr, TRUE,
SQL_OV_ODBC3);
}
break;
case SQL_HANDLE_ENV:
{
MADB_Env *Env= (MADB_Env *)Handle;
return MADB_GetDiagRec(&Env->Error, RecNumber, (void *)SQLState, NativeErrorPtr,
(void *)MessageText, BufferLength, TextLengthPtr, TRUE,
Env->OdbcVersion);
}
default:
return SQL_ERROR;
break;
}
}
/* }}} */
/*{{{ SQLErrorW */
SQLRETURN SQL_API SQLErrorW(SQLHENV Env,
SQLHDBC Dbc,
SQLHSTMT Stmt,
SQLWCHAR *Sqlstate,
SQLINTEGER *NativeError,
SQLWCHAR *Message,
SQLSMALLINT MessageMax,
SQLSMALLINT *MessageLen)
{
SQLSMALLINT HandleType= 0;
SQLHANDLE Handle= NULL;
MADB_Error *error;
if (Stmt)
{
Handle= Stmt;
HandleType= SQL_HANDLE_STMT;
error= &((MADB_Stmt*)Stmt)->Error;
}
else if (Dbc)
{
Handle= Dbc;
HandleType= SQL_HANDLE_DBC;
error= &((MADB_Dbc*)Dbc)->Error;
}
else
{
Handle= Env;
HandleType= SQL_HANDLE_ENV;
error= &((MADB_Env*)Env)->Error;
}
return MA_SQLGetDiagRecW(HandleType, Handle, ++error->ErrorNum, Sqlstate, NativeError, Message, MessageMax, MessageLen);
}
/* }}} */
/* {{{ SQLGetDiagRecW */
SQLRETURN SQL_API SQLGetDiagRecW(SQLSMALLINT HandleType,
SQLHANDLE Handle,
SQLSMALLINT RecNumber,
SQLWCHAR *SQLState,
SQLINTEGER *NativeErrorPtr,
SQLWCHAR *MessageText,
SQLSMALLINT BufferLength,
SQLSMALLINT *TextLengthPtr)
{
return MA_SQLGetDiagRecW(HandleType, Handle, RecNumber, SQLState, NativeErrorPtr, MessageText,
BufferLength, TextLengthPtr);
}
/* }}} */
/* {{{ SQLGetInfoW */
SQLRETURN SQL_API SQLGetInfoW(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);
MDBUG_C_DUMP(Dbc, InfoValuePtr, 0x);
MDBUG_C_DUMP(Dbc, StringLengthPtr, 0x);
ret= Dbc->Methods->GetInfo(Dbc, InfoType, InfoValuePtr, BufferLength, StringLengthPtr, TRUE);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
/* }}} */
/* {{{ SQLGetStmtAttrW */
SQLRETURN SQL_API SQLGetStmtAttrW(SQLHSTMT StatementHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER *StringLengthPtr)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
return Stmt->Methods->GetStmtAttr(Stmt, Attribute, ValuePtr, BufferLength, StringLengthPtr);
}
/* }}} */
/* {{{ SQLGetTypeInfoW */
SQLRETURN SQL_API SQLGetTypeInfoW(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);}
/* }}} */
/* {{{ SQLNativeSqlW */
SQLRETURN SQL_API SQLNativeSqlW(SQLHDBC ConnectionHandle,
SQLWCHAR *InStatementText,
SQLINTEGER TextLength1,
SQLWCHAR *OutStatementText,
SQLINTEGER BufferLength,
SQLINTEGER *TextLength2Ptr)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
char *InStmtStr;
SQLULEN InLength;
BOOL ConversionError;
char *InStatementStart, *InStatementEnd;
char **InStatementIterator;
SQLINTEGER OutLength;
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;
}
InStmtStr= MADB_ConvertFromWChar(InStatementText, TextLength1, &InLength, Dbc->ConnOrSrcCharset, &ConversionError);
if (ConversionError)
{
MADB_SetError(&Dbc->Error, MADB_ERR_22018, NULL, 0);
return Dbc->Error.ReturnValue;
}
InStatementStart = (char *)InStmtStr;
InStatementEnd = InStmtStr + InLength;
InStatementIterator = &InStatementStart;
if (MADB_UnescapeQuery(Dbc, &Dbc->Error, &res, InStatementIterator, &InStatementEnd, 0)) {
MADB_FREE(InStmtStr);
return Dbc->Error.ReturnValue;
}
OutLength= (SQLINTEGER)MADB_SetString(&Dbc->Charset, OutStatementText, BufferLength, (char *)res.str, res.length, &Dbc->Error);
MADB_DynstrFree(&res);
if (TextLength2Ptr)
*TextLength2Ptr= OutLength;
MADB_FREE(InStmtStr);
return Dbc->Error.ReturnValue;
}
/* }}} */
/* {{{ SQLPrepareW */
SQLRETURN SQL_API SQLPrepareW(SQLHSTMT StatementHandle,
SQLWCHAR *StatementText,
SQLINTEGER TextLength)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
char *StmtStr;
SQLULEN StmtLength;
SQLRETURN ret;
BOOL ConversionError;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
MDBUG_C_ENTER(Stmt->Connection, "SQLPrepareW");
StmtStr= MADB_ConvertFromWChar(StatementText, TextLength, &StmtLength, Stmt->Connection->ConnOrSrcCharset, &ConversionError);
MDBUG_C_DUMP(Stmt->Connection, Stmt, 0x);
MDBUG_C_DUMP(Stmt->Connection, StmtStr, s);
MDBUG_C_DUMP(Stmt->Connection, TextLength, d);
if (ConversionError)
{
MADB_SetError(&Stmt->Error, MADB_ERR_22018, NULL, 0);
ret= Stmt->Error.ReturnValue;
}
else
ret= Stmt->Methods->Prepare(Stmt, StmtStr, (SQLINTEGER)StmtLength, FALSE);
MADB_FREE(StmtStr);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLPrimaryKeysW */
SQLRETURN SQL_API SQLPrimaryKeysW(SQLHSTMT StatementHandle,
SQLWCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLWCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLWCHAR *TableName,
SQLSMALLINT NameLength3)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
char *CpCatalog= NULL,
*CpSchema= NULL,
*CpTable= NULL;
SQLULEN CpLength1, CpLength2, CpLength3;
SQLRETURN ret;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
CpCatalog= MADB_ConvertFromWChar(CatalogName, NameLength1, &CpLength1, Stmt->Connection->ConnOrSrcCharset, NULL);
CpSchema= MADB_ConvertFromWChar(SchemaName, NameLength2, &CpLength2, Stmt->Connection->ConnOrSrcCharset, NULL);
CpTable= MADB_ConvertFromWChar(TableName, NameLength3, &CpLength3, Stmt->Connection->ConnOrSrcCharset, NULL);
MDBUG_C_ENTER(Stmt->Connection, "SQLPrimaryKeysW");
MDBUG_C_DUMP(Stmt->Connection, StatementHandle, 0x);
MDBUG_C_DUMP(Stmt->Connection, CpCatalog, s);
MDBUG_C_DUMP(Stmt->Connection, CpLength1, d);
MDBUG_C_DUMP(Stmt->Connection, CpSchema, s);
MDBUG_C_DUMP(Stmt->Connection, CpLength2, d);
MDBUG_C_DUMP(Stmt->Connection, CpTable, s);
MDBUG_C_DUMP(Stmt->Connection, CpLength3, d);
ret= Stmt->Methods->PrimaryKeys(Stmt, CpCatalog, (SQLSMALLINT)CpLength1, CpSchema, (SQLSMALLINT)CpLength2,
CpTable, (SQLSMALLINT)CpLength3);
MADB_FREE(CpCatalog);
MADB_FREE(CpSchema);
MADB_FREE(CpTable);
MDBUG_C_RETURN(Stmt->Connection, ret, &Stmt->Error);
}
/* }}} */
/* {{{ SQLProcedureColumnsW */
SQLRETURN SQL_API SQLProcedureColumnsW(SQLHSTMT StatementHandle,
SQLWCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLWCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLWCHAR *ProcName,
SQLSMALLINT NameLength3,
SQLWCHAR *ColumnName,
SQLSMALLINT NameLength4)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
char *CpCatalog= NULL,
*CpSchema= NULL,
*CpProc= NULL,
*CpColumn= NULL;
SQLULEN CpLength1= 0, CpLength2= 0, CpLength3= 0, CpLength4= 0;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
if (CatalogName != NULL)
{
CpCatalog= MADB_ConvertFromWChar(CatalogName, NameLength1, &CpLength1, Stmt->Connection->ConnOrSrcCharset, NULL);
}
if (SchemaName != NULL)
{
CpSchema= MADB_ConvertFromWChar(SchemaName, NameLength2, &CpLength2, Stmt->Connection->ConnOrSrcCharset, NULL);
}
if (ProcName != NULL)
{
CpProc= MADB_ConvertFromWChar(ProcName, NameLength3, &CpLength3, Stmt->Connection->ConnOrSrcCharset, NULL);
}
if (ColumnName != NULL)
{
CpColumn= MADB_ConvertFromWChar(ColumnName, NameLength4, &CpLength4, Stmt->Connection->ConnOrSrcCharset, NULL);
}
ret= Stmt->Methods->ProcedureColumns(Stmt, CpCatalog, (SQLSMALLINT)CpLength1, CpSchema, (SQLSMALLINT)CpLength2,
CpProc, (SQLSMALLINT)CpLength3, CpColumn, (SQLSMALLINT)CpLength4);
MADB_FREE(CpCatalog);
MADB_FREE(CpSchema);
MADB_FREE(CpProc);
MADB_FREE(CpColumn);
return ret;
}
/* }}} */
/* {{{ SQLProceduresW */
SQLRETURN SQL_API SQLProceduresW(SQLHSTMT StatementHandle,
SQLWCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLWCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLWCHAR *ProcName,
SQLSMALLINT NameLength3)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
SQLRETURN ret;
char *CpCatalog= NULL,
*CpSchema= NULL,
*CpProc= NULL;
SQLULEN CpLength1, CpLength2, CpLength3;
if (!Stmt)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Stmt->Error);
CpCatalog= MADB_ConvertFromWChar(CatalogName, NameLength1, &CpLength1, Stmt->Connection->ConnOrSrcCharset, NULL);
CpSchema= MADB_ConvertFromWChar(SchemaName, NameLength2, &CpLength2, Stmt->Connection->ConnOrSrcCharset, NULL);
CpProc= MADB_ConvertFromWChar(ProcName, NameLength3, &CpLength3, Stmt->Connection->ConnOrSrcCharset, NULL);
ret= Stmt->Methods->Procedures(Stmt, CpCatalog, (SQLSMALLINT)CpLength1, CpSchema, (SQLSMALLINT)CpLength2,
CpProc, (SQLSMALLINT)CpLength3);
MADB_FREE(CpCatalog);
MADB_FREE(CpSchema);
MADB_FREE(CpProc);
return ret;
}
/* }}} */
/* {{{ SQLSetConnectAttrW */
SQLRETURN SQL_API SQLSetConnectAttrW(SQLHDBC ConnectionHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER StringLength)
{
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
SQLRETURN ret;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
MDBUG_C_ENTER(Dbc, "SetConnectAttrW");
MDBUG_C_DUMP(Dbc, Dbc, 0x);
MDBUG_C_DUMP(Dbc, Attribute, d);
MDBUG_C_DUMP(Dbc, ValuePtr, 0x);
MDBUG_C_DUMP(Dbc, StringLength, d);
ret= Dbc->Methods->SetConnectAttr(Dbc, Attribute, ValuePtr, StringLength, TRUE);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
/* }}} */
/* {{{ SQLSetConnectOptionW */
SQLRETURN SQL_API SQLSetConnectOptionW(SQLHDBC Hdbc, SQLUSMALLINT Option, SQLULEN Param)
{
SQLINTEGER StringLength= 0;
SQLRETURN ret;
MADB_Dbc *Dbc= (MADB_Dbc *)Hdbc;
if (!Dbc)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
MDBUG_C_ENTER(Dbc, "SetSetConnectOptionW");
MDBUG_C_DUMP(Dbc, Option, d);
MDBUG_C_DUMP(Dbc, Param, u);
/* todo: do we have more string options ? */
if (Option == SQL_ATTR_CURRENT_CATALOG)
StringLength= SQL_NTS;
ret= Dbc->Methods->SetConnectAttr(Dbc, Option, (SQLPOINTER)Param, StringLength, TRUE);
MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}
/* }}} */
/* {{{ SQLSetCursorNameW */
SQLRETURN SQL_API SQLSetCursorNameW(SQLHSTMT StatementHandle,
SQLWCHAR *CursorName,
SQLSMALLINT NameLength)
{
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
char *CpName= NULL;
SQLULEN Length;
SQLRETURN rc;
if (!Stmt)
{
return SQL_INVALID_HANDLE;
}
MADB_CLEAR_ERROR(&Stmt->Error);
CpName= MADB_ConvertFromWChar(CursorName, NameLength, &Length, Stmt->Connection->ConnOrSrcCharset, NULL);
rc= Stmt->Methods->SetCursorName(Stmt, (char *)CpName, (SQLINTEGER)Length);
MADB_FREE(CpName);
return rc;
}
/* }}} */
/* {{{ SQLSetDescFieldW */
SQLRETURN SQL_API SQLSetDescFieldW(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, TRUE);
}
/* }}} */
/* {{{ SQLSetDescRecW */
SQLRETURN SQL_API SQLSetDescRecW(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);
}
/* }}} */
/* {{{ SQLSetStmtAttrW */
SQLRETURN SQL_API SQLSetStmtAttrW(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);
}
/* }}} */
/* {{{ SQLSpecialColumnsW */