lidavidm commented on code in PR #1915:
URL: https://github.com/apache/arrow-adbc/pull/1915#discussion_r1634299651


##########
dev/bench/odbc/main.cc:
##########
@@ -0,0 +1,186 @@
+#include <sql.h>
+#include <sqlext.h>
+#include <sqltypes.h>
+#include <stdio.h>
+#include <string.h>
+#include <chrono>
+#include <fstream>
+#include <iostream>
+#include <map>
+#include <string>
+#include <vector>
+
+#define ERRMSG_LEN 200
+
+SQLINTEGER checkError(SQLRETURN rc, SQLSMALLINT handleType, SQLHANDLE handle,
+                      SQLWCHAR* errmsg) {
+  SQLRETURN retcode = SQL_SUCCESS;
+
+  SQLSMALLINT errNum = 1;
+  SQLWCHAR sqlState[10];
+  SQLINTEGER nativeError;
+  SQLWCHAR errMsg[ERRMSG_LEN];
+  SQLSMALLINT textLengthPtr;
+
+  if ((rc != SQL_SUCCESS) && (rc != SQL_SUCCESS_WITH_INFO) && (rc != 
SQL_NO_DATA)) {
+    SQLLEN numRecs = 0;
+    SQLGetDiagField(SQL_HANDLE_STMT, handle, 0, SQL_DIAG_NUMBER, &numRecs, 0, 
0);
+    while (retcode != SQL_NO_DATA) {
+      retcode = SQLGetDiagRecW(handleType, handle, errNum, sqlState, 
&nativeError, errMsg,
+                               ERRMSG_LEN, &textLengthPtr);
+
+      if (retcode == SQL_INVALID_HANDLE) {
+        std::cerr << "checkError function was called with an invalid handle!!"
+                  << std::endl;
+        return 1;
+      }
+
+      if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO)) {
+        wprintf(L"ERROR: %d: %ls : %ls\n", nativeError, sqlState, errMsg);
+      }
+
+      errNum++;
+    }
+
+    wprintf(L"%ls\n", errmsg);
+    return 1;
+  }
+
+  return 0;
+}
+
+#define CHECK_OK(EXPR, ERROR)                                        \
+  do {                                                               \
+    auto ret = (EXPR);                                               \
+    if (checkError(ret, SQL_HANDLE_DBC, dbc, (SQLWCHAR*)L##ERROR)) { \
+      exit(1);                                                       \
+    }                                                                \
+  } while (0)
+
+int main(int argc, char** argv) {
+  SQLHENV env;
+  SQLHDBC dbc;
+  SQLHSTMT stmt;
+  SQLHSTMT stmt1;
+
+  std::string dsn(argv[0]);
+
+  SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
+  // we want ODBC3 support, set env handle
+  SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3_80, 0);
+  // allocate connection handle
+  SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);
+
+  // connect to the DSN using dbc handle
+  CHECK_OK(SQLDriverConnect(dbc, nullptr, (SQLCHAR*)(dsn.c_str()), SQL_NTS, 
nullptr, 0,
+                            nullptr, SQL_DRIVER_COMPLETE),
+           "Error -- Driver Connect failed");
+
+  std::ofstream timing_output("odbc_perf_record");
+
+  for (size_t iter = 0; iter < 100; iter++) {
+    CHECK_OK(SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt),
+             "Error -- Statement handle alloc failed");
+
+    const auto start{std::chrono::steady_clock::now()};
+    CHECK_OK(SQLExecDirect(
+                 stmt,
+                 (SQLCHAR*)"SELECT * FROM 
SNOWFLAKE_SAMPLE_DATA.TPCH_SF1000.LINEITEM "

Review Comment:
   nit: can we avoid C-style casts?



##########
dev/bench/odbc/CMakeLists.txt:
##########
@@ -0,0 +1,28 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+cmake_minimum_required(VERSION 3.21)
+project(odbcbench LANGUAGES C CXX)
+set(CMAKE_CXX_STANDARD 20)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+find_package(ODBC)
+add_executable(odbcbench main.cc)
+target_link_libraries(odbcbench ODBC::ODBC)
+set_target_properties(odbcbench
+PROPERTIES BUILD_RPATH "\$ORIGIN"
+           INSTALL_RPATH "\$ORIGIN")

Review Comment:
   Can we run pre-commit over everything?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to