Skip to content

Commit 21116ca

Browse files
impl(bq_driver): add sql_wvarchar impl
1 parent 0ebda22 commit 21116ca

15 files changed

Lines changed: 208 additions & 40 deletions

google/cloud/odbc/bq_driver/internal/driver_adv_opt_form.cc

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ std::string AdvanceOptions::default_string_length_ = kDefaultStringLength;
5656
std::string AdvanceOptions::session_location_;
5757
std::string AdvanceOptions::additional_projects_;
5858
std::string AdvanceOptions::query_properties_;
59-
std::string AdvanceOptions::use_wchar_;
59+
std::string AdvanceOptions::use_wvarchar_;
6060
std::string AdvanceOptions::enable_session_;
6161
std::string AdvanceOptions::activation_threshold_checkbox_;
6262
std::string AdvanceOptions::allow_large_results_;
@@ -76,7 +76,7 @@ std::string const kSessionLocation = "SessionLocation";
7676
std::string const kAdditionalProjects = "AdditionalProjects";
7777
std::string const kQueryProperties = "QueryProperties";
7878
std::string const kActivationThreshold = "HTAPI_ActivationThreshold";
79-
std::string const kUseWChar = "UseWVarChar";
79+
std::string const kUseWVarchar = "UseWVarChar";
8080
std::string const kEnableSession = "EnableSession";
8181
std::string const kHTAPIActivationThresholdCheck = "AllowHtapiForLargeResults";
8282
std::string const kAllowLargeResults = "AllowLargeResults";
@@ -359,21 +359,20 @@ void AdvanceOptions::CreateAdditionalControls(HFONT h_font) {
359359
SetWindowLongPtr(
360360
h_max_retries_edit, GWL_STYLE,
361361
GetWindowLongPtr(h_max_retries_edit, GWL_STYLE) | ES_RIGHT | ES_NUMBER);
362-
// TODO(b/497725655): Enable UI feature after public release
363-
// HWND h_variables_checkbox = CreateCheckBox(
364-
// adv_hwnd, "Use SQL_WVARCHAR instead of SQL_VARCHAR", kXAxis, kYAxis +
365-
// 390, kWidth * 7, kHeight, kIdcVariableCheckbox);
366-
// CheckDlgButton(adv_hwnd, kIdcVariableCheckbox,
367-
// (use_wchar_ == "1") ? BST_CHECKED : BST_UNCHECKED);
368-
// SendMessage(h_variables_checkbox, WM_SETFONT, (WPARAM)h_font, TRUE);
369-
// SetWindowSubclass(GetDlgItem(adv_hwnd, kIdcVariableCheckbox),
370-
// CheckboxSubclassProc, 0, 0);
362+
HWND h_variables_checkbox = CreateCheckBox(
363+
adv_hwnd, "Use SQL_WVARCHAR instead of SQL_VARCHAR", kXAxis, kYAxis + 415,
364+
kWidth * 7, kHeight, kIdcUseWVarcharCheckbox);
365+
CheckDlgButton(adv_hwnd, kIdcUseWVarcharCheckbox,
366+
(use_wvarchar_ == "1") ? BST_CHECKED : BST_UNCHECKED);
367+
SendMessage(h_variables_checkbox, WM_SETFONT, (WPARAM)h_font, TRUE);
368+
SetWindowSubclass(GetDlgItem(adv_hwnd, kIdcUseWVarcharCheckbox),
369+
CheckboxSubclassProc, 0, 0);
371370
HWND h_additional_projects_label =
372-
CreateLabel(adv_hwnd, "Additional projects:", kXAxis, kYAxis + 420,
371+
CreateLabel(adv_hwnd, "Additional projects:", kXAxis, kYAxis + 440,
373372
kWidth * 5, kHeight, WS_VISIBLE | SS_LEFT);
374373
SendMessage(h_additional_projects_label, WM_SETFONT, (WPARAM)h_font, TRUE);
375374
HWND h_additional_projects_edit =
376-
CreateScrollableEditBox(adv_hwnd, kXAxis, kYAxis + 440, kWidth + 380,
375+
CreateScrollableEditBox(adv_hwnd, kXAxis, kYAxis + 460, kWidth + 380,
377376
kHeight + 32, kIdcAdditionalProjectsEdit);
378377
SendMessage(h_additional_projects_edit, WM_SETFONT, (WPARAM)h_font, TRUE);
379378

@@ -382,11 +381,11 @@ void AdvanceOptions::CreateAdditionalControls(HFONT h_font) {
382381
InputSubclassProc, 0, 0);
383382

384383
HWND h_query_properties_label =
385-
CreateLabel(adv_hwnd, "Query properties:", kXAxis, kYAxis + 500,
384+
CreateLabel(adv_hwnd, "Query properties:", kXAxis, kYAxis + 520,
386385
kWidth * 5, kHeight, WS_VISIBLE | SS_LEFT);
387386
SendMessage(h_query_properties_label, WM_SETFONT, (WPARAM)h_font, TRUE);
388387
HWND h_query_properties_edit =
389-
CreateScrollableEditBox(adv_hwnd, kXAxis, kYAxis + 520, kWidth + 385,
388+
CreateScrollableEditBox(adv_hwnd, kXAxis, kYAxis + 540, kWidth + 385,
390389
kHeight + 13, kIdcQueryPropertiesEdit);
391390
SendMessage(h_query_properties_edit, WM_SETFONT, (WPARAM)h_font, TRUE);
392391

@@ -410,12 +409,12 @@ void AdvanceOptions::CreateAdditionalControls(HFONT h_font) {
410409
}
411410

412411
void AdvanceOptions::CreateButtons(HFONT h_font) {
413-
HWND h_ok_button = CreateButton(adv_hwnd, "OK", kOkButtonX + 2, kButtonY + 38,
412+
HWND h_ok_button = CreateButton(adv_hwnd, "OK", kOkButtonX + 2, kButtonY + 58,
414413
kButtonWidth, kButtonHeight, kIdcOKButton);
415414
SendMessage(h_ok_button, WM_SETFONT, (WPARAM)h_font, TRUE);
416415

417416
HWND h_cancel_button =
418-
CreateButton(adv_hwnd, "Cancel", kCancelButtonX, kButtonY + 38,
417+
CreateButton(adv_hwnd, "Cancel", kCancelButtonX, kButtonY + 58,
419418
kButtonWidth, kButtonHeight, kIdcCancelButton);
420419
SendMessage(h_cancel_button, WM_SETFONT, (WPARAM)h_font, TRUE);
421420
}
@@ -628,11 +627,10 @@ LRESULT CALLBACK AdvanceOptions::AdvanceOptProc(HWND hwnd, UINT u_msg,
628627
GetWindowText(h_activation_threshold, activation_threshold_buffer,
629628
sizeof(activation_threshold_buffer));
630629
activation_threshold_ = activation_threshold_buffer;
631-
// TODO(b/497725655): Enable UI feature after public release
632-
// use_wchar_ =
633-
// (IsDlgButtonChecked(hwnd, kIdcVariableCheckbox) == BST_CHECKED)
634-
// ? "1"
635-
// : "0";
630+
use_wvarchar_ =
631+
(IsDlgButtonChecked(hwnd, kIdcUseWVarcharCheckbox) == BST_CHECKED)
632+
? "1"
633+
: "0";
636634

637635
enable_session_ =
638636
(IsDlgButtonChecked(hwnd, kIdcEnableSessionCheckbox) ==
@@ -785,8 +783,7 @@ void AdvanceOptions::SetValues(Section const& attribute_map) {
785783
query_properties_ = GetValueOrDefault(attribute_map, kQueryProperties);
786784
activation_threshold_ =
787785
GetValueOrDefault(attribute_map, kActivationThreshold);
788-
// TODO(b/497725655): Enable UI feature after public release
789-
// use_wchar_ = GetValueOrDefault(attribute_map, kUseWChar);
786+
use_wvarchar_ = GetValueOrDefault(attribute_map, kUseWVarchar);
790787
enable_session_ = GetValueOrDefault(attribute_map, kSessionLocation);
791788
activation_threshold_checkbox_ =
792789
GetValueOrDefault(attribute_map, kHTAPIActivationThresholdCheck);
@@ -809,7 +806,7 @@ void AdvanceOptions::ResetToDefaults() {
809806
additional_projects_.clear();
810807
query_properties_.clear();
811808
activation_threshold_.clear();
812-
// use_wchar_.clear();
809+
use_wvarchar_.clear();
813810
enable_session_.clear();
814811
activation_threshold_checkbox_.clear();
815812
allow_large_results_.clear();
@@ -837,7 +834,7 @@ void AdvanceOptions::Show(HWND hwnd) {
837834
RegisterClass(&wc_adv);
838835

839836
int window_width = 462;
840-
int window_height = 650;
837+
int window_height = 670;
841838
int screen_width = GetSystemMetrics(SM_CXSCREEN);
842839
int screen_height = GetSystemMetrics(SM_CYSCREEN);
843840
int x_pos = (screen_width - window_width) / 2;

google/cloud/odbc/bq_driver/internal/driver_adv_opt_form.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static int const kIdcQueryPropertiesEdit = 140;
3737
static int const kIdcOKButton = 141;
3838
static int const kIdcCancelButton = 142;
3939
static int const kIdcLanguageDialectComboBox = 143;
40-
static int const kIdcVariableCheckbox = 144;
40+
static int const kIdcUseWVarcharCheckbox = 144;
4141
static int const KIdcLargeResultHeader = 145;
4242
static int const kIdcEncryptionKeyComboBox = 146;
4343
static int const kIdcHyperlink2 = 147;
@@ -85,7 +85,7 @@ class AdvanceOptions {
8585
inline std::string const& GetActivationThreshold() const {
8686
return activation_threshold_;
8787
}
88-
inline std::string const& GetUseWchar() const { return use_wchar_; }
88+
inline std::string const& GetUseWVarChar() const { return use_wvarchar_; }
8989
inline std::string const& GetEnableSession() const { return enable_session_; }
9090
inline std::string const& GetActivationThresholdCheckbox() const {
9191
return activation_threshold_checkbox_;
@@ -119,7 +119,7 @@ class AdvanceOptions {
119119
static std::string additional_projects_;
120120
static std::string query_properties_;
121121
static std::string activation_threshold_;
122-
static std::string use_wchar_;
122+
static std::string use_wvarchar_;
123123
static std::string enable_session_;
124124
static std::string activation_threshold_checkbox_;
125125
static std::string allow_large_results_;

google/cloud/odbc/bq_driver/internal/driver_form.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static Section BuildTestConnectionAttributes(
224224
attributes_map["QueryProperties"] = adv_form.GetQueryProperties();
225225
attributes_map["HTAPI_ActivationThreshold"] =
226226
adv_form.GetActivationThreshold();
227-
attributes_map["UseWVarChar"] = adv_form.GetUseWchar();
227+
attributes_map["UseWVarChar"] = adv_form.GetUseWVarChar();
228228
attributes_map["EnableSession"] = adv_form.GetEnableSession();
229229
attributes_map["AllowHtapiForLargeResults"] =
230230
adv_form.GetActivationThresholdCheckbox();

google/cloud/odbc/bq_driver/internal/odbc_conn_handle.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ void ConnectionHandle::SetUp(Section& dsn_section,
138138
dsn_.max_retries =
139139
!max_retries.empty() ? std::stoull(max_retries) : kDefaultMaxRetries;
140140

141+
std::string use_wvarchar = dsn_section["USEWVARCHAR"];
142+
if (!use_wvarchar.empty()) {
143+
GetUpperStr(use_wvarchar);
144+
dsn_.use_wvarchar = (use_wvarchar == "1" || use_wvarchar == "TRUE");
145+
}
141146
dsn_.pem_file = dsn_section["TRUSTEDCERTS"];
142147
dsn_.kms_key_name = dsn_section["KMSKEYNAME"];
143148
dsn_.session_location = dsn_section["SESSIONLOCATION"];

google/cloud/odbc/bq_driver/internal/odbc_conn_handle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct Dsn {
7676
bool use_default_large_results_dataset = true;
7777
std::string large_results_dataset_id;
7878
bool allow_htapi = false;
79+
bool use_wvarchar = false;
7980
std::string htapi_activation_threshold = "10000";
8081
std::string large_table_expiration_time = kDefaultLargeResultsTableExpiration;
8182

google/cloud/odbc/bq_driver/internal/odbc_desc_attr.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,12 @@ StatusRecord DescriptorRecord::SetOctetLength(SQLSMALLINT type,
386386
octet_length = value;
387387
break;
388388
case SQL_WCHAR:
389-
case SQL_WVARCHAR:
390389
case SQL_WLONGVARCHAR:
391390
octet_length = value * sizeof(SQLWCHAR);
392391
break;
392+
case SQL_WVARCHAR:
393+
octet_length = value * 4;
394+
break;
393395
case SQL_DECIMAL:
394396
case SQL_NUMERIC:
395397
octet_length = (precision + 2);

google/cloud/odbc/bq_driver/internal/odbc_internal_commons.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,12 +1189,12 @@ odbc_internal::StatusRecordOr<std::string> GetDataTypeInStr(BQDataType type) {
11891189
}
11901190

11911191
odbc_internal::StatusRecordOr<SQLSMALLINT> GetSQLDataType(
1192-
std::string const& type, bool isArray) {
1192+
std::string const& type, bool isArray, bool UseWvarchar) {
11931193
if (isArray) {
11941194
return SQL_VARCHAR;
11951195
}
11961196
if (type == "STRING") {
1197-
return SQL_VARCHAR;
1197+
return UseWvarchar ? SQL_WVARCHAR : SQL_VARCHAR;
11981198
}
11991199
if (type == "INTEGER" || type == "INT64") {
12001200
return SQL_BIGINT;

google/cloud/odbc/bq_driver/internal/odbc_internal_commons.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ odbc_internal::StatusRecordOr<BQDataType> ConvertDSType(
584584
std::string const& type);
585585

586586
odbc_internal::StatusRecordOr<SQLSMALLINT> GetSQLDataType(
587-
std::string const& type, bool isArray = false);
587+
std::string const& type, bool isArray = false, bool UseWvarchar = false);
588588

589589
odbc_internal::StatusRecordOr<
590590
google::cloud::bigquery_v2_minimal_internal::QueryParameter>

google/cloud/odbc/bq_driver/internal/odbc_stmt_handle.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ StatusRecord StatementHandle::PopulateIrd(DescriptorHandle& descriptor_handle,
354354
DescriptorRecord descriptor_record;
355355
descriptor_record.SetName(res.name, res.name.length());
356356
descriptor_record.length = res.max_length;
357-
StatusRecordOr<SQLSMALLINT> type_status_record =
358-
GetSQLDataType(res.type, (res.mode == array_field));
357+
StatusRecordOr<SQLSMALLINT> type_status_record = GetSQLDataType(
358+
res.type, (res.mode == array_field), conn_handle.GetDsn().use_wvarchar);
359359

360360
if (!type_status_record.Ok()) {
361361
LOG(ERROR) << "StatementHandle::PopulateIrd::GetSQLDataType:: "

google/cloud/odbc/bq_driver/odbc_sql_results.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ SQLRETURN SQLDescribeColInternal(
484484
case SQL_SMALLINT:
485485
case SQL_TINYINT:
486486
case SQL_BIGINT:
487+
case SQL_WVARCHAR:
487488
IntValueToOutputBufferResponse<SQLSMALLINT, SQLSMALLINT>(
488489
desc_record.precision, column_size, nullptr);
489490
break;

0 commit comments

Comments
 (0)