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