@@ -35,6 +35,46 @@ std::string GetDriverName() {
3535#endif // _WIN32
3636}
3737
38+ void UpdateTraceConfig (std::string const & odbc_trace_config,
39+ std::string const & log_path,
40+ std::string const & log_level) {
41+ // Ensure parent directory exists
42+ fs::create_directories (fs::path (odbc_trace_config).parent_path ());
43+ std::unordered_map<std::string, std::string> kv;
44+ std::string line;
45+
46+ if (fs::exists (odbc_trace_config)) {
47+ std::ifstream input (odbc_trace_config);
48+ ASSERT_TRUE (input.is_open ());
49+
50+ while (std::getline (input, line)) {
51+ if (line == " [Driver]" || line.empty ()) {
52+ continue ;
53+ }
54+ auto pos = line.find (' =' );
55+ if (pos != std::string::npos) {
56+ std::string key = line.substr (0 , pos);
57+ std::string val = line.substr (pos + 1 );
58+ kv[key] = val;
59+ }
60+ }
61+ input.close ();
62+ }
63+
64+ // Update trace config
65+ kv[" LogPath" ] = log_path;
66+ kv[" LogLevel" ] = log_level;
67+
68+ std::ofstream output (odbc_trace_config, std::ios::trunc);
69+ ASSERT_TRUE (output.is_open ());
70+
71+ output << " [Driver]\n " ;
72+ for (auto const & [k, v] : kv) {
73+ output << k << " =" << v << " \n " ;
74+ }
75+ output.close ();
76+ }
77+
3878TEST (SQLGetInfo, CheckPositionalUpdate) {
3979 auto conn = std::make_shared<ODBCHandles>();
4080 EXPECT_EQ (Connect (kDefaultConnectionString , conn), SQL_SUCCESS );
@@ -1571,19 +1611,33 @@ TEST(SQLGetFunctionsInternal,
15711611}
15721612
15731613TEST (ConnectionTest, CheckTraceLogFileExist) {
1614+ std::string log_path;
1615+ std::string log_file;
1616+
15741617#ifdef _WIN32
1575- std::string log_path = " C:\\ b" ;
1576- std::string log_file = log_path + " \\ odbcdriverforbigquery_0.log" ;
1618+ log_path = " C:\\ b" ;
1619+ log_file = log_path + " \\ odbcdriverforbigquery_0.log" ;
1620+ auto conn_str =
1621+ kDefaultConnectionString + " ;LogPath=" + log_path + " ;LogLevel=3" ;
1622+ #elif defined(__APPLE__)
1623+ log_path = " /tmp" ;
1624+ log_file = log_path + " /odbcdriverforbigquery_0.log" ;
1625+ auto conn_str =
1626+ kDefaultConnectionString + " ;LogPath=" + log_path + " ;LogLevel=3" ;
15771627#else
1578- std::string log_path = " /tmp" ;
1579- std::string log_file = log_path + " /odbcdriverforbigquery_0.log" ;
1580- #endif // _WIN32
1581- // Delete the log file if it already exists
1628+ log_path = " /tmp" ;
1629+ log_file = log_path + " /odbcdriverforbigquery_0.log" ;
1630+
1631+ auto odbc_ini = google::cloud::internal::GetEnv (" GOOGLEBIGQUERYODBCINI" );
1632+ auto odbc_ini_path = odbc_ini.value_or (" " );
1633+ UpdateTraceConfig (odbc_ini_path, log_path, " 3" );
1634+ auto const & conn_str = kDefaultConnectionString ;
1635+ #endif /* _WIN32 */
1636+
1637+ // Remove existing file
15821638 if (fs::exists (log_file)) {
15831639 fs::remove (log_file);
15841640 }
1585- auto conn_str = kDefaultConnectionString + " ;LogPath=" + log_path +
1586- " ;LogLevel=3;LogFileCount=1;LogFileSize=1;" ;
15871641
15881642 auto conn = std::make_shared<ODBCHandles>();
15891643 EXPECT_EQ (Connect (conn_str, conn), SQL_SUCCESS );
@@ -1607,20 +1661,10 @@ TEST(ConnectionTest, CheckTraceLogFileExist) {
16071661 content.find (" SQLFreeHandle:: DBC handle is free" ) != std::string::npos;
16081662 EXPECT_TRUE (contains_text);
16091663
1610- // validate log file count and log file size
1611- int log_count = 0 ;
1612- for (auto const & entry : fs::directory_iterator (log_path)) {
1613- auto path = entry.path ();
1614- if (path.extension () == " .log" ) {
1615- auto filename = path.filename ().string ();
1616- if (filename.rfind (" odbcdriverforbigquery" ) == 0 ) {
1617- ++log_count;
1618- auto const size = fs::file_size (entry.path ());
1619- EXPECT_LE (size, 1 * 1024 * 1024 );
1620- }
1621- }
1622- }
1623- EXPECT_LE (log_count, 1 );
1664+ #if !defined(_WIN32) && !defined(__APPLE__)
1665+ // Disable tracing for non windows
1666+ UpdateTraceConfig (odbc_ini_path, log_path, " 0" );
1667+ #endif /* defined(_WIN32) || defined(__APPLE__) */
16241668}
16251669
16261670#endif // BQ_DRIVER_INTEGRATION_TESTS
0 commit comments