forked from CUBRID/cubrid-odbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
odbc_interface.c
2660 lines (2010 loc) · 67.3 KB
/
odbc_interface.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) 2008 Search Solution Corporation. All rights reserved by Search Solution.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of the <ORGANIZATION> nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
*/
#include <windows.h>
#include <stdio.h>
#include "odbc_portable.h"
#include "sqlext.h"
#include "odbc_connection.h"
#include "odbc_env.h"
#include "odbc_statement.h"
#include "odbc_result.h"
#include "odbc_diag_record.h"
#include "odbc_util.h"
#include "odbc_catalog.h"
#include "odbc_descriptor.h"
#include "cas_cci.h"
#include "odbc_resource.h"
//#include "setup.h"
PUBLIC INT_PTR CALLBACK
ConfigDSNDlgProc (HWND hwndParent, UINT message, WPARAM wParam,
LPARAM lParam);
typedef struct __st_DriverConnectInfo
{
/* Deprecated
char db_name[VALUEBUFLEN];
*/
char user[ITEMBUFLEN];
char pwd[ITEMBUFLEN];
} DriverConnectInfo;
PRIVATE INT_PTR CALLBACK
ConnectDlgProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
PUBLIC HINSTANCE hInstance;
BOOL WINAPI
DllMain (HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
HMODULE hMd = NULL;
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
{
cci_init ();
DisableThreadLibraryCalls (hModule);
GetModuleHandleEx (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_PIN,
(LPCTSTR)SQLDriverConnect,
&hMd);
}
// hInstance is declared at resource_proc.c
hInstance = (HINSTANCE) hModule;
return TRUE;
}
const char *cci_client_name = "ODBC";
#if (ODBCVER >= 0x0300)
/************************************************************************
* name: SQLAllocHandle
* arguments:
* returns/side-effects:
* description:
* NOTE:
************************************************************************/
ODBC_INTERFACE RETCODE SQL_API
SQLAllocHandle (SQLSMALLINT HandleType,
SQLHANDLE InputHandle, SQLHANDLE * OutputHandle)
{
RETCODE rc = SQL_SUCCESS;
#ifdef _DEBUG
ODBC_ENV *env = InputHandle;
#endif
OutputDebugString ("SQLAllocHandle called\n");
DEBUG_TIMESTAMP (START_SQLAllocHandle);
if (InputHandle != NULL)
{
odbc_free_diag (((ODBC_ENV *) InputHandle)->diag, RESET);
}
if (OutputHandle == NULL)
{
odbc_set_diag (((ODBC_ENV *) InputHandle)->diag, "HY009", 0, NULL);
return SQL_ERROR;
}
switch (HandleType)
{
case SQL_HANDLE_ENV:
rc = odbc_alloc_env ((ODBC_ENV **) OutputHandle);
break;
case SQL_HANDLE_DBC:
rc =
odbc_alloc_connection ((ODBC_ENV *) InputHandle,
(ODBC_CONNECTION **) OutputHandle);
break;
case SQL_HANDLE_STMT:
rc =
odbc_alloc_statement ((ODBC_CONNECTION *) InputHandle,
(ODBC_STATEMENT **) OutputHandle);
break;
case SQL_HANDLE_DESC:
rc =
odbc_alloc_desc ((ODBC_CONNECTION *) InputHandle,
(ODBC_DESC **) OutputHandle);
break;
}
DEBUG_TIMESTAMP (END_SQLAllocHandle);
if (InputHandle != NULL)
{
ODBC_RETURN (rc, InputHandle);
}
else
{
return (rc);
}
}
#endif
ODBC_INTERFACE RETCODE SQL_API
SQLBindCol (SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber,
SQLSMALLINT TargetType,
SQLPOINTER TargetValue,
SQLLEN BufferLength, SQLLEN * StrLen_or_Ind)
{
RETCODE rc = SQL_SUCCESS;
ODBC_STATEMENT *stmt_handle;
OutputDebugString ("SQLBindCol called\n");
DEBUG_TIMESTAMP (START_SQLBindCol);
stmt_handle = (ODBC_STATEMENT *) StatementHandle;
odbc_free_diag (stmt_handle->diag, RESET);
rc = odbc_bind_col (stmt_handle, ColumnNumber, TargetType,
TargetValue, BufferLength, StrLen_or_Ind);
DEBUG_TIMESTAMP (END_SQLAllocHandle);
ODBC_RETURN (rc, StatementHandle);
}
ODBC_INTERFACE RETCODE SQL_API
SQLBindParameter (SQLHSTMT StatementHandle,
SQLUSMALLINT ParameterNumber,
SQLSMALLINT InputOutputType,
SQLSMALLINT ValueType,
SQLSMALLINT ParameterType,
SQLULEN ColumnSize,
SQLSMALLINT DecimalDigits,
SQLPOINTER ParameterValuePtr,
SQLLEN BufferLength, SQLLEN * StrLen_or_IndPtr)
{
RETCODE rc = SQL_SUCCESS;
ODBC_STATEMENT *stmt_handle;
OutputDebugString ("SQLBindParameter called\n");
DEBUG_TIMESTAMP (START_SQLBindParameter);
stmt_handle = (ODBC_STATEMENT *) StatementHandle;
if (StrLen_or_IndPtr && ValueType == SQL_WCHAR)
{
if (is_odd_number(*StrLen_or_IndPtr))
{
odbc_set_diag(stmt_handle->diag, "HY090", 0, NULL);
ODBC_RETURN(ODBC_ERROR, StatementHandle);
}
else
{
*StrLen_or_IndPtr = *StrLen_or_IndPtr / sizeof (wchar_t);
}
}
odbc_free_diag (stmt_handle->diag, RESET);
rc = odbc_bind_parameter (stmt_handle, ParameterNumber,
InputOutputType, ValueType,
ParameterType, ColumnSize,
DecimalDigits, ParameterValuePtr,
BufferLength, StrLen_or_IndPtr);
DEBUG_TIMESTAMP (END_SQLBindParameter);
ODBC_RETURN (rc, StatementHandle);
}
ODBC_INTERFACE RETCODE SQL_API
SQLCancel (SQLHSTMT StatementHandle)
{
RETCODE rc = SQL_SUCCESS;
ODBC_STATEMENT *stmt_handle;
OutputDebugString ("SQLCancel called\n");
DEBUG_TIMESTAMP (START_SQLCancel);
stmt_handle = (ODBC_STATEMENT *) StatementHandle;
odbc_free_diag (stmt_handle->diag, RESET);
rc = odbc_cancel (stmt_handle);
stmt_handle->canceled = _TRUE_;
DEBUG_TIMESTAMP (END_SQLCancel);
ODBC_RETURN (rc, StatementHandle);
}
#if (ODBCVER >= 0x0300)
ODBC_INTERFACE RETCODE SQL_API
SQLCloseCursor (SQLHSTMT StatementHandle)
{
RETCODE rc = SQL_SUCCESS;
ODBC_STATEMENT *stmt_handle;
OutputDebugString ("SQLCloseCursor called\n");
DEBUG_TIMESTAMP (START_SQLCloseCursor);
stmt_handle = (ODBC_STATEMENT *) StatementHandle;
odbc_free_diag (stmt_handle->diag, RESET);
rc = odbc_close_cursor (stmt_handle);
DEBUG_TIMESTAMP (END_SQLCloseCursor);
ODBC_RETURN (rc, StatementHandle);
}
ODBC_INTERFACE RETCODE SQL_API
SQLColAttribute (SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber,
SQLUSMALLINT FieldIdentifier,
SQLPOINTER CharacterAttribute,
SQLSMALLINT BufferLength, SQLSMALLINT * StringLength,
#ifdef _WIN64
SQLLEN * NumericAttribute)
#else
SQLPOINTER NumericAttribute)
#endif
{
RETCODE rc = SQL_SUCCESS;
ODBC_STATEMENT *stmt_handle;
OutputDebugString ("SQLColAttribute called\n");
DEBUG_TIMESTAMP (START_SQLColAttribute);
stmt_handle = (ODBC_STATEMENT *) StatementHandle;
odbc_free_diag (stmt_handle->diag, RESET);
rc = odbc_col_attribute (stmt_handle, ColumnNumber,
FieldIdentifier, CharacterAttribute, BufferLength,
StringLength, NumericAttribute);
DEBUG_TIMESTAMP (END_SQLColAttribute);
ODBC_RETURN (rc, StatementHandle);
}
#endif
ODBC_INTERFACE RETCODE SQL_API
SQLColumns (SQLHSTMT StatementHandle,
SQLCHAR * CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR * SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR * TableName,
SQLSMALLINT NameLength3,
SQLCHAR * ColumnName, SQLSMALLINT NameLength4)
{
RETCODE rc = SQL_SUCCESS;
ODBC_STATEMENT *stmt_handle;
SQLCHAR *stCatalogName = NULL;
SQLCHAR *stSchemaName = NULL;
SQLCHAR *stTableName = NULL;
SQLCHAR *stColumnName = NULL;
OutputDebugString ("SQLColumns called\n");
DEBUG_TIMESTAMP (START_SQLColumns);
stCatalogName = UT_MAKE_STRING (CatalogName, NameLength1);
stSchemaName = UT_MAKE_STRING (SchemaName, NameLength2);
stTableName = UT_MAKE_STRING (TableName, NameLength3);
stColumnName = UT_MAKE_STRING (ColumnName, NameLength4);
stmt_handle = (ODBC_STATEMENT *) StatementHandle;
odbc_free_diag (stmt_handle->diag, RESET);
rc =
odbc_columns (stmt_handle, stCatalogName, stSchemaName, stTableName,
stColumnName);
NA_FREE (stCatalogName);
NA_FREE (stSchemaName);
NA_FREE (stTableName);
NA_FREE (stColumnName);
DEBUG_TIMESTAMP (END_SQLColumns);
ODBC_RETURN (rc, StatementHandle);
}
ODBC_INTERFACE RETCODE SQL_API
SQLConnect (SQLHDBC ConnectionHandle,
SQLCHAR * DataSource,
SQLSMALLINT NameLength1,
SQLCHAR * UserName,
SQLSMALLINT NameLength2,
SQLCHAR * Authentication, SQLSMALLINT NameLength3)
{
RETCODE rc = SQL_SUCCESS;
SQLCHAR *stDataSource = NULL;
SQLCHAR *stUserName = NULL;
SQLCHAR *stAuthentication = NULL;
SQLCHAR stDBName[ITEMBUFLEN];
SQLCHAR stServerName[ITEMBUFLEN];
SQLINTEGER Port, FetchSize;
SQLCHAR stCharSet[ITEMBUFLEN];
SQLCHAR stAutocommit[ITEMBUFLEN];
SQLCHAR stOmitSchema[ITEMBUFLEN];
OutputDebugString ("SQLConnect called\n");
DEBUG_TIMESTAMP (START_SQLConnect);
stDataSource = UT_MAKE_STRING (DataSource, NameLength1);
stUserName = UT_MAKE_STRING (UserName, NameLength2);
stAuthentication = UT_MAKE_STRING (Authentication, NameLength3);
odbc_free_diag (((ODBC_CONNECTION *) ConnectionHandle)->diag, RESET);
get_dsn_info (stDataSource, stDBName, sizeof (stDBName), NULL, 0, NULL, 0,
stServerName, sizeof (stServerName), &Port, &FetchSize,
stCharSet, sizeof (stCharSet), stAutocommit, sizeof (stAutocommit),
stOmitSchema, sizeof(stOmitSchema));
rc = odbc_connect_new ((ODBC_CONNECTION *) ConnectionHandle, stDataSource,
stDBName, stUserName, stAuthentication, stServerName,
Port, FetchSize, stCharSet, stAutocommit, stOmitSchema, NULL);
NA_FREE (stDataSource);
NA_FREE (stUserName);
NA_FREE (stAuthentication);
DEBUG_TIMESTAMP (END_SQLConnect);
ODBC_RETURN (rc, ConnectionHandle);
}
#if (ODBCVER >= 0x0300)
ODBC_INTERFACE RETCODE SQL_API
SQLCopyDesc (SQLHDESC SourceDescHandle, SQLHDESC TargetDescHandle)
{
RETCODE rc = SQL_SUCCESS;
OutputDebugString ("SQLCopyDesc called\n");
DEBUG_TIMESTAMP (START_SQLCopyDesc);
odbc_free_diag (((ODBC_DESC *) TargetDescHandle)->diag, RESET);
rc =
odbc_copy_desc ((ODBC_DESC *) SourceDescHandle,
(ODBC_DESC *) TargetDescHandle);
DEBUG_TIMESTAMP (END_SQLCopyDesc);
ODBC_RETURN (rc, TargetDescHandle);
}
#endif
ODBC_INTERFACE RETCODE SQL_API
SQLDescribeCol (SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber,
SQLCHAR * ColumnName,
SQLSMALLINT BufferLength,
SQLSMALLINT * NameLength,
SQLSMALLINT * DataType,
SQLULEN * ColumnSize,
SQLSMALLINT * DecimalDigits, SQLSMALLINT * Nullable)
{
RETCODE rc = SQL_SUCCESS;
ODBC_STATEMENT *stmt_handle;
OutputDebugString ("SQLDescribeCol called\n");
DEBUG_TIMESTAMP (START_SQLDescribeCol);
stmt_handle = (ODBC_STATEMENT *) StatementHandle;
odbc_free_diag (stmt_handle->diag, RESET);
rc = odbc_describe_col (stmt_handle, ColumnNumber,
ColumnName, BufferLength, NameLength, DataType,
ColumnSize, DecimalDigits, Nullable);
DEBUG_TIMESTAMP (END_SQLDescribeCol);
ODBC_RETURN (rc, StatementHandle);
}
ODBC_INTERFACE RETCODE SQL_API
SQLDisconnect (SQLHDBC ConnectionHandle)
{
/* always return SQL_SUCCESS */
RETCODE rc = SQL_SUCCESS;
OutputDebugString ("SQLDisconnect called\n");
DEBUG_TIMESTAMP (START_SQLDisconnect);
odbc_free_diag (((ODBC_CONNECTION *) ConnectionHandle)->diag, RESET);
odbc_disconnect ((ODBC_CONNECTION *) ConnectionHandle);
DEBUG_TIMESTAMP (END_SQLDisconnect);
ODBC_RETURN (rc, ConnectionHandle);
}
/*
* SQLDriverConnect
* - PWD entry는 file DSN에 추가되지 않는다.
*/
ODBC_INTERFACE RETCODE SQL_API
SQLDriverConnect (HDBC hdbc,
HWND hWnd,
UCHAR * szConnStrIn,
SWORD cbConnStrIn,
UCHAR * szConnStrOut,
SWORD cbConnStrOut,
SQLSMALLINT * pcbConnStrOut, UWORD uwMode)
{
RETCODE rc = ODBC_SUCCESS;
INT_PTR dlgrc;
char *pt;
DriverConnectInfo dci;
CUBRIDDSNItem dsn_item;
const char *ptDriver;
const char *ptDSN;
const char *ptDBName;
const char *ptUser;
const char *ptPWD;
const char *ptServer;
const char *ptPort;
const char *ptFileDSN;
const char *ptSaveFile;
const char *ptFetchSize;
const char *ptDescription;
const char *ptCharSet;
const char *ptAutoCommit;
const char *ptOmitSchema;
// Deprecated : char szDriver[ITEMBUFLEN];
char ConnStrIn[BUF_SIZE*4];
char buf[4096];
char buf2[4096];
char user[4096] = "";
char pwd[ITEMBUFLEN] = "";
char db_name[ITEMBUFLEN] = "";
char server[ITEMBUFLEN] = "";
char charset[ITEMBUFLEN] = "";
char autocommit[ITEMBUFLEN] = "";
char omit_schema[ITEMBUFLEN] = "";
int port = 0;
int fetch_size = 0;
OutputDebugString ("SQLDriverConnect called\n");
DEBUG_TIMESTAMP (START_SQLDriverConnect);
if ((cbConnStrIn == SQL_NTS) && (szConnStrIn))
cbConnStrIn = strlen (szConnStrIn);
strncpy (ConnStrIn, szConnStrIn, cbConnStrIn);
ConnStrIn[cbConnStrIn] = '\0'; // for end of list, if cbConnStrIn isn't end
// with ';'
for (pt = ConnStrIn; *pt != '\0'; ++pt)
{
if (*pt == ';') // connection string delimiter
*pt = '\0';
}
ptDriver = element_value_by_key (ConnStrIn, KEYWORD_DRIVER);
/*
pt = strchr(ptDriver, '{');
if ( pt == NULL ) {
strcpy(szDriver, ptDriver);
} else {
pt2 = strchr(ptDriver, '}');
// if ( pt2 == NULL ) error;
strncpy(szDriver, pt+1, pt2 - pt -1);
szDriver[pt2-pt -1] = '\0';
}
*/
ptDSN = element_value_by_key (ConnStrIn, KEYWORD_DSN);
ptUser = element_value_by_key (ConnStrIn, KEYWORD_USER);
ptPWD = element_value_by_key (ConnStrIn, KEYWORD_PASSWORD);
ptSaveFile = element_value_by_key (ConnStrIn, KEYWORD_SAVEFILE);
ptCharSet = element_value_by_key (ConnStrIn, KEYWORD_CHARSET);
ptAutoCommit = element_value_by_key (ConnStrIn, KEYWORD_AUTOCOMMIT);
ptOmitSchema = element_value_by_key (ConnStrIn, KEYWORD_OMIT_SCHEMA);
if (ptSaveFile == NULL)
{ // for just connect
// extracting user & pwd by dialog box
if (ptUser == NULL || ptUser[0] == '\0' || ptPWD == NULL)
{
if (ptDSN != NULL)
{
get_dsn_info (ptDSN, NULL, 0, user, sizeof (user),
pwd, sizeof (pwd), NULL, 0, NULL, NULL, NULL, 0, NULL, 0, NULL, 0);
}
if (ptUser == NULL || ptUser[0] == '\0')
{
sprintf (dci.user, "%s", user);
sprintf (dci.pwd, "%s", pwd);
}
else
{
sprintf (dci.user, "%s", ptUser);
sprintf (dci.pwd, "");
}
if (strcmp (dci.user, "") == 0)
{
DialogBoxParam (hInstance, (LPCTSTR) IDD_DRIVERCONNECT, hWnd,
ConnectDlgProc, (LPARAM) & dci);
}
ptUser = dci.user;
ptPWD = dci.pwd;
}
if (ptDSN == NULL)
{
ptFileDSN = element_value_by_key (ConnStrIn, KEYWORD_FILEDSN);
ptDBName = element_value_by_key (ConnStrIn, KEYWORD_DBNAME);
ptServer = element_value_by_key (ConnStrIn, KEYWORD_SERVER);
ptPort = element_value_by_key (ConnStrIn, KEYWORD_PORT);
ptFetchSize = element_value_by_key (ConnStrIn, KEYWORD_FETCH_SIZE);
ptCharSet = element_value_by_key (ConnStrIn, KEYWORD_CHARSET);
ptAutoCommit = element_value_by_key (ConnStrIn, KEYWORD_AUTOCOMMIT);
ptOmitSchema = element_value_by_key(ConnStrIn, KEYWORD_OMIT_SCHEMA);
port = ptPort ? atoi (ptPort) : 0;
fetch_size = ptFetchSize ? atoi (ptFetchSize) : 0;
rc = odbc_connect_new (hdbc, ptFileDSN, ptDBName, ptUser,
ptPWD, ptServer, port, fetch_size, ptCharSet, ptAutoCommit, ptOmitSchema, ConnStrIn);
}
else
{
// with DSN
ptDBName = element_value_by_key (ConnStrIn, KEYWORD_DBNAME);
ptServer = element_value_by_key (ConnStrIn, KEYWORD_SERVER);
ptPort = element_value_by_key (ConnStrIn, KEYWORD_PORT);
ptFetchSize = element_value_by_key (ConnStrIn, KEYWORD_FETCH_SIZE);
ptCharSet = element_value_by_key (ConnStrIn, KEYWORD_CHARSET);
ptAutoCommit = element_value_by_key (ConnStrIn, KEYWORD_AUTOCOMMIT);
ptOmitSchema = element_value_by_key (ConnStrIn, KEYWORD_OMIT_SCHEMA);
get_dsn_info (ptDSN, db_name, sizeof (db_name), NULL, 0,
NULL, 0, server, sizeof (server), &port, &fetch_size,
charset, sizeof(charset), autocommit, sizeof(autocommit),
omit_schema, sizeof (omit_schema));
// cbConnStrIn이 DSN의 정보보다 우선하다.
if (ptDBName == NULL)
{
ptDBName = db_name;
}
if (ptServer == NULL)
{
ptServer = server;
}
if (ptPort != NULL)
{
port = atoi (ptPort);
}
if (ptFetchSize != NULL)
{
fetch_size = atoi (ptFetchSize);
}
if (ptCharSet == NULL)
{
ptCharSet = charset;
}
if (ptAutoCommit == NULL)
{
ptAutoCommit = autocommit;
}
if (ptOmitSchema == NULL)
{
ptOmitSchema = omit_schema;
}
rc = odbc_connect_new (hdbc, ptDSN, ptDBName, ptUser,
ptPWD, ptServer, port, fetch_size, ptCharSet, ptAutoCommit, ptOmitSchema, ConnStrIn);
}
// Building ConnStrOut
if (ptDSN != NULL)
{
sprintf (buf, "%s=%s;", KEYWORD_DSN, ptDSN);
}
if (ptDriver != NULL)
{
sprintf (buf, "%s=%s;", KEYWORD_DRIVER, ptDriver);
}
else
{
buf2[0] = '\0';
}
if (ptDBName != NULL)
{
sprintf (buf2, "%s=%s;", KEYWORD_DBNAME, ptDBName);
strcat (buf, buf2);
}
if (ptUser != NULL)
{
sprintf (buf2, "%s=%s;", KEYWORD_USER, ptUser);
strcat (buf, buf2);
}
if (ptPWD != NULL)
{
sprintf (buf2, "%s=%s;", KEYWORD_PASSWORD, ptPWD);
strcat (buf, buf2);
}
if (ptServer != NULL)
{
sprintf (buf2, "%s=%s;", KEYWORD_SERVER, ptServer);
strcat (buf, buf2);
}
if (port > 0)
{
sprintf (buf2, "%s=%d;", KEYWORD_PORT, port);
strcat (buf, buf2);
}
if (fetch_size > 0)
{
sprintf (buf2, "%s=%d;", KEYWORD_FETCH_SIZE, fetch_size);
strcat (buf, buf2);
}
if (ptCharSet != NULL)
{
sprintf (buf2, "%s=%s;", KEYWORD_CHARSET, ptCharSet);
strcat (buf, buf2);
}
if (ptAutoCommit != NULL)
{
sprintf (buf2, "%s=%s;", KEYWORD_AUTOCOMMIT, ptAutoCommit);
strcat (buf, buf2);
}
if (ptOmitSchema != NULL)
{
sprintf(buf2, "%s=%s;", KEYWORD_OMIT_SCHEMA, ptOmitSchema);
strcat(buf, buf2);
}
if ((szConnStrOut) && cbConnStrOut > 0)
{
strncpy (szConnStrOut, buf,
MIN (strlen (buf), (unsigned) cbConnStrOut));
szConnStrOut[MIN (strlen (buf), (unsigned) cbConnStrOut)] = '\0';
}
if (pcbConnStrOut)
*pcbConnStrOut = MIN (strlen (buf), (unsigned) cbConnStrOut);
}
else
{
// for creating & managing FILEDSN
// SAVEFILE이 있는 경우, DSN은 찾을 수 없다.
ptDBName = element_value_by_key (buf, KEYWORD_DBNAME);
ptUser = element_value_by_key (buf, KEYWORD_USER);
ptPWD = element_value_by_key (buf, KEYWORD_PASSWORD);
ptServer = element_value_by_key (buf, KEYWORD_SERVER);
ptPort = element_value_by_key (buf, KEYWORD_PORT);
ptFetchSize = element_value_by_key (buf, KEYWORD_FETCH_SIZE);
ptDescription = element_value_by_key (buf, KEYWORD_DESCRIPTION);
ptCharSet = element_value_by_key (buf, KEYWORD_CHARSET);
ptAutoCommit = element_value_by_key (buf, KEYWORD_AUTOCOMMIT);
ptOmitSchema = element_value_by_key(buf, KEYWORD_OMIT_SCHEMA);
memset (&dsn_item, 0, sizeof (CUBRIDDSNItem));
strcpy (dsn_item.save_file, ptSaveFile);
if (ptDBName != NULL)
strcpy (dsn_item.db_name, ptDBName);
if (ptUser != NULL)
strcpy (dsn_item.user, ptUser);
if (ptPWD != NULL)
strcpy (dsn_item.password, ptPWD);
if (ptServer != NULL)
strcpy (dsn_item.server, ptServer);
if (ptPort != NULL)
strcpy (dsn_item.port, ptPort);
if (ptFetchSize != NULL)
strcpy (dsn_item.fetch_size, ptFetchSize);
if (ptDescription != NULL)
strcpy (dsn_item.description, ptDescription);
if (ptCharSet != NULL)
strcpy (dsn_item.charset, ptCharSet);
if (ptAutoCommit != NULL)
strcpy (dsn_item.autocommit, ptAutoCommit);
if (ptOmitSchema != NULL)
strcpy(dsn_item.omit_schema, ptOmitSchema);
dlgrc = DialogBoxParam (hInstance, (LPCTSTR) IDD_CONFIGDSN, hWnd,
ConfigDSNDlgProc, (LPARAM) & dsn_item);
sprintf (buf, "%s=%s;%s=%s;%s=%s;%s=%s;%s=%s;%s=%s;%s=%s;%s=%s;%s=%s;%s=%s;%s=%s;%s=%s",
KEYWORD_DRIVER, ptDriver,
KEYWORD_SAVEFILE, ptSaveFile,
KEYWORD_DESCRIPTION, dsn_item.description,
KEYWORD_DBNAME, dsn_item.db_name,
KEYWORD_PASSWORD, dsn_item.password,
KEYWORD_USER, dsn_item.user,
KEYWORD_SERVER, dsn_item.server,
KEYWORD_PORT, dsn_item.port,
KEYWORD_FETCH_SIZE, dsn_item.fetch_size,
KEYWORD_CHARSET, dsn_item.charset,
KEYWORD_AUTOCOMMIT, dsn_item.autocommit,
KEYWORD_OMIT_SCHEMA, dsn_item.omit_schema);
if ((szConnStrOut) && cbConnStrOut > 0)
{
strncpy (szConnStrOut, buf,
MIN (strlen (buf), (unsigned) cbConnStrOut));
szConnStrOut[MIN (strlen (buf), (unsigned) cbConnStrOut)] = '\0';
}
if (pcbConnStrOut)
*pcbConnStrOut = MIN (strlen (buf), (unsigned) cbConnStrOut);
// CHECK : return value
}
DEBUG_TIMESTAMP (END_SQLDriverConnect);
ODBC_RETURN (rc, hdbc);
}
#if (ODBCVER >= 0x0300)
ODBC_INTERFACE RETCODE SQL_API
SQLEndTran (SQLSMALLINT HandleType,
SQLHANDLE Handle, SQLSMALLINT CompletionType)
{
RETCODE rc = SQL_SUCCESS;
OutputDebugString ("SQLEndTran called\n");
DEBUG_TIMESTAMP (START_SQLEndTran);
odbc_free_diag (((ODBC_ENV *) Handle)->diag, RESET);
rc = odbc_end_tran (HandleType, Handle, CompletionType);
DEBUG_TIMESTAMP (END_SQLEndTran);
ODBC_RETURN (rc, Handle);
}
#endif
// 오직 SQLExecDirect만 prepare된 상태를 풀 수 있다.
ODBC_INTERFACE RETCODE SQL_API
SQLExecDirect (SQLHSTMT StatementHandle,
SQLCHAR * StatementText, SQLINTEGER TextLength)
{
RETCODE rc = SQL_SUCCESS;
SQLCHAR *stStatementText = NULL;
ODBC_STATEMENT *stmt_handle;
OutputDebugString ("SQLExecDirect called\n");
DEBUG_TIMESTAMP (START_SQLExecDirect);
stmt_handle = (ODBC_STATEMENT *) StatementHandle;
odbc_free_diag (stmt_handle->diag, RESET);
stStatementText = UT_MAKE_STRING (StatementText, TextLength);
if (stricmp(StatementText, "@QP@") == 0)
{
stmt_handle->query_plan = CCI_EXEC_ONLY_QUERY_PLAN;
return ODBC_SUCCESS;
}
if (stricmp(StatementText, "@QE@") == 0)
{
stmt_handle->query_plan = CCI_EXEC_ONLY_QUERY_PLAN | CCI_EXEC_QUERY_ALL;
return ODBC_SUCCESS;
}
stmt_handle->is_prepared = _FALSE_;
rc = odbc_prepare (stmt_handle, stStatementText);
ERROR_GOTO (rc, error);
rc = odbc_execute (stmt_handle);
ERROR_GOTO (rc, error);
DEBUG_TIMESTAMP (END_SQLExecDirect);
error:
NA_FREE (stStatementText);
ODBC_RETURN (rc, StatementHandle);
}
ODBC_INTERFACE RETCODE SQL_API
SQLExecute (SQLHSTMT StatementHandle)
{
RETCODE rc = SQL_SUCCESS;
ODBC_STATEMENT *stmt_handle;
char *buf = NULL;
OutputDebugString ("SQLExecute called\n");
DEBUG_TIMESTAMP (START_SQLExecute);
stmt_handle = (ODBC_STATEMENT *) StatementHandle;
odbc_free_diag (stmt_handle->diag, RESET);
if (stricmp (stmt_handle->sql_text, "@QP@") == 0)
{
stmt_handle->query_plan = CCI_EXEC_ONLY_QUERY_PLAN;
return ODBC_SUCCESS;
}
if (stricmp (stmt_handle->sql_text, "@QE@") == 0)
{
stmt_handle->query_plan = CCI_EXEC_ONLY_QUERY_PLAN | CCI_EXEC_QUERY_ALL;
return ODBC_SUCCESS;
}
// SQLEndTran()에 의해서 cursor가 delete된 상태
if (stmt_handle->is_prepared == _TRUE_ && stmt_handle->stmthd <= 0)
{
buf = UT_MAKE_STRING (stmt_handle->sql_text, -1);
rc = odbc_prepare (stmt_handle, buf);
NA_FREE (buf);
}
rc = odbc_execute (stmt_handle);
DEBUG_TIMESTAMP (END_SQLExecute);
ODBC_RETURN (rc, StatementHandle);
}
ODBC_INTERFACE RETCODE SQL_API
SQLFetch (SQLHSTMT StatementHandle)
{
RETCODE rc = SQL_SUCCESS;
ODBC_STATEMENT *stmt_handle;
stmt_handle = (ODBC_STATEMENT *) StatementHandle;
OutputDebugString ("SQLFetch called\n");
DEBUG_TIMESTAMP (START_SQLFetch);
stmt_handle = (ODBC_STATEMENT *) StatementHandle;
odbc_free_diag (stmt_handle->diag, RESET);
rc = odbc_fetch (stmt_handle, SQL_FETCH_NEXT, 1, 0, 0); // fetch_offset is ignored
DEBUG_TIMESTAMP (END_SQLFetch);
ODBC_RETURN (rc, StatementHandle);
}
#if (ODBCVER >= 0x0300)
ODBC_INTERFACE RETCODE SQL_API
SQLFetchScroll (SQLHSTMT StatementHandle,
SQLSMALLINT FetchOrientation, SQLLEN FetchOffset)
{
RETCODE rc = SQL_SUCCESS;
ODBC_STATEMENT *stmt_handle;
OutputDebugString ("SQLFetchScroll called\n");
DEBUG_TIMESTAMP (START_SQLFetchScroll);
stmt_handle = (ODBC_STATEMENT *) StatementHandle;
odbc_free_diag (stmt_handle->diag, RESET);
rc = odbc_fetch (stmt_handle, FetchOrientation, FetchOffset, 0, 0);
DEBUG_TIMESTAMP (END_SQLFetchScroll);
ODBC_RETURN (rc, StatementHandle);
}
#endif
/************************************************************************
* name: SQLExtendedFetch
* arguments:
* returns/side-effects:
* description:
* NOTE:
* SQLExtenedtFetch를 SQLFetchScroll에 mapping하고 있다.
* 이 때 odbc 2.x는 SQL_ATTR_ROWS_FETCHED_PTR과 SQL_ATTR_ROW_STATUS_PTR
* 을 RowCountPtr, RowStatusArray로 대신하여 사용하므로 odbc_fetch()에서
* 작동하기 위해서 odbc_set_stmt_attr()을 사용하여 setting해 준다.
* 물론 SQL_ROWSET_SIZE는 SQL_ATTR_ROW_ARRAY_SIZE로 mapping되어 있다.
*
************************************************************************/
// for 2.x backward compatibility
ODBC_INTERFACE RETCODE SQL_API
SQLExtendedFetch (SQLHSTMT StatementHandle,
SQLUSMALLINT FetchOrientation,
SQLLEN FetchOffset,
SQLULEN * RowCountPtr, SQLUSMALLINT * RowStatusArray)
{
RETCODE rc = SQL_SUCCESS;
ODBC_STATEMENT *stmt_handle;
OutputDebugString ("SQLExtendedFetch called\n");
stmt_handle = (ODBC_STATEMENT *) StatementHandle;
odbc_free_diag (stmt_handle->diag, RESET);
odbc_set_stmt_attr (stmt_handle, SQL_ATTR_ROWS_FETCHED_PTR,
(void *) RowCountPtr, 0, 1);
odbc_set_stmt_attr (stmt_handle, SQL_ATTR_ROW_STATUS_PTR,
(void *) RowStatusArray, 0, 1);
rc = odbc_fetch (stmt_handle, FetchOrientation, FetchOffset, 0, 0);
ODBC_RETURN (rc, StatementHandle);
return (rc);