-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstatement_test.cc
More file actions
4472 lines (3682 loc) · 165 KB
/
Copy pathstatement_test.cc
File metadata and controls
4472 lines (3682 loc) · 165 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "google/cloud/odbc/testing/odbc_utils/statement.h"
#include "google/cloud/odbc/testing/odbc_utils/connection.h"
#include "google/cloud/odbc/testing/odbc_utils/descriptor.h"
#include "absl/strings/match.h"
#include <gmock/gmock.h>
using ::testing::Contains;
using ::testing::HasSubstr;
namespace google::cloud::odbc_tests {
using ::testing::StartsWith;
class StatementParameterizedTest : public ::testing::TestWithParam<bool> {};
INSTANTIATE_TEST_SUITE_P(TestingWithOrWithoutANSI, StatementParameterizedTest,
testing::Values(false, true));
class MultiStatementTest : public ::testing::TestWithParam<bool> {};
INSTANTIATE_TEST_SUITE_P(TestingWithOrWithoutPrepare, MultiStatementTest,
testing::Values(true, false));
#ifdef BQ_DRIVER_INTEGRATION_TESTS
class HTAPIParameterizedTest : public ::testing::TestWithParam<bool> {};
INSTANTIATE_TEST_SUITE_P(TestingWithOrWithouthtapi, HTAPIParameterizedTest,
testing::Values(false, true));
#else
// The existing driver doesn't properly handle location for paginate(REST) API
class HTAPIParameterizedTest : public ::testing::TestWithParam<bool> {};
INSTANTIATE_TEST_SUITE_P(TestingWithOrWithouthtapi, HTAPIParameterizedTest,
testing::Values(true));
#endif // BQ_DRIVER_INTEGRATION_TESTS
StdRows const kSampleData{
{"Test String 1", 1, 1.1}, {"", 237, 2.22},
{"Test String 3", NULL, 3.333}, {"Test String 4", 49, 0.0},
{"Test String 5", 53, 5}, {"Test String 6", 698, 0.31},
{"Test String 7", 12, 71.6}, {"Test String 8", 83, 8.8},
};
std::vector<std::string> const kSampleLargeStringData{
{GetRandomString(100)},
{GetRandomString(1800)},
{GetRandomString(3000)},
{GetRandomString(50)},
};
StdUnicodeRows const kUnicodeSampleData{
{1, L"हिंदी", L"中国人"},
{2, L"random string 1", L"random string 2"},
// The test case doesn't fetch the values below
{3, L"untested val 1", L"untested val 2"}};
StdRows const kRowCountSampleData{
{"Row 1", 1, 1.1}, {"Row 2", 2, 2.2}, {"Row 3", 3, 3.3}};
// Checks if the column description returned by DescribeCol matches the schema
void CheckColumnData(std::shared_ptr<ODBCHandles> conn, std::string table_name,
Schema schema, bool use_ansi = false) {
SQLRETURN status;
char read_stmt[kBufferLength];
StrToChar(read_stmt, "SELECT * FROM " + table_name);
if (use_ansi) {
status = SQLPrepareA(conn->hstmt, (SQLCHAR*)read_stmt, strlen(read_stmt));
} else {
status = SQLPrepare(conn->hstmt, (SQLCHAR*)read_stmt, strlen(read_stmt));
}
CheckError(status, "SQLPrepare", conn, use_ansi);
// Check if the number of columns returned is correct
SQLSMALLINT num_cols;
status = SQLNumResultCols(conn->hstmt, &num_cols);
CheckError(status, "SQLNumResultCols", conn);
EXPECT_EQ(num_cols, schema.size());
// Loop through columns and verify descriptions
std::vector<std::shared_ptr<Column>> cols(num_cols);
for (int i = 0; i < num_cols; i++) {
auto col_ptr = std::make_shared<Column>();
cols[i] = col_ptr;
DescribeCol(conn, col_ptr, i + 1, use_ansi);
// Verify returned column descriptions with the table schema
EXPECT_STREQ((char const*)col_ptr->name, schema[i].name.c_str());
EXPECT_EQ(col_ptr->name_len, schema[i].name.length());
EXPECT_TRUE(AreSqlAndBqTypesSame(col_ptr->data_type, schema[i].type));
EXPECT_EQ(col_ptr->nullable, SQL_NULLABLE);
}
}
struct ExpectedColMetadata {
std::string name;
SQLSMALLINT type;
SQLULEN size;
SQLSMALLINT decimals;
SQLSMALLINT nullable;
};
void VerifyResultSetMetadata(SQLHSTMT hstmt, SQLSMALLINT expected_col_count,
ExpectedColMetadata const* expected_cols) {
SQLSMALLINT col_count = 0;
SQLRETURN ret = SQLNumResultCols(hstmt, &col_count);
ASSERT_TRUE(SQL_SUCCEEDED(ret));
EXPECT_EQ(col_count, expected_col_count);
for (SQLSMALLINT i = 1; i <= col_count; ++i) {
SQLCHAR col_name[256] = {0};
SQLSMALLINT name_len = 0;
SQLSMALLINT data_type = 0;
SQLSMALLINT decimal_digits = 0;
SQLSMALLINT nullable = 0;
SQLULEN col_size = 0;
ret = SQLDescribeCol(hstmt, i, col_name, sizeof(col_name), &name_len,
&data_type, &col_size, &decimal_digits, &nullable);
ASSERT_TRUE(SQL_SUCCEEDED(ret));
auto const& exp = expected_cols[i - 1];
EXPECT_EQ(std::string(reinterpret_cast<char const*>(col_name)), exp.name)
<< "Column " << i << " name mismatch";
EXPECT_EQ(data_type, exp.type) << "Column " << i << " type mismatch";
EXPECT_EQ(col_size, exp.size) << "Column " << i << " size mismatch";
EXPECT_EQ(decimal_digits, exp.decimals)
<< "Column " << i << " decimal digits mismatch";
EXPECT_EQ(nullable, exp.nullable)
<< "Column " << i << " nullable flag mismatch";
}
}
// Verify if the inserted data(<input_data>) is the same as the data fetched
// col-wise Note: This doesn't verify the integrity of the fetched rows
void VerifyColumnWiseUnicodeResults(StdUnicodeRows input_data,
Results col_wise_data,
std::vector<std::string> col_names) {
if (!col_names.size()) {
std::vector<std::string> all_col_names;
for (auto it = col_wise_data.begin(); it != col_wise_data.end(); it++) {
all_col_names.emplace_back(it->first);
}
col_names = all_col_names;
}
for (auto col_name : col_names) {
auto ret_col_values = col_wise_data[col_name];
// We have to sort inserted and returned values because we haven't specified
// the ordering
sort(ret_col_values.begin(), ret_col_values.end(), str_comparison);
std::vector<std::string> input_col_values;
if (col_name.compare("Hindi")) {
for (auto data : input_data) {
std::string data_str;
// For the existing driver in Unicode mode on Windows, data is
// received(by the application) encoded in CP_ACP but is transmitted as
// UTF-8. In contrast, our driver consistently uses UTF-8 for Unicode
// data, because we don't want to conform to the legacy CP_ACP encoding
#ifdef _WIN32
#ifdef BQ_DRIVER_INTEGRATION_TESTS
data_str = Utf16ToUtf8(data.str_field2);
#else
data_str = Utf16ToUtf8(data.str_field2, CP_ACP);
#endif // BQ_DRIVER_INTEGRATION_TESTS
#else
data_str = Utf16ToUtf8(data.str_field2);
#endif //_WIN32
input_col_values.emplace_back(data_str);
}
} else if (col_name.compare("Chinese")) {
for (auto data : input_data) {
std::string data_str;
#ifdef _WIN32
#ifdef BQ_DRIVER_INTEGRATION_TESTS
data_str = Utf16ToUtf8(data.str_field1);
#else
data_str = Utf16ToUtf8(data.str_field1, CP_ACP);
#endif // BQ_DRIVER_INTEGRATION_TESTS
#else
data_str = Utf16ToUtf8(data.str_field1);
#endif //_WIN32
input_col_values.emplace_back(data_str);
}
}
sort(input_col_values.begin(), input_col_values.end(), str_comparison);
// Check if the sorted inserted and returned vectors have same values
EXPECT_EQ(ret_col_values.size(), input_col_values.size());
for (int i = 0; i < ret_col_values.size(); i++) {
EXPECT_STREQ(ret_col_values[i].c_str(), input_col_values[i].c_str());
}
}
}
// Helper to store field information
struct DataField {
SQLPOINTER data_ptr;
SQLLEN data_size;
SQLSMALLINT c_type;
SQLSMALLINT sql_type;
SQLLEN* str_len_or_ind_ptr;
};
// Function to insert all data types using SQLPutData
void PutAllDataTypes(std::shared_ptr<ODBCHandles> conn,
std::string const& table_name) {
// Prepare data
SQLCHAR bool_data = SQL_TRUE;
SQLLEN bool_len = SQL_DATA_AT_EXEC;
SQLBIGINT int_data = 42;
SQLLEN int_len = SQL_DATA_AT_EXEC;
double float_data = 3.14;
SQLLEN float_len = SQL_DATA_AT_EXEC;
std::string text_data = "";
SQLLEN string_len = SQL_DATA_AT_EXEC;
std::vector<uint8_t> binary_data = {0xDE, 0xAD, 0xBE, 0xEF};
SQLLEN binary_len = SQL_DATA_AT_EXEC;
DataField fields[] = {
{&bool_data, sizeof(bool_data), SQL_C_BIT, SQL_BIT, &bool_len},
{&int_data, sizeof(int_data), SQL_C_SBIGINT, SQL_BIGINT, &int_len},
{&float_data, sizeof(float_data), SQL_C_DOUBLE, SQL_DOUBLE, &float_len},
{(SQLPOINTER)text_data.c_str(), static_cast<SQLLEN>(text_data.size()),
SQL_C_CHAR, SQL_LONGVARCHAR, &string_len},
{(SQLPOINTER)binary_data.data(), static_cast<SQLLEN>(binary_data.size()),
SQL_C_BINARY, SQL_LONGVARBINARY, &binary_len},
};
// Prepare and bind parameters
auto query = "INSERT INTO " + table_name + " VALUES (?, ?, ?, ?, ?)";
EXPECT_EQ(SQLPrepare(conn->hstmt, (SQLCHAR*)query.c_str(), SQL_NTS),
SQL_SUCCESS);
for (int i = 0; i < 5; ++i) {
EXPECT_EQ(SQLBindParameter(conn->hstmt, i + 1, SQL_PARAM_INPUT,
fields[i].c_type, fields[i].sql_type, 0, 0,
nullptr, 0, fields[i].str_len_or_ind_ptr),
SQL_SUCCESS);
}
// Execute and provide data using SQLPutData
EXPECT_EQ(SQLExecute(conn->hstmt), SQL_NEED_DATA);
SQLPOINTER param = nullptr;
for (int i = 0; i < 5; ++i) {
EXPECT_EQ(SQLParamData(conn->hstmt, ¶m), SQL_NEED_DATA);
EXPECT_EQ(SQLPutData(conn->hstmt, fields[i].data_ptr, fields[i].data_size),
SQL_SUCCESS);
}
// Finalize data execution
EXPECT_EQ(SQLParamData(conn->hstmt, nullptr), SQL_SUCCESS);
}
// Function to validate inserted data
void ValidateAllPutData(std::shared_ptr<ODBCHandles> conn,
std::string const& table_name) {
// Prepare and execute query
auto query =
"SELECT BoolField, IntField, FloatField, StringField, BinaryField FROM " +
table_name;
EXPECT_EQ(SQLPrepare(conn->hstmt, (SQLCHAR*)query.c_str(), SQL_NTS),
SQL_SUCCESS);
EXPECT_EQ(SQLExecute(conn->hstmt), SQL_SUCCESS);
EXPECT_EQ(SQLFetch(conn->hstmt), SQL_SUCCESS);
// Define validation fields
SQLCHAR result_bool = 0;
SQLLEN result_bool_len = 0;
SQLBIGINT result_int = 0;
SQLLEN result_int_len = 0;
double result_float = 0.0;
SQLLEN result_float_len = 0;
SQLCHAR result_string[256] = {0};
SQLLEN result_string_len = 0;
uint8_t result_binary[256] = {0};
SQLLEN result_binary_len = 0;
DataField validations[] = {
{&result_bool, sizeof(result_bool), SQL_C_BIT, SQL_BIT, &result_bool_len},
{&result_int, sizeof(result_int), SQL_C_SBIGINT, SQL_BIGINT,
&result_int_len},
{&result_float, sizeof(result_float), SQL_C_DOUBLE, SQL_DOUBLE,
&result_float_len},
{result_string, sizeof(result_string), SQL_C_CHAR, SQL_LONGVARCHAR,
&result_string_len},
{result_binary, sizeof(result_binary), SQL_C_BINARY, SQL_LONGVARBINARY,
&result_binary_len},
};
// Fetch and validate data
for (int i = 0; i < 5; ++i) {
EXPECT_EQ(SQLGetData(conn->hstmt, i + 1, validations[i].c_type,
validations[i].data_ptr, validations[i].data_size,
validations[i].str_len_or_ind_ptr),
SQL_SUCCESS);
}
// Assertions for validation
EXPECT_EQ(result_bool, SQL_TRUE);
EXPECT_EQ(result_int, 42);
EXPECT_DOUBLE_EQ(result_float, 3.14);
EXPECT_EQ(std::string((char*)result_string), "");
std::vector<uint8_t> expected_binary = {0xDE, 0xAD, 0xBE, 0xEF};
EXPECT_EQ(result_binary_len, expected_binary.size());
EXPECT_TRUE(std::equal(result_binary, result_binary + result_binary_len,
expected_binary.begin()));
}
TEST(StatementTest, SQLFetch_Unicode) {
std::string const table_name = kDatasetWithTablePrefix + "ODBC_UNICODE_TEST";
Table table(table_name);
// Create Table
auto conn = std::make_shared<ODBCHandles>();
EXPECT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
table.CreateWithPrepare(
conn, "(IntegerField INTEGER, Hindi STRING, Chinese STRING)");
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
// Insert data to read
EXPECT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
table.InsertUnicodeData(conn, kUnicodeSampleData);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
// Execute a read query and check whether the results returned are as expected
EXPECT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
// TODO(#14): Add integer and floating point fields too
// The IntegerField value is supposed to be unique and used as an index to
// sort
auto const query =
"SELECT Hindi, Chinese FROM " + table_name + " ORDER BY IntegerField";
SQLULEN max_rows = 9193;
SQLRETURN status =
SQLGetStmtAttr(conn->hstmt, SQL_ATTR_MAX_ROWS, &max_rows, 0, nullptr);
CheckError(status, "SQLGetStmtAttr(SQL_ATTR_MAX_ROWS)", conn);
EXPECT_EQ(max_rows, 0);
// validating if SQL_ATTR_MAX_ROWS attr works.
status = SQLSetStmtAttr(conn->hstmt, SQL_ATTR_MAX_ROWS, (SQLPOINTER)2, 0);
CheckError(status, "SQLSetStmtAttr(SQL_ATTR_MAX_ROWS)", conn);
auto results = *FetchResults(conn, query, true);
VerifyColumnWiseUnicodeResults({kUnicodeSampleData[0], kUnicodeSampleData[1]},
results, std::vector<std::string>());
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
// Delete table
EXPECT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
table.Drop(conn);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
}
// Verify if the inserted data(<input_data>) is the same as the data fetched
// col-wise Note: This doesn't verify the integrity of the fetched rows
void VerifyColumnWiseResults(StdRows input_data, Results col_wise_data,
std::vector<std::string> col_names) {
if (!col_names.size()) {
std::vector<std::string> all_col_names;
for (auto it = col_wise_data.begin(); it != col_wise_data.end(); it++) {
all_col_names.emplace_back(it->first);
}
col_names = all_col_names;
}
for (auto col_name : col_names) {
auto ret_col_values = col_wise_data[col_name];
// We have to sort inserted and returned values because we haven't specified
// the ordering
sort(ret_col_values.begin(), ret_col_values.end(), str_comparison);
std::vector<std::string> input_col_values;
if (!col_name.compare("StringField")) {
for (auto data : input_data) {
input_col_values.emplace_back(data.str_field);
}
} else if (!col_name.compare("IntegerField")) {
for (auto data : input_data) {
if (data.int_field != NULL)
input_col_values.emplace_back(std::to_string(data.int_field));
else
input_col_values.emplace_back("");
}
} else if (!col_name.compare("FloatField")) {
for (auto data : input_data) {
if (data.float_field != NULL)
input_col_values.emplace_back(std::to_string(data.float_field));
else
input_col_values.emplace_back("");
}
}
sort(input_col_values.begin(), input_col_values.end(), str_comparison);
// Check if the sorted inserted and returned vectors have same values
EXPECT_EQ(ret_col_values.size(), input_col_values.size());
if ((!col_name.compare("FloatField"))) {
for (int i = 0; i < ret_col_values.size(); i++) {
if (ret_col_values[i].compare("") != 0)
EXPECT_EQ(stod(ret_col_values[i]), stod(input_col_values[i]))
<< " at index: " << i;
}
} else {
for (int i = 0; i < ret_col_values.size(); i++) {
EXPECT_EQ(ret_col_values[i], input_col_values[i]) << " at index: " << i;
}
}
}
}
void ExecDirectWithFetchTest(std::string const in_table_name, bool is_async,
bool use_ansi = false) {
std::string const table_name = kDatasetWithTablePrefix + in_table_name;
Table table(table_name);
// Create Table
auto conn = std::make_shared<ODBCHandles>();
EXPECT_EQ(Connect(kDefaultConnectionString, conn, use_ansi), SQL_SUCCESS);
table.Create(conn,
"(StringField STRING, IntegerField INTEGER, FloatField FLOAT64)",
use_ansi);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
// Insert data to read
EXPECT_EQ(Connect(kDefaultConnectionString, conn, use_ansi), SQL_SUCCESS);
table.InsertData(conn, kSampleData, use_ansi);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
// Execute a read query and check whether the results returned are as expected
EXPECT_EQ(Connect(kDefaultConnectionString, conn, use_ansi), SQL_SUCCESS);
// TODO(#14): Add integer and floating point fields too
auto const query = "SELECT StringField FROM " + table_name;
auto results = *FetchDirect(conn, query, 1, is_async, use_ansi);
VerifyColumnWiseResults(kSampleData, results, std::vector<std::string>());
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
// Delete table
EXPECT_EQ(Connect(kDefaultConnectionString, conn, use_ansi), SQL_SUCCESS);
table.Drop(conn, use_ansi);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
}
TEST(StatementTest, SQLExecDirect) {
SQLRETURN status;
auto conn = std::make_shared<ODBCHandles>();
// This test doesn't work with existing driver. It fails with error:
// "Invalid query: Cannot set destination table in jobs with ASSERT statements
// (70) SQLSTATE=42000"
#ifdef BQ_DRIVER_INTEGRATION_TESTS
EXPECT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
status = SQLExecDirect(conn->hstmt, (SQLCHAR*)"ASSERT ((SELECT COUNT(*) > 5 FROM UNNEST([1, 2, 3, 4, 5, 6]))) AS 'Table must contain more than 5 rows.'", SQL_NTS);
CheckError(status, "SQLExecDirect(ASSERT)", conn);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
#endif // BQ_DRIVER_INTEGRATION_TESTS
EXPECT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
status = SQLExecDirect(
conn->hstmt,
(SQLCHAR*)"SELECT num FROM UNNEST(GENERATE_ARRAY(1, 10)) AS num;",
SQL_NTS);
CheckError(status, "SQLExecDirect(SELECT num)", conn);
int num_rows_returned = 0;
while (SQLFetch(conn->hstmt) == SQL_SUCCESS) {
num_rows_returned++;
}
EXPECT_EQ(num_rows_returned, 10);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
EXPECT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
EXPECT_EQ(InsertDirectStatement(conn), SQL_SUCCESS);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
////////////////
/// USE ANSI
////////////////
EXPECT_EQ(Connect(kDefaultConnectionString, conn, true), SQL_SUCCESS);
EXPECT_EQ(InsertDirectStatement(conn, true), SQL_SUCCESS);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
}
static std::string const kBasicTypesQuery =
R"(SELECT )"
R"(CAST(123 AS INT64) AS int_col1,)"
R"('example string' AS str_col,)"
R"(CAST(3.14 AS FLOAT64) AS float_col,)"
R"(TRUE AS bool_col,)"
R"(NUMERIC '12345.6789' AS numeric_col,)"
R"(BIGNUMERIC '9876543210987654321.123456789012345678' AS bignumeric_col,)"
R"(PARSE_JSON('{"name": "John", "age": 30}') AS json_col,)"
R"(TIMESTAMP '2025-11-12 23:22:27.500' AS timestamp_col,)"
R"(TIME(DATETIME '2024-06-01 12:34:56') AS time_col,)"
R"(DATETIME(TIMESTAMP '2024-05-01 08:00:00') AS datetime_col,)"
R"(DATE '2023-04-01' AS date_col,)"
R"([3, 4, 5] AS array_int_col,)";
static RowWiseResults const kBasicTypesExpected{
{{
{0, "123"},
{1, "example string"},
{2, "3.14"},
{3, kIsBqDriver ? "true" : "1"},
{4, "12345.6789"},
{5, "9876543210987654321.123456789012345678"},
{6, "{\"age\":30,\"name\":\"John\"}"},
{7, "2025-11-12 23:22:27.500000"},
{8, kIsBqDriver ? "12:34:56" : "12:34:56.000000"},
{9, kIsBqDriver ? "2024-05-01 08:00:00" : "2024-05-01 08:00:00.000000"},
{10, "2023-04-01"},
{11, kIsBqDriver
? "[\"3\",\"4\",\"5\"]"
: "{\"v\":[{\"v\":\"3\"},{\"v\":\"4\"},{\"v\":\"5\"}]}"},
}},
};
class StatementHtapiTest : public ::testing::TestWithParam<std::string> {};
TEST_P(StatementHtapiTest, SQLExecDirect_htapi_basictypes_success) {
auto conn = std::make_shared<ODBCHandles>();
EXPECT_EQ(Connect(GetParam(), conn), SQL_SUCCESS);
Table table("Random_table_name");
auto const& results = table.Fetch(conn, kBasicTypesQuery);
VerifyRowWiseResults(results, kBasicTypesExpected);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
}
INSTANTIATE_TEST_SUITE_P(
HtapiConnectionStrings, StatementHtapiTest,
::testing::Values(kDefaultConnectionString + ";AllowHtapiForLargeResults=1;"
"HTAPI_ActivationThreshold=0",
kDefaultConnectionString +
";DefaultDataset=ODBC_TEST_DATASET_HTAPI_US_EAST1;"
"AllowHtapiForLargeResults=1;"
"UseDefaultLargeResultsDataset=0;"
"LargeResultsDataSetId=ODBC_TEST_DATASET"));
#ifdef _WIN32
// TODO(sachinpro): Disabling `UseSystemTrustStore` results in the driver using
// the packaged pem file. We need a way to verify that the system store is used.
TEST(StatementTest, SQLExecDirect_htapi_basictypes_system_trust_store) {
GTEST_SKIP();
auto conn = std::make_shared<ODBCHandles>();
std::string bad_conn_str = kDefaultConnectionString +
";AllowHtapiForLargeResults=1;"
"HTAPI_ActivationThreshold=0;"
"UseSystemTrustStore=0;";
// Existing driver fails while SQLDriverConnect whereas our driver fails when we
// run a query
#ifndef BQ_DRIVER_INTEGRATION_TESTS
ASSERT_EQ(Connect(bad_conn_str, conn), SQL_ERROR);
#else
ASSERT_EQ(Connect(bad_conn_str, conn), SQL_SUCCESS);
SQLRETURN rc = SQLExecDirect(
conn->hstmt,
reinterpret_cast<SQLCHAR*>(const_cast<char*>(kBasicTypesQuery.c_str())),
SQL_NTS);
EXPECT_EQ(rc, SQL_ERROR);
SQLCHAR sql_state[6] = {0};
SQLINTEGER native_error = 0;
SQLCHAR message[1024] = {0};
SQLSMALLINT message_len = 0;
SQLRETURN diag_rc = SQLGetDiagRec(SQL_HANDLE_STMT, conn->hstmt,
1, // first diagnostic record
sql_state, &native_error, message,
sizeof(message), &message_len);
EXPECT_EQ(diag_rc, SQL_SUCCESS);
EXPECT_THAT(reinterpret_cast<char*>(message),
HasSubstr("SSL peer certificate or SSH remote key was not OK"));
EXPECT_STREQ(reinterpret_cast<char*>(sql_state), "HY000");
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
#endif
std::string good_conn_str = kDefaultConnectionString +
";AllowHtapiForLargeResults=1;"
"HTAPI_ActivationThreshold=0;"
"UseSystemTrustStore=1";
ASSERT_EQ(Connect(good_conn_str, conn), SQL_SUCCESS);
Table table("Random_table_name");
auto const& results = table.Fetch(conn, kBasicTypesQuery);
VerifyRowWiseResults(results, kBasicTypesExpected);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
}
#endif // _WIN32
TEST(StatementTest, SQLExecDirect_htapi_bytes_type) {
SQLRETURN status;
auto conn = std::make_shared<ODBCHandles>();
EXPECT_EQ(
Connect(kDefaultConnectionString +
";AllowHtapiForLargeResults=1;HTAPI_ActivationThreshold=0",
conn),
SQL_SUCCESS);
std::string query =
"SELECT CAST(b'\\xDE\\xAD\\xBE\\xEF' AS BYTES) AS bytes_col";
status = SQLExecDirect(conn->hstmt, (SQLCHAR*)query.c_str(), SQL_NTS);
CheckError(status, "SQLExecDirect(bytes)", conn);
EXPECT_EQ(SQLFetch(conn->hstmt), SQL_SUCCESS);
uint8_t buffer[16] = {0};
SQLLEN indicator = 0;
status = SQLGetData(conn->hstmt, 1, SQL_C_BINARY, buffer, sizeof(buffer),
&indicator);
CheckError(status, "SQLGetData(SQL_C_BINARY)", conn);
std::vector<uint8_t> expected = {0xDE, 0xAD, 0xBE, 0xEF};
// TODO(sachnpro): We need to validate indicator as well
// Right now it fails for our driver but passes for the existing one
// EXPECT_EQ(indicator, expected.size());
EXPECT_TRUE(std::equal(buffer, buffer + indicator, expected.begin()));
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
}
#ifdef BQ_DRIVER_INTEGRATION_TESTS
TEST(StatementTest, ReadAPI_RegionalEndpoint) {
auto conn = std::make_shared<ODBCHandles>();
std::string connection_string =
kDefaultConnectionString +
";PrivateServiceConnectUris=BIGQUERY=https://"
"bigquery.us-east1.rep.googleapis.com/"
",READ_API=bigquerystorage.us-east1.rep.googleapis.com"
";AllowHtapiForLargeResults=1;HTAPI_ActivationThreshold=0;"
"UseDefaultLargeResultsDataset=0;"
// The default LargeResultsDataSetId `_bqodbc_temp_tables` cannot be
// created in us_east1 because it already exists in `US`
"LargeResultsDataSetId=_bqodbc_temp_tables_us_east1";
EXPECT_EQ(Connect(connection_string, conn), SQL_SUCCESS);
// `ODBC_HTAPI_TESTING` table doesn't exist in us-east1
std::string query =
"SELECT * EXCEPT (index) FROM ODBC_HTAPI_TESTING.300_columns_string "
"ORDER BY index LIMIT 10";
SQLRETURN status =
SQLExecDirect(conn->hstmt, (SQLCHAR*)query.c_str(), SQL_NTS);
// If the test is using the regional endpoint, we should see an error
EXPECT_EQ(status, SQL_ERROR);
SQLCHAR sql_state[6];
SQLINTEGER native_error;
SQLCHAR message[1024];
SQLSMALLINT message_len;
SQLRETURN diag_ret =
SQLGetDiagRec(SQL_HANDLE_STMT, conn->hstmt, 1, sql_state, &native_error,
message, sizeof(message), &message_len);
ASSERT_EQ(diag_ret, SQL_SUCCESS);
std::string error_message(reinterpret_cast<char*>(message), message_len);
EXPECT_STREQ(reinterpret_cast<char*>(sql_state), "HY000");
EXPECT_THAT(error_message,
HasSubstr("Error in non-idempotent operation: Not found: Dataset "
"bigquery-devtools-drivers:ODBC_HTAPI_TESTING was not "
"found in location us-east1"));
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
EXPECT_EQ(Connect(connection_string, conn), SQL_SUCCESS);
// `ODBC_HTAPI_TESTING_US_EAST1` table exists only in us-east1
query =
"SELECT * EXCEPT (index) FROM "
"ODBC_HTAPI_TESTING_US_EAST1.300_columns_string "
"ORDER BY index LIMIT 10";
status = SQLExecDirect(conn->hstmt, (SQLCHAR*)query.c_str(), SQL_NTS);
CheckError(status, "SQLExecDirect", conn);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
}
TEST(ConnectionTest, InvalidLogPathDoesNotCrash) {
auto conn = std::make_shared<ODBCHandles>();
auto conn_str =
kDefaultConnectionString + ";LogPath=InvalidLogPath;LogLevel=3;";
auto table_name = kDatasetWithTablePrefix + "TEST_TABLE";
Table table(table_name);
EXPECT_EQ(Connect(conn_str, conn), SQL_SUCCESS);
table.CreateWithPrepare(conn, "(StringFiled STRING)");
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
// Delete table
EXPECT_EQ(Connect(conn_str, conn), SQL_SUCCESS);
table.Drop(conn);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
}
#endif // BQ_DRIVER_INTEGRATION_TESTS
TEST_P(HTAPIParameterizedTest, SQLExecDirect_with_pagination) {
bool is_htapi = GetParam();
SQLRETURN status;
auto conn = std::make_shared<ODBCHandles>();
std::string connection_string = kDefaultConnectionString;
int limit = 3000;
if (is_htapi) {
connection_string =
kDefaultConnectionString +
";AllowHtapiForLargeResults=1;UseDefaultLargeResultsDataset=0;"
// The default LargeResultsDataSetId `_bqodbc_temp_tables` cannot be
// created in europe_west1 because it already exists in `US`
"LargeResultsDataSetId=_bqodbc_temp_tables_euwest1";
limit = 500;
}
EXPECT_EQ(Connect(connection_string, conn), SQL_SUCCESS);
// This table has 300 string columns and one for `index`
// The values follow this pattern: col<col_index>_row<row_index>
std::string query =
"SELECT * EXCEPT (index) FROM "
"ODBC_HTAPI_TESTING_EUROPE_WEST1.300_columns_string "
"ORDER BY index LIMIT " +
std::to_string(limit) + ";";
// The table name here doesn't matter because we didn't create one.
Table table("Random_table_name");
RowWiseResults const& results = table.Fetch(conn, query);
int const expected_num_cols = 300;
ASSERT_EQ(results.size(), limit) << "Row count mismatch.";
for (int i = 0; i < limit; ++i) {
Row const& row = results[i];
ASSERT_EQ(row.size(), expected_num_cols)
<< "Row " << i << ": Column count mismatch.";
for (int j = 0; j < expected_num_cols; ++j) {
// Construct the expected string: "col<j>_row<i>"
std::string expected_value =
"col" + std::to_string(j) + "_row" + std::to_string(i);
ASSERT_TRUE(row.count(j))
<< "Row " << i << ": Missing expected column with index " << j;
ASSERT_EQ(row.at(j), expected_value)
<< "Row " << i << ", Col " << j << ": Value mismatch.";
}
}
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
}
TEST_P(HTAPIParameterizedTest, SQLExecDirect_with_empty_result_set) {
bool is_htapi = GetParam();
auto conn = std::make_shared<ODBCHandles>();
std::string connection_string = kDefaultConnectionString;
if (is_htapi) {
connection_string =
kDefaultConnectionString + ";AllowHtapiForLargeResults=1;";
}
EXPECT_EQ(Connect(connection_string, conn), SQL_SUCCESS);
// Query that intentionally returns no rows.
std::string query = "SELECT 1 LIMIT 0";
Table table("Random_table_name");
RowWiseResults const& results = table.Fetch(conn, query);
// Expect an empty result set.
EXPECT_EQ(results.size(), 0U);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
}
TEST(StatementTest, SQLExecDirectW) {
auto conn = std::make_shared<ODBCHandles>();
EXPECT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
std::wstring const table_name =
ToWStr(kDatasetWithTablePrefix) + L"ODBC_INSERT_SQLEXECDIRECTW_TEST";
Table table(table_name);
table.CreateW(conn, L"(string_field STRING)");
std::wstring const string_field = L"Some Test String नमस्ते";
std::wstring query =
L"INSERT INTO " + table_name + L" VALUES ('" + string_field + L"')";
std::vector<SQLWCHAR> insert_stmt(query.begin(), query.end());
insert_stmt.emplace_back(L'\0');
SQLRETURN status =
SQLExecDirectW(conn->hstmt, (SQLWCHAR*)insert_stmt.data(), SQL_NTS);
CheckError(status, "SQLExecDirectW", conn);
table.DropW(conn);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
}
TEST(StatementTest, SQLExecute_UsingDescriptor) {
auto conn = std::make_shared<ODBCHandles>();
EXPECT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
EXPECT_EQ(InsertStatementWithBindParameter(conn), SQL_SUCCESS);
// We inserted a row using first statement handle.
// Now we're going to do the same using a new statement handle,
// but without SQLBindParameter calls.
// We reuse desc handle instead.
// Free existing statement handle (within same connection)
SQLCloseCursor(conn->hstmt);
auto status = SQLFreeHandle(SQL_HANDLE_STMT, conn->hstmt);
CheckError(status, "SQLFreeHandle", conn);
// Allocate a new statement handle (within same connection)
status = SQLAllocHandle(SQL_HANDLE_STMT, conn->hdbc, &conn->hstmt);
CheckError(status, "SQLAllocHandle", conn);
EXPECT_EQ(InsertStatementWithoutBindParameter(conn), SQL_SUCCESS);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
////////////////
/// USE ANSI
////////////////
EXPECT_EQ(Connect(kDefaultConnectionString, conn, true), SQL_SUCCESS);
EXPECT_EQ(InsertStatementWithBindParameter(conn, true), SQL_SUCCESS);
// We inserted a row using first statement handle.
// Now we're going to do the same using a new statement handle,
// but without SQLBindParameter calls.
// We reuse desc handle instead.
// Free existing statement handle (within same connection)
SQLCloseCursor(conn->hstmt);
status = SQLFreeHandle(SQL_HANDLE_STMT, conn->hstmt);
CheckError(status, "SQLFreeHandle", conn);
// Allocate a new statement handle (within same connection)
status = SQLAllocHandle(SQL_HANDLE_STMT, conn->hdbc, &conn->hstmt);
CheckError(status, "SQLAllocHandle", conn);
EXPECT_EQ(InsertStatementWithoutBindParameter(conn, true), SQL_SUCCESS);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
}
TEST(StatementTest, SQLPrimaryKeys_VerifyMetadata) {
auto conn = std::make_shared<ODBCHandles>();
ASSERT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
SQLRETURN ret = SQLPrimaryKeys(
conn->hstmt, (SQLCHAR*)"bigquery-devtools-drivers", SQL_NTS,
(SQLCHAR*)"INTEGRATION_TESTS", SQL_NTS, (SQLCHAR*)"Test_Table", SQL_NTS);
ASSERT_TRUE(SQL_SUCCEEDED(ret));
ExpectedColMetadata expected[] = {
{"TABLE_CAT", SQL_WVARCHAR, 128, 0, SQL_NULLABLE},
{"TABLE_SCHEM", SQL_WVARCHAR, 1024, 0, SQL_NULLABLE},
{"TABLE_NAME", SQL_WVARCHAR, 1024, 0, SQL_NO_NULLS},
{"COLUMN_NAME", SQL_WVARCHAR, 128, 0, SQL_NO_NULLS},
{"KEY_SEQ", SQL_SMALLINT, 5, 0, SQL_NO_NULLS},
{"PK_NAME", SQL_WVARCHAR, 128, 0, SQL_NULLABLE},
};
VerifyResultSetMetadata(
conn->hstmt, static_cast<SQLSMALLINT>(std::size(expected)), expected);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
}
TEST(StatementTest, SQLForeignKeys_VerifyMetadata) {
auto conn = std::make_shared<ODBCHandles>();
ASSERT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
SQLRETURN ret = SQLForeignKeys(
conn->hstmt, (SQLCHAR*)"bigquery-devtools-drivers", SQL_NTS,
(SQLCHAR*)"INTEGRATION_TESTS", SQL_NTS, (SQLCHAR*)"Test_Table", SQL_NTS,
NULL, 0, NULL, 0, NULL, 0);
ASSERT_TRUE(SQL_SUCCEEDED(ret));
ExpectedColMetadata expected[] = {
{"PKTABLE_CAT", SQL_WVARCHAR, 128, 0, SQL_NULLABLE},
{"PKTABLE_SCHEM", SQL_WVARCHAR, 1024, 0, SQL_NULLABLE},
{"PKTABLE_NAME", SQL_WVARCHAR, 1024, 0, SQL_NO_NULLS},
{"PKCOLUMN_NAME", SQL_WVARCHAR, 128, 0, SQL_NO_NULLS},
{"FKTABLE_CAT", SQL_WVARCHAR, 128, 0, SQL_NULLABLE},
{"FKTABLE_SCHEM", SQL_WVARCHAR, 1024, 0, SQL_NULLABLE},
{"FKTABLE_NAME", SQL_WVARCHAR, 1024, 0, SQL_NO_NULLS},
{"FKCOLUMN_NAME", SQL_WVARCHAR, 128, 0, SQL_NO_NULLS},
{"KEY_SEQ", SQL_SMALLINT, 5, 0, SQL_NO_NULLS},
{"UPDATE_RULE", SQL_SMALLINT, 5, 0, SQL_NULLABLE},
{"DELETE_RULE", SQL_SMALLINT, 5, 0, SQL_NULLABLE},
{"FK_NAME", SQL_WVARCHAR, 128, 0, SQL_NULLABLE},
{"PK_NAME", SQL_WVARCHAR, 128, 0, SQL_NULLABLE},
{"DEFERRABILITY", SQL_SMALLINT, 5, 0, SQL_NULLABLE},
};
VerifyResultSetMetadata(
conn->hstmt, static_cast<SQLSMALLINT>(std::size(expected)), expected);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
}
TEST(StatementTest, SQLNumParamsAndSQLBindParam) {
auto conn = std::make_shared<ODBCHandles>();
auto table_name =
kDatasetWithTablePrefix + "ODBC_NUM_PARAMS_AND_BIND_PARAM_TEST";
auto insert_stmt = "INSERT INTO " + table_name + " VALUES (?, ?, ?)";
Table table(table_name);
// Create Table
EXPECT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
table.Create(
conn, "(StringField STRING, IntegerField INTEGER, FloatField FLOAT64)");
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
// Prepare statement
EXPECT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
SQLSMALLINT num_params;
auto status = SQLPrepare(conn->hstmt, (SQLCHAR*)insert_stmt.c_str(), SQL_NTS);
CheckError(status, "SQLPrepare", conn);
// Bind parameter with number 10
SQLUSMALLINT param_number = 10;
SQLINTEGER param_val = 30;
status = SQLBindParameter(conn->hstmt, param_number, SQL_PARAM_INPUT,
SQL_C_CHAR, SQL_CHAR, 10, 20, ¶m_val, 40, NULL);
CheckError(status, "SQLBindParameter", conn);
status =
SQLGetStmtAttr(conn->hstmt, SQL_ATTR_IMP_PARAM_DESC, &conn->ipd, 0, NULL);
CheckError(status, "SQLGetStmtAttr(SQL_ATTR_IMP_PARAM_DESC)", conn);
SQLSMALLINT count = 0;
status = SQLGetDescField(conn->ipd, 0, SQL_DESC_COUNT, &count, 0, NULL);
CheckError(status, "SQLGetDescField(SQL_DESC_COUNT)", conn);
EXPECT_EQ(count, param_number);
// Check SQLNumParams returns count of parameters from SQLPrepare
status = SQLNumParams(conn->hstmt, &num_params);
CheckError(status, "SQLNumParams", conn);
EXPECT_EQ(num_params, 3);
EXPECT_NE(num_params, count);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
EXPECT_EQ(Connect(kDefaultConnectionString, conn, true), SQL_SUCCESS);
table.Drop(conn, true);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
}
TEST(StatementTest, SQLDescribeCol) {
auto const table_name =
kDatasetWithTablePrefix + "ODBC_COLUMN_DESCRIPTION_TEST";
Table table(table_name);
Schema schema{{"StringField", "STRING"},
{"IntegerField", "INT64"},
{"FloatField", "FLOAT64"}};
// Create Table
auto conn = std::make_shared<ODBCHandles>();
EXPECT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
table.Create(
conn, "(StringField STRING, IntegerField INTEGER, FloatField FLOAT64)");
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
// Insert data to read
EXPECT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
table.InsertData(conn, kSampleData);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
EXPECT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
CheckColumnData(conn, table_name, schema);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
EXPECT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
table.Drop(conn);
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
////////////////
/// USE ANSI
////////////////
auto const table_name_ansi =
kDatasetWithTablePrefix + "ODBC_COLUMN_DESCRIPTION_TEST_ANSI";
Table table_ansi(table_name_ansi);