Skip to content

Commit 848b85d

Browse files
impl(bq_driver): Add Log macros in bq_drvier/internal dir second pr (#1172)
1 parent 002ea76 commit 848b85d

13 files changed

Lines changed: 358 additions & 36 deletions

File tree

ci/cloudbuild/dockerfiles/ubuntu-22.04-install.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ ENV PATH=${CLOUD_SDK_LOCATION}/bin:${PATH}
261261
COPY ./gha/builds/lib/odbc.ini /opt/odbc-driver/odbc.ini
262262
COPY ./gha/builds/lib/odbcinst.ini /opt/odbc-driver/odbcinst.ini
263263
COPY ./gha/builds/lib/lsan.supp /opt/odbc-driver/lsan.supp
264+
COPY ./gha/builds/lib/google.googlebigqueryodbc.ini /opt/odbc-driver/google.googlebigqueryodbc.ini
264265

265266
# glibc 2.17 or later
266267
RUN echo 'Installing glibc...'

ci/dependencies/driver-manager-setup-google-driver.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}:/usr/local/lib/
5050
export ODBCSYSINI=/opt/odbc-driver
5151
export ODBCINI=/opt/odbc-driver/odbc.ini
5252
export CPP_BIGQUERY_ODBC_TEST_SERVICE_ACCOUNT_AUTH_KEY=/opt/odbc-driver/connection/key.json
53-
53+
export GOOGLEBIGQUERYODBCINI=/opt/odbc-driver/google.googlebigqueryodbc.ini
5454
cd "$CPP_GOOGLE_BIGQUERY_ODBC_DRIVER_MANAGER_SETUP_CURR_DIR"
5555

5656
echo '**** ODBC Driver installation END****'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[Driver]
2+
LogLevel=0
3+
LogPath=

ci/gha/builds/lib/system_dsn_setup_32.reg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ REGEDIT4
5555
"LogFile"="C:\\b\\trace.log"
5656

5757
[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Google\ODBC Driver for Google BigQuery\Driver]
58-
"LogLevel"="1"
59-
"LogFile"="C:\\b\\trace.log"
58+
"LogLevel"="0"
59+
"LogFile"=

ci/gha/builds/lib/system_dsn_setup_64.reg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ REGEDIT4
5555
"LogFile"="C:\\b\\trace.log"
5656

5757
[HKEY_LOCAL_MACHINE\SOFTWARE\Google\ODBC Driver for Google BigQuery\Driver]
58-
"LogLevel"="1"
59-
"LogFile"="C:\\b\\trace.log"
58+
"LogLevel"="0"
59+
"LogFile"=

ci/gha/builds/macos-cmake.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ source module ci/gha/builds/lib/cmake.sh
2222

2323
cp ci/gha/builds/lib/odbc_osx.ini /Users/runner/work/connection/odbc-driver/odbc.ini
2424
cp ci/gha/builds/lib/odbcinst_osx.ini /Users/runner/work/connection/odbc-driver/odbcinst.ini
25+
cp ci/gha/builds/lib/google.googlebigqueryodbc.ini /Users/runner/work/connection/google.googlebigqueryodbc.ini
2526
export ODBCINI=/Users/runner/work/connection/odbc-driver/odbc.ini
2627
export ODBCINSTINI=/Users/runner/work/connection/odbc-driver/odbcinst.ini
28+
export GOOGLEBIGQUERYODBCINI=/Users/runner/work/connection/google.googlebigqueryodbc.ini
2729
export ODBC_TESTS_DSN="SampleDSNGoogleDriver"
2830
export CPP_BIGQUERY_ODBC_TEST_SERVICE_ACCOUNT_AUTH_KEY=/Users/runner/work/connection/key.json
2931

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

