Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve logging configuration and usage #4

Merged
merged 12 commits into from
Apr 24, 2018
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if (${WIN32})
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Ze")

if (${IS_UNICODE})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DUNICODE")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DUNICODE /D_UNICODE")
endif (${IS_UNICODE})
# set the version
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DDRV_VER_MAJOR=${DRV_VER_MAJOR}")
Expand Down
71 changes: 42 additions & 29 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ REM cls

SET ARG="%*"
SET SRC_PATH=%~dp0

call:SET_TEMP

REM 32/64 bit argument needs to stay on top, before setting LIBCURL path.
REM presence of '32' or '64': set the Bits/Target ARCHhitecture
Expand All @@ -27,28 +27,19 @@ REM
if "%BUILD_DIR%" == "" (
SET BUILD_DIR=%SRC_PATH%\builds
)
if "%LOGGING_DIR%" == "" (
if exist %USERPROFILE%\AppData\Local\Temp\ (
SET LOGGING_DIR=%USERPROFILE%\AppData\Local\Temp\
) else (
SET LOGGING_DIR="%USERPROFILE%\Local Settings\Temp\"
)
if not "%ESODBC_LOG_DIR%" == "" (
for /f "tokens=1 delims=?" %%a in ("%ESODBC_LOG_DIR%") do set LOGGING_DIR=%%a
)
if "%INSTALL_DIR%" == "" (
REM change to lib
if exist %USERPROFILE%\AppData\Local\Temp\ (
SET INSTALL_DIR=%USERPROFILE%\AppData\Local\Temp
) else (
SET INSTALL_DIR="%USERPROFILE%\Local Settings\Temp"
)
set INSTALL_DIR=%TEMP%
)

if "%LIBCURL_PATH_BUILD%" == "" (
SET LIBCURL_PATH_BUILD=%SRC_PATH%\libs\curl\builds\libcurl-vc-!TARCH!-release-dll-ipv6-sspi-winssl
set LIBCURL_PATH_BUILD=%SRC_PATH%\libs\curl\builds\libcurl-vc-!TARCH!-release-dll-ipv6-sspi-winssl
)

if "%CMAKE_BIN_PATH%" == "" (
SET CMAKE_BIN_PATH="C:\Program Files\CMake\bin"
set CMAKE_BIN_PATH="C:\Program Files\CMake\bin"
)


Expand Down Expand Up @@ -110,11 +101,11 @@ if /i not _%ARG:copy=% == _%ARG% (
REM Invoked without 'copy': DLLs test installation skipped.
)

REM presence of 'trunclogs': invoke TRUNCLOGS "function"
if /i not _%ARG:trunclogs=% == _%ARG% (
call:TRUNCLOGS
REM presence of 'clearlogs': invoke CLEARLOGS "function"
if /i not _%ARG:clearlogs=% == _%ARG% (
call:CLEARLOGS
) else (
REM Invoked without 'trunclogs', logs not truncated.
REM Invoked without 'clearlogs', logs not touched.
)

REM presence of 'regadd': call REGADD "function"
Expand All @@ -140,6 +131,21 @@ REM
REM "Functions"
REM

REM if TEMP var not set, set it.
:SET_TEMP
if exist %TEMP% goto:eof
set TEMP=%TMP%
if exist %TEMP% goto:eof
set TEMP=%USERPROFILE%\AppData\Local\Temp
if exist %TEMP% goto:eof
set TEMP="%USERPROFILE%\Local Settings\Temp\"
if exist %TEMP% goto:eof
echo WARN: no temporary directory available; using root
set TEMP=\

goto:eof


REM USAGE function: output a usage message
:USAGE
echo Usage: %1 [argument(s^)]
Expand All @@ -160,7 +166,7 @@ REM USAGE function: output a usage message
echo (needs Administrator privileges^).
echo regdel : deregister the driver from the registry;
echo (needs Administrator privileges^).
echo trunclogs : truncate the logs (in %LOGGING_DIR%^).
echo clearlogs : clear the logs (in: %LOGGING_DIR%^).
echo.
echo Multiple arguments can be used concurrently.
echo Invoked with no arguments, the script will only initiate a build.
Expand All @@ -169,8 +175,8 @@ REM USAGE function: output a usage message
echo List of settable environment variables:
echo BUILD_DIR : path to folder to hold the build files;
echo now set to: `%BUILD_DIR%`.
echo LOGGING_DIR : path to folder holding the logging files;
echo now set to: `%LOGGING_DIR%`.
echo ESODBC_LOG_DIR : path to folder holding the logging files;
echo now set to: `%ESODBC_LOG_DIR%`.
echo INSTALL_DIR : path to folder to hold the built driver;
echo now set to: `%INSTALL_DIR%`.
echo LIBCURL_PATH_BUILD : path to libcurl library;
Expand Down Expand Up @@ -288,13 +294,20 @@ REM COPY function: copy DLLs (libcurl, odbc) to the test "install" dir
goto:eof


REM TRUNCLOGS function: empty logs files
:TRUNCLOGS
echo Truncating logs in %LOGGING_DIR%.
echo.>%LOGGING_DIR%\mylog.txt
echo.>%LOGGING_DIR%\SQL32.LOG
echo.>%LOGGING_DIR%\SQL.LOG

REM CLEARLOGS function: empty logs files
:CLEARLOGS
if not "%LOGGING_DIR%" == "" (
echo Clearing logs in %LOGGING_DIR%.
del %LOGGING_DIR%\esodbc_*.log >nul 2>&1
if exist %LOGGING_DIR%\SQL32.LOG (
echo.>%LOGGING_DIR%\SQL32.LOG
)
if exist %LOGGING_DIR%\SQL.LOG (
echo.>%LOGGING_DIR%\SQL.LOG
)
) else (
echo No logging directory to clear set; re-run with 'help' argument.
)
goto:eof


Expand Down
28 changes: 14 additions & 14 deletions driver/catalogue.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ SQLRETURN EsSQLTablesW(
if (NameLength1 == SQL_NTS) {
cnt_cat = wcslen(catalog);
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_cat) {
ERRSTMT(stmt, "catalog identifier name '" LTPDL "' too long "
ERRH(stmt, "catalog identifier name '" LTPDL "' too long "
"(%d. max=%d).", cnt_cat, catalog, cnt_cat,
ESODBC_MAX_IDENTIFIER_LEN);
RET_HDIAG(stmt, SQL_STATE_HY090, "catalog name too long", 0);
Expand All @@ -84,7 +84,7 @@ SQLRETURN EsSQLTablesW(
if (NameLength2 == SQL_NTS) {
cnt_sch = wcslen(schema);
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_sch) {
ERRSTMT(stmt, "schema identifier name '" LTPDL "' too long "
ERRH(stmt, "schema identifier name '" LTPDL "' too long "
"(%d. max=%d).", cnt_sch, schema, cnt_sch,
ESODBC_MAX_IDENTIFIER_LEN);
RET_HDIAG(stmt, SQL_STATE_HY090, "schema name too long", 0);
Expand All @@ -100,7 +100,7 @@ SQLRETURN EsSQLTablesW(
/* TODO: server support needed for sch. name filtering */
if (cnt_sch && wszmemcmp(schema, MK_WPTR(SQL_ALL_SCHEMAS),
(long)cnt_sch)) {
ERR("filtering by schemas is not supported.");
ERRH(stmt, "filtering by schemas is not supported.");
RET_HDIAG(stmt, SQL_STATE_IM001, "schema filtering not supported", 0);
}

Expand All @@ -110,7 +110,7 @@ SQLRETURN EsSQLTablesW(
if (NameLength3 == SQL_NTS) {
cnt_tab = wcslen(table);
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_tab) {
ERRSTMT(stmt, "table identifier name '" LTPDL "' too long "
ERRH(stmt, "table identifier name '" LTPDL "' too long "
"(%d. max=%d).", cnt_tab, table, cnt_tab,
ESODBC_MAX_IDENTIFIER_LEN);
RET_HDIAG(stmt, SQL_STATE_HY090, "table name too long", 0);
Expand All @@ -133,7 +133,7 @@ SQLRETURN EsSQLTablesW(
pos = swprintf(wbuf, sizeof(wbuf)/sizeof(wbuf[0]), SQL_TABLES,
(int)cnt_cat, catalog, (int)cnt_tab, table);
if (pos <= 0) {
ERRSTMT(stmt, "failed to print 'tables' catalog SQL.");
ERRH(stmt, "failed to print 'tables' catalog SQL.");
RET_HDIAGS(stmt, SQL_STATE_HY000);
}

Expand Down Expand Up @@ -175,7 +175,7 @@ SQLRETURN EsSQLColumnsW
if (cchCatalogName == SQL_NTS) {
cnt_cat = wcslen(catalog);
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_cat) {
ERRSTMT(stmt, "catalog identifier name '" LTPDL "' too long "
ERRH(stmt, "catalog identifier name '" LTPDL "' too long "
"(%d. max=%d).", cnt_cat, catalog, cnt_cat,
ESODBC_MAX_IDENTIFIER_LEN);
RET_HDIAG(stmt, SQL_STATE_HY090, "catalog name too long", 0);
Expand All @@ -192,7 +192,7 @@ SQLRETURN EsSQLColumnsW
if (cchSchemaName == SQL_NTS) {
cnt_sch = wcslen(schema);
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_sch) {
ERRSTMT(stmt, "schema identifier name '" LTPDL "' too long "
ERRH(stmt, "schema identifier name '" LTPDL "' too long "
"(%d. max=%d).", cnt_sch, schema, cnt_sch,
ESODBC_MAX_IDENTIFIER_LEN);
RET_HDIAG(stmt, SQL_STATE_HY090, "schema name too long", 0);
Expand All @@ -208,7 +208,7 @@ SQLRETURN EsSQLColumnsW
/* TODO: server support needed for sch. name filtering */
if (cnt_sch && wszmemcmp(schema, MK_WPTR(SQL_ALL_SCHEMAS),
(long)cnt_sch)) {
ERR("filtering by schemas is not supported.");
ERRH(stmt, "filtering by schemas is not supported.");
RET_HDIAG(stmt, SQL_STATE_IM001, "schema filtering not supported", 0);
}

Expand All @@ -218,7 +218,7 @@ SQLRETURN EsSQLColumnsW
if (cchTableName == SQL_NTS) {
cnt_tab = wcslen(table);
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_tab) {
ERRSTMT(stmt, "table identifier name '" LTPDL "' too long "
ERRH(stmt, "table identifier name '" LTPDL "' too long "
"(%d. max=%d).", cnt_tab, table, cnt_tab,
ESODBC_MAX_IDENTIFIER_LEN);
RET_HDIAG(stmt, SQL_STATE_HY090, "table name too long", 0);
Expand All @@ -236,7 +236,7 @@ SQLRETURN EsSQLColumnsW
if (cchColumnName == SQL_NTS) {
cnt_col = wcslen(column);
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_col) {
ERRSTMT(stmt, "column identifier name '" LTPDL "' too long "
ERRH(stmt, "column identifier name '" LTPDL "' too long "
"(%d. max=%d).", cnt_col, column, cnt_col,
ESODBC_MAX_IDENTIFIER_LEN);
RET_HDIAG(stmt, SQL_STATE_HY090, "column name too long", 0);
Expand All @@ -260,7 +260,7 @@ SQLRETURN EsSQLColumnsW
(int)cnt_tab, table, (int)cnt_col, column);
}
if (pos <= 0) {
ERRSTMT(stmt, "failed to print 'columns' catalog SQL.");
ERRH(stmt, "failed to print 'columns' catalog SQL.");
RET_HDIAGS(stmt, SQL_STATE_HY000);
}

Expand Down Expand Up @@ -288,7 +288,7 @@ SQLRETURN EsSQLSpecialColumnsW
{
// TODO: is there a "rowid" equivalent: ID uniquely a ROW in the table?
// or unique indexes equivalents
WARN("no special columns available.");
WARNH(hstmt, "no special columns available.");
STMT_FORCE_NODATA(STMH(hstmt));
return SQL_SUCCESS;
}
Expand All @@ -309,7 +309,7 @@ SQLRETURN EsSQLForeignKeysW(
_In_reads_opt_(cchFkTableName) SQLWCHAR* szFkTableName,
SQLSMALLINT cchFkTableName)
{
WARN("no foreign keys supported.");
WARNH(hstmt, "no foreign keys supported.");
STMT_FORCE_NODATA(STMH(hstmt));
return SQL_SUCCESS;
}
Expand All @@ -323,7 +323,7 @@ SQLRETURN SQL_API EsSQLPrimaryKeysW(
_In_reads_opt_(cchTableName) SQLWCHAR* szTableName,
SQLSMALLINT cchTableName)
{
WARN("no primary keys supported.");
WARNH(hstmt, "no primary keys supported.");
STMT_FORCE_NODATA(STMH(hstmt));
return SQL_SUCCESS;
}
Expand Down
Loading