-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathodbc_internal_commons.h
More file actions
658 lines (575 loc) · 23.2 KB
/
Copy pathodbc_internal_commons.h
File metadata and controls
658 lines (575 loc) · 23.2 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
// Copyright 2024 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.
#ifndef CPP_BIGQUERY_ODBC_GOOGLE_CLOUD_ODBC_BQ_DRIVER_INTERNAL_ODBC_INTERNAL_COMMONS_H
#define CPP_BIGQUERY_ODBC_GOOGLE_CLOUD_ODBC_BQ_DRIVER_INTERNAL_ODBC_INTERNAL_COMMONS_H
#include "google/cloud/odbc/bq_client_interface/odbc_bq_client.h"
#include "google/cloud/odbc/bq_driver/internal/odbc_conn_handle.h"
#include "google/cloud/odbc/bq_driver/internal/odbc_handle.h"
#include "google/cloud/odbc/bq_driver/internal/trace_utils.h"
#include "google/cloud/odbc/internal/odbc_includes.h"
#include "google/cloud/odbc/internal/sql_state_constants.h"
#include "google/cloud/odbc/internal/status_record_or.h"
#include "absl/types/variant.h"
#if (!defined(_WIN32) || defined(_WIN64)) && !defined(NO_ARROW)
#include <arrow/api.h>
#include <arrow/io/memory.h>
#include <arrow/ipc/api.h>
#include <arrow/ipc/reader.h>
#endif // (!defined(_WIN32) || defined(_WIN64)) && !defined(NO_ARROW)
#include <chrono>
#include <cstring>
#include <sstream>
#include <string>
#include <vector>
#ifdef _WIN32
#include <wincrypt.h>
#endif
namespace google::cloud::odbc_bq_driver_internal {
// The Base64 character set
// (ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/) is a
// well-defined, standardized string that doesn’t change across different
// implementations of Base64 encoding. The characters in this string represent
// the 64 possible values used in Base64 encoding.
static std::string const kBasE64Chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
template <typename T>
SQLRETURN LogAndReturnCode(
Handle& handle, odbc_internal::StatusRecordOr<T> const& status_record_or) {
if (!status_record_or) {
auto status_record = status_record_or.GetStatusRecord();
// Handling special case for SQL_NO_DATA where we are not supposed to have
// an error diagnostic message
if (status_record.sql_state ==
google::cloud::odbc_internal::SQLStates::k_SQL_NO_DATA()) {
return SQL_NO_DATA;
}
handle.GetDiagnostics().AddStatusRecord(status_record);
}
return status_record_or.GetCalculatedReturnCode();
}
inline SQLRETURN LogAndReturnCode(
Handle& handle, odbc_internal::StatusRecord const& status_record) {
if (!status_record.ok()) {
// Handling special case for SQL_NO_DATA where we are not supposed to have
// an error diagnostic message
if (status_record.sql_state ==
google::cloud::odbc_internal::SQLStates::k_SQL_NO_DATA()) {
return SQL_NO_DATA;
}
handle.GetDiagnostics().AddStatusRecord(status_record);
}
return status_record.CalculateReturnCode();
}
odbc_internal::StatusRecordOr<std::string> GetMissingAttributesStr(
ConnectionHandle* conn_handle);
odbc_internal::StatusRecord ValidateAllowedAttributes(
ConnectionHandle* conn_handle, Section const& attributes);
// Data Types as supported by the BQ DataSource.
enum BQDataType {
kArray,
kBigNumeric,
kNumeric,
kBytes,
kInt64,
kDate,
kFloat64,
kInterval,
kGeography,
kDatetime,
kTime,
kBool,
kString,
kRange,
kStruct,
kJson,
kTimeStamp,
kNull,
kInValid
};
// Contains the column data types, as represented by the data source,
// for each column in a ResultSet row.
struct ColumnSchema {
int col_index;
BQDataType col_type;
bool is_mode_repeated = false;
};
bool operator==(ColumnSchema const& lhs, ColumnSchema const& rhs);
bool operator>(ColumnSchema const& lhs, ColumnSchema const& rhs);
bool operator<(ColumnSchema const& lhs, ColumnSchema const& rhs);
inline constexpr char const* kTableCatColName = "TABLE_CAT";
inline constexpr char const* kTableSchemaColName = "TABLE_SCHEM";
inline constexpr char const* kTableNameColName = "TABLE_NAME";
inline constexpr char const* kRemarksColName = "REMARKS";
inline constexpr char const* kColumnNameColName = "COLUMN_NAME";
inline constexpr char const* kKeySeqColName = "KEY_SEQ";
inline constexpr char const* kPkNameColName = "PK_NAME";
inline constexpr ColumnSchema kTableCatSchema{0, BQDataType::kString};
inline constexpr ColumnSchema kTableSchemaSchema{0, BQDataType::kString};
inline constexpr ColumnSchema kTableNameSchema{0, BQDataType::kString};
inline constexpr ColumnSchema kRemarksSchema{0, BQDataType::kString};
inline constexpr ColumnSchema kColumnNameSchema{0, BQDataType::kString};
inline constexpr ColumnSchema kKeySeqSchema{0, BQDataType::kInt64};
inline constexpr ColumnSchema kPkNameSchema{0, BQDataType::kString};
inline ColumnSchema WithIndex(int col_index, ColumnSchema base) {
base.col_index = col_index;
return base;
}
// Data Source Value.
using DSValue = std::vector<char>;
// Data Source Row.
using DSRow = std::vector<DSValue>;
// ResultSet rows containing data source rows.
using ResultSetRows = std::vector<DSRow>;
// Row schema representing the column schema of the
// data source row columns.
using RowSchema = std::vector<ColumnSchema>;
struct TranslatedData {
SQLLEN row_offset{0}; // Offset to manage last fetch row index in case
// of partial data fetch in SQLGetData
DSValue data; // To store translated data when buffer length is less
// and SQLGetData fetches partial data.
SQLSMALLINT last_target_c_type{0}; // Holds the last fetched target data type
// (SQL C data type) for the column.
// This is used to track the type of the data fetched in the previous
// SQLGetData call.
int last_column_index{
-1}; // contains the column number fetched in last SQLGetData call
};
// ResultSet structure representing the data from the BQ DataSource.
struct ResultSet {
RowSchema row_schema;
#if (!defined(_WIN32) || defined(_WIN64)) && !defined(NO_ARROW)
std::shared_ptr<arrow::Schema> arrow_schema;
#endif // (!defined(_WIN32) || defined(_WIN64)) && !defined(NO_ARROW)
ResultSetRows rows;
mutable int cursor{-1}; // points before the next row to fetch
// Total number of rows fetched in previous batches
// This is used to handle `SQL_ATTR_MAX_ROWS` attribute
mutable int num_rows_fetched_yet{0};
mutable TranslatedData translated_data;
};
DSValue const kNullValue{0};
inline bool IsDSValueNull(DSValue const& value) {
return value.size() == 1 && value[0] == 0;
}
// converting the given string to Numeric number
// getting scale ,precision, sign and the value from sting parameter
odbc_internal::StatusRecord GetNumericDetailsFromStr(
std::string const& src_dsval, SQL_NUMERIC_STRUCT& numst);
inline void StringToDSValue(std::string const& str, DSValue& value) {
value.resize(str.size());
std::copy(str.begin(), str.end(), value.begin());
}
// Func to decode a Base64-encoded string into a vector of bytes.
inline void Base64Decode(std::string const& encoded,
std::vector<uint8_t>& result) {
int val = 0;
int valb = -8;
for (unsigned char c : encoded) {
if (!absl::StrContains(kBasE64Chars, c)) {
break; // Stop at non-base64 characters (ignore padding)
}
val = (val << 6) + kBasE64Chars.find(c);
valb += 6;
if (valb >= 0) {
result.push_back((val >> valb) & 0xFF);
valb -= 8;
}
}
}
inline void NumericToDSValue(std::string const& str, DSValue& DSval) {
DSval.resize(str.size());
std::copy(str.begin(), str.end(), DSval.begin());
}
// Function to convert byte data to a hex string
inline void BytesToHex(std::vector<uint8_t> const& data,
std::string& restult_str) {
std::stringstream ss;
for (auto byte : data) {
ss << std::hex << std::uppercase << std::setfill('0') << std::setw(2)
<< static_cast<int>(byte);
}
restult_str = "0x" + ss.str();
}
// Function to convert hex string to byte data
inline std::vector<uint8_t> HexToBytes(std::string const& hex) {
std::vector<uint8_t> bytes;
for (size_t i = 0; i < hex.length(); i += 2) {
std::string byte_string = hex.substr(i, 2);
bytes.push_back(static_cast<uint8_t>(std::stoul(byte_string, nullptr, 16)));
}
return bytes;
}
#ifdef _WIN32
// Encrypt password using Windows DPAPI
std::string EncryptPassword(std::string const& password);
// Decrypt password using Windows DPAPI
odbc_internal::StatusRecordOr<std::string> DecryptPassword(
std::string const& encrypted_hex);
#endif //_WIN32
inline void StringToDSValue(const SQLCHAR* c_str, DSValue& value) {
std::string str = reinterpret_cast<char const*>(c_str);
StringToDSValue(str, value);
}
inline void DSValueToString(DSValue const& value, std::string& str) {
str.assign(value.begin(), value.end());
}
inline void IntToDSValue(int64_t int_val, DSValue& ds_value) {
ds_value.resize(sizeof(int_val));
std::memcpy(ds_value.data(), &int_val, sizeof(int64_t));
}
template <typename SrcType>
inline void ArithmeticToDSValue(SrcType arithmetic_val, DSValue& ds_value) {
ds_value.resize(sizeof(SrcType));
std::memcpy(ds_value.data(), &arithmetic_val, sizeof(SrcType));
}
template <typename SrcType>
inline SrcType DSValueToArithmetic(DSValue& ds_value) {
SrcType val;
std::memcpy(&val, ds_value.data(), sizeof(val));
return val;
}
inline int64_t DSValueToInt(DSValue& ds_value) {
int64_t int_val;
std::memcpy(&int_val, ds_value.data(), sizeof(int_val));
return int_val;
}
inline void DateToDSValue(const SQL_DATE_STRUCT& date, DSValue& value) {
value.resize(sizeof(SQL_DATE_STRUCT));
std::memcpy(value.data(), &date, sizeof(SQL_DATE_STRUCT));
}
inline SQL_DATE_STRUCT DSValueToDate(DSValue const& value,
SQL_DATE_STRUCT& date_struct) {
std::memcpy(&date_struct, value.data(), sizeof(SQL_DATE_STRUCT));
return date_struct;
}
inline std::string FormatTimestampToString(
const SQL_TIMESTAMP_STRUCT& timestamp) {
char buffer[30];
auto const* timestamp_format = (timestamp.fraction == 0)
? "%04d-%02d-%02d %02d:%02d:%02d"
: "%04d-%02d-%02d %02d:%02d:%02d.%06d";
snprintf(buffer, sizeof(buffer), timestamp_format, timestamp.year,
timestamp.month, timestamp.day, timestamp.hour, timestamp.minute,
timestamp.second, timestamp.fraction);
return buffer;
}
inline std::string FormatDatetimeToString(
const SQL_TIMESTAMP_STRUCT& datetime) {
char buffer[30];
auto const* datetime_format = (datetime.fraction == 0)
? "%04d-%02d-%02d %02d:%02d:%02d"
: "%04d-%02d-%02d %02d:%02d:%02d.%06d";
snprintf(buffer, sizeof(buffer), datetime_format, datetime.year,
datetime.month, datetime.day, datetime.hour, datetime.minute,
datetime.second, datetime.fraction);
return buffer;
}
inline void TimestampToDSValue(const SQL_TIMESTAMP_STRUCT& timestamp,
DSValue& value) {
value.resize(sizeof(SQL_TIMESTAMP_STRUCT));
std::memcpy(value.data(), ×tamp, sizeof(SQL_TIMESTAMP_STRUCT));
}
inline void DSValueToTimestamp(DSValue const& value,
SQL_TIMESTAMP_STRUCT& timestamp_struct) {
std::memcpy(×tamp_struct, value.data(), sizeof(SQL_TIMESTAMP_STRUCT));
}
inline void DSValueToDatetime(DSValue const& value,
SQL_TIMESTAMP_STRUCT& timestamp_struct) {
std::memcpy(×tamp_struct, value.data(), sizeof(SQL_TIMESTAMP_STRUCT));
}
inline void TimeToDSValue(const SQL_TIME_STRUCT& time, DSValue& value) {
value.resize(sizeof(SQL_TIME_STRUCT));
std::memcpy(value.data(), &time, sizeof(SQL_TIME_STRUCT));
}
inline SQL_TIME_STRUCT DSValueToTime(DSValue const& value,
SQL_TIME_STRUCT& time_struct) {
std::memcpy(&time_struct, value.data(), sizeof(SQL_TIME_STRUCT));
return time_struct;
}
inline std::string FormatTimetoString(const SQL_TIME_STRUCT& time) {
char buffer[9];
snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", time.hour, time.minute,
time.second);
return buffer;
}
template <typename SrcType>
inline std::string FormatFloatToString(SrcType val) {
std::ostringstream oss;
if constexpr (std::is_same_v<SrcType, double>) {
oss << std::setprecision(std::numeric_limits<double>::max_digits10);
} else if constexpr (std::is_same_v<SrcType, float>) {
oss << std::setprecision(std::numeric_limits<float>::max_digits10);
} else {
oss << std::setprecision(8); // fallback for other cases
}
oss << std::defaultfloat << val;
return oss.str();
}
inline void BooleanToDSValue(bool bool_val, DSValue& value) {
std::string str_val = bool_val ? "true" : "false";
value.resize(str_val.size());
std::copy(str_val.begin(), str_val.end(), value.begin());
}
inline void DSValueToBoolean(DSValue const& value, bool& bool_val) {
std::string str_value(value.begin(), value.end());
bool_val = !(str_value == "false" || str_value == "0" || str_value.empty());
}
inline SQL_TIME_STRUCT ConvertToTimeStruct(std::string const& time_str) {
int hr = std::stoi(time_str.substr(0, 2));
int min = std::stoi(time_str.substr(3, 2));
int sec = std::stoi(time_str.substr(6, 2));
SQL_TIME_STRUCT time;
time.hour = static_cast<SQLSMALLINT>(hr);
time.minute = static_cast<SQLUSMALLINT>(min);
time.second = static_cast<SQLUSMALLINT>(sec);
return time;
}
odbc_internal::StatusRecordOr<SQL_DATE_STRUCT> ConvertStringToDateStruct(
std::string const& date_str);
std::string FormatIntervalToString(SQL_INTERVAL_STRUCT interval);
odbc_internal::StatusRecordOr<std::string> FormatDateToString(
SQL_DATE_STRUCT date);
std::string FormatNumericToString(SQL_NUMERIC_STRUCT numeric);
odbc_internal::StatusRecord ConvertUnixTimestampToTimestampStruct(
double unix_timestamp, SQL_TIMESTAMP_STRUCT& timestamp_struct);
odbc_internal::StatusRecord ConvertStringToIntervalStruct(
std::string const& interval_str, SQL_INTERVAL_STRUCT& interval_struct);
inline void GetSinglePrecisionInterval(
const SQL_INTERVAL_STRUCT interval_struct, SQLUINTEGER& value) {
using odbc_internal::StatusRecord;
StatusRecord status_record = StatusRecord::Ok();
switch (interval_struct.interval_type) {
case SQL_IS_YEAR:
value = interval_struct.intval.year_month.year;
break;
case SQL_IS_MONTH:
value = interval_struct.intval.year_month.month;
break;
case SQL_IS_DAY:
value = interval_struct.intval.day_second.day;
break;
case SQL_IS_HOUR:
value = interval_struct.intval.day_second.hour;
break;
case SQL_IS_MINUTE:
value = interval_struct.intval.day_second.minute;
break;
case SQL_IS_SECOND:
value = interval_struct.intval.day_second.second;
break;
default:
status_record = odbc_internal::StatusRecord{
odbc_internal::SQLStates::k_07006(),
"Interval precision was not a single field"};
break;
}
}
inline void ArrayJsonToDSValue(std::string const& str, DSValue& value,
BQDataType array_type) {
nlohmann::json json_data = nlohmann::json::parse(str);
std::string str_data;
nlohmann::json obj;
obj["v"] = json_data;
switch (array_type) {
case BQDataType::kString:
case BQDataType::kNumeric:
case BQDataType::kBigNumeric:
case BQDataType::kBytes:
case BQDataType::kBool:
case BQDataType::kDate:
case BQDataType::kTime:
case BQDataType::kDatetime:
case BQDataType::kGeography:
case BQDataType::kRange:
case BQDataType::kJson:
case BQDataType::kFloat64: {
std::vector<std::string> result;
for (auto const& item : obj["v"]) {
if (item.contains("v") && item["v"].is_string()) {
result.emplace_back(item["v"].get<std::string>());
}
}
str_data = nlohmann::json(result).dump();
break;
}
case BQDataType::kStruct: {
nlohmann::json str_result = nlohmann::json::array();
for (auto& item : obj["v"]) {
std::string val = item["v"]["f"][0]["v"].get<std::string>();
nlohmann::json obj;
obj["value"] = val;
str_result.emplace_back(obj);
}
str_data = str_result.dump();
break;
}
case BQDataType::kInt64: {
std::vector<std::string> result;
for (auto& item : obj["v"]) {
if (item.contains("v") && !item["v"].is_null()) {
try {
result.emplace_back(std::to_string(item["v"].get<int64_t>()));
} catch (nlohmann::json::exception const& e) {
try {
result.emplace_back(item["v"].get<std::string>());
} catch (...) {
result.emplace_back("0");
}
}
} else {
result.emplace_back("0");
}
}
str_data = nlohmann::json(result).dump();
break;
}
case BQDataType::kTimeStamp: {
std::vector<std::string> result;
for (auto const& item : obj["v"]) {
if (item.is_object() && item.contains("v") && item["v"].is_string()) {
double unix_timestamp = std::stod(item["v"].get<std::string>());
SQL_TIMESTAMP_STRUCT timestamp_struct;
auto status_record = ConvertUnixTimestampToTimestampStruct(
unix_timestamp, timestamp_struct);
if (status_record.ok()) {
auto timestamp_string = FormatTimestampToString(timestamp_struct);
result.emplace_back(timestamp_string);
} else {
result.emplace_back("NULL");
}
}
}
str_data = nlohmann::json(result).dump();
break;
}
default: {
str_data = "";
break;
}
}
value.resize(str_data.size());
std::copy(str_data.begin(), str_data.end(), value.begin());
}
// This is the result populated by performing a bq query API.
// For each call, onely one of PostQueryResults or GetQueryResults will be
// populated with the following semantics:
//
// PostQueryResults:
// - Query finished in specified or default timeout.
// - All query results rows will be present in PostQueryResults.
// GetQueryResults
// - Query did not finish in specified or default timeout and odbc bq client's
// GetAllQueryResults was called.
// - All query results rows will be present in GetQueryResults.
struct DSResults {
absl::variant<absl::monostate,
google::cloud::bigquery_v2_minimal_internal::PostQueryResults,
google::cloud::bigquery_v2_minimal_internal::GetQueryResults,
google::cloud::odbc_bq_driver_internal::ResultSet>
data_source_results;
std::int64_t num_dml_affected_rows = 0;
// We need optional here because:
// 1) In async execution, PostQuery might not have finished.
// 2) No job has been created using JOB_CREATION_OPTIONAL
std::optional<google::cloud::bigquery_v2_minimal_internal::JobReference>
job_ref;
};
//////////////////////////////////////////////////////////////////////
// Common Helper functions related to BQ data source.
/////////////////////////////////////////////////////////////////////
odbc_internal::StatusRecordOr<google::cloud::bigquery_v2_minimal_internal::Job>
CancelBQJob(ConnectionHandle& conn_handle, std::string const& job_id,
std::string const& location = "");
// Calls "jobs.query" without waiting for job_complete to be "true". It assumes
// the job will be finished within the timeout.
odbc_internal::StatusRecordOr<
google::cloud::bigquery_v2_minimal_internal::PostQueryResults>
PostQueryWithoutResults(
std::shared_ptr<ODBCBQClient> const& bq_client,
google::cloud::bigquery_v2_minimal_internal::PostQueryRequest const&
post_query_request,
Options const& options);
odbc_internal::StatusRecordOr<
google::cloud::bigquery_v2_minimal_internal::PostQueryResults>
PostQueryWithoutResults(
ConnectionHandle& conn_handle,
google::cloud::bigquery_v2_minimal_internal::PostQueryRequest const&
post_query_request);
////////////////////////////////////////////////////////////////////////
// Common Helper functions for processing data results from BQ data source and
// converting that to ODBC result sets.
////////////////////////////////////////////////////////////////////////
odbc_internal::StatusRecordOr<ResultSet> ProcessResultSetRows(
google::cloud::bigquery_v2_minimal_internal::TableSchema const& schema,
std::vector<google::cloud::bigquery_v2_minimal_internal::RowData> const&
rows);
odbc_internal::StatusRecordOr<ResultSet> ProcessPostQueryResults(
google::cloud::bigquery_v2_minimal_internal::PostQueryResults const&
post_query_results);
odbc_internal::StatusRecordOr<ResultSet> ProcessGetQueryResults(
google::cloud::bigquery_v2_minimal_internal::GetQueryResults const&
get_query_results);
odbc_internal::StatusRecordOr<ResultSet> ProcessQueryResults(
DSResults const& query_results);
odbc_internal::StatusRecordOr<
std::vector<google::cloud::bigquery_v2_minimal_internal::RowData>>
GetRowsResults(DSResults const& query_results);
///////////////////////////////////////////////////////
// Common helper functions.
////////////////////////////////////////////////////////
odbc_internal::StatusRecordOr<BQDataType> ConvertDSType(
std::string const& type);
odbc_internal::StatusRecordOr<SQLSMALLINT> GetSQLDataType(
std::string const& type, bool isArray = false);
odbc_internal::StatusRecordOr<
google::cloud::bigquery_v2_minimal_internal::QueryParameter>
ConstructStringArrayQueryParameter(
std::string const& parameter_name,
std::vector<std::string> const& parameter_values);
odbc_internal::StatusRecordOr<
google::cloud::bigquery_v2_minimal_internal::QueryParameter>
ConstructStringQueryParameter(std::string const& parameter_name,
std::string const& parameter_value);
odbc_internal::StatusRecordOr<
std::vector<google::cloud::bigquery_v2_minimal_internal::QueryParameter>>
ConstructStringQueryParameters(
std::map<std::string, std::string> const& params);
google::cloud::bigquery_v2_minimal_internal::PostQueryRequest
ConstructBasicPostQueryRequest(ConnectionHandle const& conn_handle,
std::string const& query_str,
int query_timeout = 0,
std::string location = "");
odbc_internal::StatusRecordOr<
google::cloud::bigquery_v2_minimal_internal::PostQueryRequest>
ConstructNamedParametersPostQueryRequest(
std::string const& catalog, std::string const& dataset,
std::string const& named_query,
std::vector<
google::cloud::bigquery_v2_minimal_internal::QueryParameter> const&
named_query_params);
odbc_internal::StatusRecordOr<SQL_TIMESTAMP_STRUCT>
ConvertStringToTimestampStruct(std::string const& date_str);
enum class LanguageDialect {
kStandardSQL = 1,
kLegacySQL = 0,
};
odbc_internal::StatusRecordOr<std::string> GetDataTypeInStr(BQDataType type);
odbc_internal::StatusRecordOr<
google::cloud::bigquery_v2_minimal_internal::TableSchema>
BuildTableSchemaFromRowSchema(
RowSchema& row_schema,
std::map<std::string, ColumnSchema> const& metadata_schema);
} // namespace google::cloud::odbc_bq_driver_internal
#endif // CPP_BIGQUERY_ODBC_GOOGLE_CLOUD_ODBC_BQ_DRIVER_INTERNAL_ODBC_INTERNAL_COMMONS_H