@@ -34,6 +34,46 @@ std::string GetDriverName() {
3434#endif // _WIN32
3535}
3636
37+ void UpdateTraceConfig (std::string const & odbc_trace_config,
38+ std::string const & log_path,
39+ std::string const & log_level) {
40+ // Ensure parent directory exists
41+ fs::create_directories (fs::path (odbc_trace_config).parent_path ());
42+ std::unordered_map<std::string, std::string> kv;
43+ std::string line;
44+
45+ if (fs::exists (odbc_trace_config)) {
46+ std::ifstream input (odbc_trace_config);
47+ ASSERT_TRUE (input.is_open ());
48+
49+ while (std::getline (input, line)) {
50+ if (line == " [Driver]" || line.empty ()) {
51+ continue ;
52+ }
53+ auto pos = line.find (' =' );
54+ if (pos != std::string::npos) {
55+ std::string key = line.substr (0 , pos);
56+ std::string val = line.substr (pos + 1 );
57+ kv[key] = val;
58+ }
59+ }
60+ input.close ();
61+ }
62+
63+ // Update trace config
64+ kv[" LogPath" ] = log_path;
65+ kv[" LogLevel" ] = log_level;
66+
67+ std::ofstream output (odbc_trace_config, std::ios::trunc);
68+ ASSERT_TRUE (output.is_open ());
69+
70+ output << " [Driver]\n " ;
71+ for (auto const & [k, v] : kv) {
72+ output << k << " =" << v << " \n " ;
73+ }
74+ output.close ();
75+ }
76+
3777TEST (SQLGetInfo, CheckPositionalUpdate) {
3878 auto conn = std::make_shared<ODBCHandles>();
3979 EXPECT_EQ (Connect (kDefaultConnectionString , conn), SQL_SUCCESS );
@@ -1570,15 +1610,33 @@ TEST(SQLGetFunctionsInternal,
15701610}
15711611
15721612TEST (ConnectionTest, CheckTraceLogFileExist) {
1613+ std::string log_path;
1614+ std::string log_file;
1615+
15731616#ifdef _WIN32
1574- std::string log_path = " C:\\ b" ;
1575- std::string log_file = log_path + " \\ odbcdriverforbigquery_0.log" ;
1576- #else
1577- std::string log_path = " /tmp" ;
1578- std::string log_file = log_path + " /odbcdriverforbigquery_0.log" ;
1579- #endif // _WIN32
1617+ log_path = " C:\\ b" ;
1618+ log_file = log_path + " \\ odbcdriverforbigquery_0.log" ;
1619+ auto conn_str =
1620+ kDefaultConnectionString + " ;LogPath=" + log_path + " ;LogLevel=3" ;
1621+ #elif defined(__APPLE__)
1622+ log_path = " /tmp" ;
1623+ log_file = log_path + " /odbcdriverforbigquery_0.log" ;
15801624 auto conn_str =
15811625 kDefaultConnectionString + " ;LogPath=" + log_path + " ;LogLevel=3" ;
1626+ #else
1627+ log_path = " /tmp" ;
1628+ log_file = log_path + " /odbcdriverforbigquery_0.log" ;
1629+
1630+ auto odbc_ini = google::cloud::internal::GetEnv (" GOOGLEBIGQUERYODBCINI" );
1631+ auto odbc_ini_path = odbc_ini.value_or (" " );
1632+ UpdateTraceConfig (odbc_ini_path, log_path, " 3" );
1633+ auto const & conn_str = kDefaultConnectionString ;
1634+ #endif /* _WIN32 */
1635+
1636+ // Remove existing file
1637+ if (fs::exists (log_file)) {
1638+ fs::remove (log_file);
1639+ }
15821640
15831641 auto conn = std::make_shared<ODBCHandles>();
15841642 EXPECT_EQ (Connect (conn_str, conn), SQL_SUCCESS );
@@ -1601,6 +1659,11 @@ TEST(ConnectionTest, CheckTraceLogFileExist) {
16011659 auto contains_text =
16021660 content.find (" SQLFreeHandle:: DBC handle is free" ) != std::string::npos;
16031661 EXPECT_TRUE (contains_text);
1662+
1663+ #if !defined(_WIN32) && !defined(__APPLE__)
1664+ // Disable tracing for non windows
1665+ UpdateTraceConfig (odbc_ini_path, log_path, " 0" );
1666+ #endif /* defined(_WIN32) || defined(__APPLE__) */
16041667}
16051668
16061669#endif // BQ_DRIVER_INTEGRATION_TESTS
0 commit comments