Lines changed: 165 additions & 1 deletion
Large diffs are not rendered by default.

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "google/cloud/odbc/bq_driver/internal/odbc_internal_commons.h"
1919
#include "google/cloud/odbc/bq_driver/internal/odbc_type_utils.h"
20+
#include "google/cloud/odbc/bq_driver/internal/trace_utils.h"
2021
#include "google/cloud/odbc/bq_driver/internal/utils.h"
2122
#include "google/cloud/odbc/internal/odbc_includes.h"
2223
#include "google/cloud/odbc/internal/status_record_or.h"
@@ -34,6 +35,8 @@ inline odbc_internal::StatusRecord CheckLimitsArithmetic(SrcType value) {
3435
using odbc_internal::SQLStates;
3536
using odbc_internal::StatusRecord;
3637
if (!std::is_arithmetic_v<SrcType> || !std::is_arithmetic_v<DestType>) {
38+
LOG(ERROR)
39+
<< "CheckLimitsArithmetic::Invalid datatypes for conversion check!";
3740
return odbc_internal::StatusRecord{
3841
SQLStates::k_HY000(), "Invalid datatypes for conversion check!"};
3942
}
@@ -54,6 +57,7 @@ inline odbc_internal::StatusRecord CheckLimitsArithmetic(SrcType value) {
5457
static_cast<double>(value) <=
5558
static_cast<double>(std::numeric_limits<DestType>::max());
5659
if (!status) {
60+
LOG(ERROR) << "CheckLimitsArithmetic::Numeric value out of range";
5761
return StatusRecord{SQLStates::k_22003(), "Numeric value out of range"};
5862
}
5963

@@ -63,6 +67,7 @@ inline odbc_internal::StatusRecord CheckLimitsArithmetic(SrcType value) {
6367
bool status =
6468
(value == static_cast<DestType>(value)); // Check for truncation
6569
if (!status) {
70+
LOG(WARNING) << "CheckLimitsArithmetic::Fractional truncation";
6671
return StatusRecord{SQLStates::k_01S07(), "Fractional truncation"};
6772
}
6873
}
@@ -75,6 +80,8 @@ inline odbc_internal::StatusRecord ConvertFromArithmeticDSValue(
7580
using odbc_internal::SQLStates;
7681
using odbc_internal::StatusRecord;
7782
if (!std::is_arithmetic_v<SrcType>) {
83+
LOG(ERROR) << "ConvertFromArithmeticDSValue::Invalid datatypes for "
84+
"conversion check!";
7885
return StatusRecord{SQLStates::k_HY000(),
7986
"Invalid datatypes for conversion check!"};
8087
}
@@ -103,6 +110,9 @@ inline odbc_internal::StatusRecord ConvertFromArithmeticDSValue(
103110
*res_len = sizeof(SQLREAL);
104111
}
105112
}
113+
if (!status_record.ok())
114+
LOG(ERROR) << "ConvertFromArithmeticDSValue::CheckLimitsArithmetic:: "
115+
<< status_record.message;
106116
return status_record;
107117
}
108118
case SQL_C_DOUBLE: {
@@ -117,6 +127,9 @@ inline odbc_internal::StatusRecord ConvertFromArithmeticDSValue(
117127
*res_len = sizeof(SQLDOUBLE);
118128
}
119129
}
130+
if (!status_record.ok())
131+
LOG(ERROR) << "ConvertFromArithmeticDSValue::CheckLimitsArithmetic:: "
132+
<< status_record.message;
120133
return status_record;
121134
}
122135
case SQL_C_SBIGINT: {
@@ -131,6 +144,9 @@ inline odbc_internal::StatusRecord ConvertFromArithmeticDSValue(
131144
*res_len = sizeof(SQLBIGINT);
132145
}
133146
}
147+
if (!status_record.ok())
148+
LOG(ERROR) << "ConvertFromArithmeticDSValue::CheckLimitsArithmetic:: "
149+
<< status_record.message;
134150
return status_record;
135151
}
136152
case SQL_C_UBIGINT: {
@@ -145,6 +161,9 @@ inline odbc_internal::StatusRecord ConvertFromArithmeticDSValue(
145161
*res_len = sizeof(SQLUBIGINT);
146162
}
147163
}
164+
if (!status_record.ok())
165+
LOG(ERROR) << "ConvertFromArithmeticDSValue::CheckLimitsArithmetic:: "
166+
<< status_record.message;
148167
return status_record;
149168
}
150169
case SQL_C_SSHORT: {
@@ -159,6 +178,9 @@ inline odbc_internal::StatusRecord ConvertFromArithmeticDSValue(
159178
*res_len = sizeof(SQLSMALLINT);
160179
}
161180
}
181+
if (!status_record.ok())
182+
LOG(ERROR) << "ConvertFromArithmeticDSValue::CheckLimitsArithmetic:: "
183+
<< status_record.message;
162184
return status_record;
163185
}
164186
case SQL_C_USHORT: {
@@ -174,6 +196,9 @@ inline odbc_internal::StatusRecord ConvertFromArithmeticDSValue(
174196
*res_len = sizeof(SQLUSMALLINT);
175197
}
176198
}
199+
if (!status_record.ok())
200+
LOG(ERROR) << "ConvertFromArithmeticDSValue::CheckLimitsArithmetic:: "
201+
<< status_record.message;
177202
return status_record;
178203
}
179204
case SQL_C_LONG:
@@ -189,6 +214,9 @@ inline odbc_internal::StatusRecord ConvertFromArithmeticDSValue(
189214
*res_len = sizeof(SQLINTEGER);
190215
}
191216
}
217+
if (!status_record.ok())
218+
LOG(ERROR) << "ConvertFromArithmeticDSValue::CheckLimitsArithmetic:: "
219+
<< status_record.message;
192220
return status_record;
193221
}
194222
case SQL_C_ULONG: {
@@ -203,13 +231,19 @@ inline odbc_internal::StatusRecord ConvertFromArithmeticDSValue(
203231
*res_len = sizeof(SQLUINTEGER);
204232
}
205233
}
234+
if (!status_record.ok())
235+
LOG(ERROR) << "ConvertFromArithmeticDSValue::CheckLimitsArithmetic:: "
236+
<< status_record.message;
206237
return status_record;
207238
}
208239
case SQL_C_CHAR: {
209240
std::string str = std::to_string(src_val);
210241
StatusRecord status_record =
211242
StringValueToOutputBufferResponse(str.c_str(), dest_data);
212243
if (status_record.sql_state == SQLStates::k_01004()) {
244+
LOG(ERROR)
245+
<< "ConvertFromArithmeticDSValue::"
246+
"StringValueToOutputBufferResponse:: Numeric value out of range";
213247
return StatusRecord{SQLStates::k_22003(), "Numeric value out of range"};
214248
}
215249
return status_record;
@@ -220,6 +254,8 @@ inline odbc_internal::StatusRecord ConvertFromArithmeticDSValue(
220254
*dest_val = static_cast<SQLCHAR>(src_val);
221255
return StatusRecord::Ok();
222256
}
257+
LOG(ERROR) << "ConvertFromArithmeticDSValue::Numeric value out of range "
258+
"for BIT type";
223259
return StatusRecord{SQLStates::k_22003(), "Numeric value out of range"};
224260
}
225261
case SQL_C_SHORT: {
@@ -234,6 +270,9 @@ inline odbc_internal::StatusRecord ConvertFromArithmeticDSValue(
234270
*res_len = sizeof(SQLSMALLINT);
235271
}
236272
}
273+
if (!status_record.ok())
274+
LOG(ERROR) << "ConvertFromArithmeticDSValue::CheckLimitsArithmetic:: "
275+
<< status_record.message;
237276
return status_record;
238277
}
239278
case SQL_WCHAR: {
@@ -245,6 +284,8 @@ inline odbc_internal::StatusRecord ConvertFromArithmeticDSValue(
245284
wstr.GetValue(), dest_data.buf, dest_data.buflen, src_len,
246285
dest_data.buflen, dest_data.result_len);
247286
if (status_record.sql_state == SQLStates::k_01004()) {
287+
LOG(ERROR) << "ConvertFromArithmeticDSValue::"
288+
"WStrToOutputBufferResponse:: Numeric value out of range";
248289
return StatusRecord{SQLStates::k_22003(), "Numeric value out of range"};
249290
}
250291
return status_record;
@@ -262,6 +303,8 @@ inline odbc_internal::StatusRecord ConvertFromArithmeticDSValue(
262303
abs_val >>= 8;
263304
}
264305
if (abs_val > 0) {
306+
LOG(ERROR) << "ConvertFromArithmeticDSValue::Numeric value out of "
307+
"range for NUMERIC type";
265308
return StatusRecord{SQLStates::k_22003(), "Numeric value out of range"};
266309
}
267310
if (res_len) {
@@ -270,6 +313,9 @@ inline odbc_internal::StatusRecord ConvertFromArithmeticDSValue(
270313
return StatusRecord::Ok();
271314
}
272315
default: {
316+
LOG(WARNING) << "ConvertFromArithmeticDSValue::Conversion is unsupported "
317+
"for C-type: "
318+
<< dest_type;
273319
return StatusRecord{SQLStates::k_HY000(), "Conversion is unsupported"};
274320
}
275321
}
@@ -289,11 +335,14 @@ inline odbc_internal::StatusRecordOr<SQLDOUBLE> ConvertToDouble(
289335

290336
if (endptr == str.c_str() || *endptr != '\0' || errno == ERANGE) {
291337
// Conversion failed or overflow/underflow occurred
338+
LOG(ERROR) << "ConvertToDouble::Invalid conversion from string: " << str;
292339
return StatusRecord{SQLStates::k_HY000(), "Invalid conversion"};
293340
}
294341

295342
// Check for NaN or infinity
296343
if (!std::isfinite(result)) {
344+
LOG(ERROR) << "ConvertToDouble::Value is NaN or infinity for string: "
345+
<< str;
297346
return StatusRecord{SQLStates::k_HY000(), "Value is NaN"};
298347
}
299348
return result;

0 commit comments

Comments
 (0)