Skip to content

Commit 881f900

Browse files
authored
Merge pull request #4 from bpintea/feature/handle_logging
improve logging configuration and usage
2 parents 3de5728 + c8e543d commit 881f900

15 files changed

+1229
-909
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ if (${WIN32})
5959
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Ze")
6060

6161
if (${IS_UNICODE})
62-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DUNICODE")
62+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DUNICODE /D_UNICODE")
6363
endif (${IS_UNICODE})
6464
# set the version
6565
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DDRV_VER_MAJOR=${DRV_VER_MAJOR}")

build.bat

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ REM cls
66

77
SET ARG="%*"
88
SET SRC_PATH=%~dp0
9-
9+
call:SET_TEMP
1010

1111
REM 32/64 bit argument needs to stay on top, before setting LIBCURL path.
1212
REM presence of '32' or '64': set the Bits/Target ARCHhitecture
@@ -27,28 +27,19 @@ REM
2727
if "%BUILD_DIR%" == "" (
2828
SET BUILD_DIR=%SRC_PATH%\builds
2929
)
30-
if "%LOGGING_DIR%" == "" (
31-
if exist %USERPROFILE%\AppData\Local\Temp\ (
32-
SET LOGGING_DIR=%USERPROFILE%\AppData\Local\Temp\
33-
) else (
34-
SET LOGGING_DIR="%USERPROFILE%\Local Settings\Temp\"
35-
)
30+
if not "%ESODBC_LOG_DIR%" == "" (
31+
for /f "tokens=1 delims=?" %%a in ("%ESODBC_LOG_DIR%") do set LOGGING_DIR=%%a
3632
)
3733
if "%INSTALL_DIR%" == "" (
38-
REM change to lib
39-
if exist %USERPROFILE%\AppData\Local\Temp\ (
40-
SET INSTALL_DIR=%USERPROFILE%\AppData\Local\Temp
41-
) else (
42-
SET INSTALL_DIR="%USERPROFILE%\Local Settings\Temp"
43-
)
34+
set INSTALL_DIR=%TEMP%
4435
)
4536

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

5041
if "%CMAKE_BIN_PATH%" == "" (
51-
SET CMAKE_BIN_PATH="C:\Program Files\CMake\bin"
42+
set CMAKE_BIN_PATH="C:\Program Files\CMake\bin"
5243
)
5344

5445

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

113-
REM presence of 'trunclogs': invoke TRUNCLOGS "function"
114-
if /i not _%ARG:trunclogs=% == _%ARG% (
115-
call:TRUNCLOGS
104+
REM presence of 'clearlogs': invoke CLEARLOGS "function"
105+
if /i not _%ARG:clearlogs=% == _%ARG% (
106+
call:CLEARLOGS
116107
) else (
117-
REM Invoked without 'trunclogs', logs not truncated.
108+
REM Invoked without 'clearlogs', logs not touched.
118109
)
119110

120111
REM presence of 'regadd': call REGADD "function"
@@ -140,6 +131,21 @@ REM
140131
REM "Functions"
141132
REM
142133

134+
REM if TEMP var not set, set it.
135+
:SET_TEMP
136+
if exist %TEMP% goto:eof
137+
set TEMP=%TMP%
138+
if exist %TEMP% goto:eof
139+
set TEMP=%USERPROFILE%\AppData\Local\Temp
140+
if exist %TEMP% goto:eof
141+
set TEMP="%USERPROFILE%\Local Settings\Temp\"
142+
if exist %TEMP% goto:eof
143+
echo WARN: no temporary directory available; using root
144+
set TEMP=\
145+
146+
goto:eof
147+
148+
143149
REM USAGE function: output a usage message
144150
:USAGE
145151
echo Usage: %1 [argument(s^)]
@@ -160,7 +166,7 @@ REM USAGE function: output a usage message
160166
echo (needs Administrator privileges^).
161167
echo regdel : deregister the driver from the registry;
162168
echo (needs Administrator privileges^).
163-
echo trunclogs : truncate the logs (in %LOGGING_DIR%^).
169+
echo clearlogs : clear the logs (in: %LOGGING_DIR%^).
164170
echo.
165171
echo Multiple arguments can be used concurrently.
166172
echo Invoked with no arguments, the script will only initiate a build.
@@ -169,8 +175,8 @@ REM USAGE function: output a usage message
169175
echo List of settable environment variables:
170176
echo BUILD_DIR : path to folder to hold the build files;
171177
echo now set to: `%BUILD_DIR%`.
172-
echo LOGGING_DIR : path to folder holding the logging files;
173-
echo now set to: `%LOGGING_DIR%`.
178+
echo ESODBC_LOG_DIR : path to folder holding the logging files;
179+
echo now set to: `%ESODBC_LOG_DIR%`.
174180
echo INSTALL_DIR : path to folder to hold the built driver;
175181
echo now set to: `%INSTALL_DIR%`.
176182
echo LIBCURL_PATH_BUILD : path to libcurl library;
@@ -288,13 +294,20 @@ REM COPY function: copy DLLs (libcurl, odbc) to the test "install" dir
288294
goto:eof
289295

290296

291-
REM TRUNCLOGS function: empty logs files
292-
:TRUNCLOGS
293-
echo Truncating logs in %LOGGING_DIR%.
294-
echo.>%LOGGING_DIR%\mylog.txt
295-
echo.>%LOGGING_DIR%\SQL32.LOG
296-
echo.>%LOGGING_DIR%\SQL.LOG
297-
297+
REM CLEARLOGS function: empty logs files
298+
:CLEARLOGS
299+
if not "%LOGGING_DIR%" == "" (
300+
echo Clearing logs in %LOGGING_DIR%.
301+
del %LOGGING_DIR%\esodbc_*.log >nul 2>&1
302+
if exist %LOGGING_DIR%\SQL32.LOG (
303+
echo.>%LOGGING_DIR%\SQL32.LOG
304+
)
305+
if exist %LOGGING_DIR%\SQL.LOG (
306+
echo.>%LOGGING_DIR%\SQL.LOG
307+
)
308+
) else (
309+
echo No logging directory to clear set; re-run with 'help' argument.
310+
)
298311
goto:eof
299312

300313

driver/catalogue.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ SQLRETURN EsSQLTablesW(
6666
if (NameLength1 == SQL_NTS) {
6767
cnt_cat = wcslen(catalog);
6868
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_cat) {
69-
ERRSTMT(stmt, "catalog identifier name '" LTPDL "' too long "
69+
ERRH(stmt, "catalog identifier name '" LTPDL "' too long "
7070
"(%d. max=%d).", cnt_cat, catalog, cnt_cat,
7171
ESODBC_MAX_IDENTIFIER_LEN);
7272
RET_HDIAG(stmt, SQL_STATE_HY090, "catalog name too long", 0);
@@ -84,7 +84,7 @@ SQLRETURN EsSQLTablesW(
8484
if (NameLength2 == SQL_NTS) {
8585
cnt_sch = wcslen(schema);
8686
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_sch) {
87-
ERRSTMT(stmt, "schema identifier name '" LTPDL "' too long "
87+
ERRH(stmt, "schema identifier name '" LTPDL "' too long "
8888
"(%d. max=%d).", cnt_sch, schema, cnt_sch,
8989
ESODBC_MAX_IDENTIFIER_LEN);
9090
RET_HDIAG(stmt, SQL_STATE_HY090, "schema name too long", 0);
@@ -100,7 +100,7 @@ SQLRETURN EsSQLTablesW(
100100
/* TODO: server support needed for sch. name filtering */
101101
if (cnt_sch && wszmemcmp(schema, MK_WPTR(SQL_ALL_SCHEMAS),
102102
(long)cnt_sch)) {
103-
ERR("filtering by schemas is not supported.");
103+
ERRH(stmt, "filtering by schemas is not supported.");
104104
RET_HDIAG(stmt, SQL_STATE_IM001, "schema filtering not supported", 0);
105105
}
106106

@@ -110,7 +110,7 @@ SQLRETURN EsSQLTablesW(
110110
if (NameLength3 == SQL_NTS) {
111111
cnt_tab = wcslen(table);
112112
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_tab) {
113-
ERRSTMT(stmt, "table identifier name '" LTPDL "' too long "
113+
ERRH(stmt, "table identifier name '" LTPDL "' too long "
114114
"(%d. max=%d).", cnt_tab, table, cnt_tab,
115115
ESODBC_MAX_IDENTIFIER_LEN);
116116
RET_HDIAG(stmt, SQL_STATE_HY090, "table name too long", 0);
@@ -133,7 +133,7 @@ SQLRETURN EsSQLTablesW(
133133
pos = swprintf(wbuf, sizeof(wbuf)/sizeof(wbuf[0]), SQL_TABLES,
134134
(int)cnt_cat, catalog, (int)cnt_tab, table);
135135
if (pos <= 0) {
136-
ERRSTMT(stmt, "failed to print 'tables' catalog SQL.");
136+
ERRH(stmt, "failed to print 'tables' catalog SQL.");
137137
RET_HDIAGS(stmt, SQL_STATE_HY000);
138138
}
139139

@@ -175,7 +175,7 @@ SQLRETURN EsSQLColumnsW
175175
if (cchCatalogName == SQL_NTS) {
176176
cnt_cat = wcslen(catalog);
177177
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_cat) {
178-
ERRSTMT(stmt, "catalog identifier name '" LTPDL "' too long "
178+
ERRH(stmt, "catalog identifier name '" LTPDL "' too long "
179179
"(%d. max=%d).", cnt_cat, catalog, cnt_cat,
180180
ESODBC_MAX_IDENTIFIER_LEN);
181181
RET_HDIAG(stmt, SQL_STATE_HY090, "catalog name too long", 0);
@@ -192,7 +192,7 @@ SQLRETURN EsSQLColumnsW
192192
if (cchSchemaName == SQL_NTS) {
193193
cnt_sch = wcslen(schema);
194194
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_sch) {
195-
ERRSTMT(stmt, "schema identifier name '" LTPDL "' too long "
195+
ERRH(stmt, "schema identifier name '" LTPDL "' too long "
196196
"(%d. max=%d).", cnt_sch, schema, cnt_sch,
197197
ESODBC_MAX_IDENTIFIER_LEN);
198198
RET_HDIAG(stmt, SQL_STATE_HY090, "schema name too long", 0);
@@ -208,7 +208,7 @@ SQLRETURN EsSQLColumnsW
208208
/* TODO: server support needed for sch. name filtering */
209209
if (cnt_sch && wszmemcmp(schema, MK_WPTR(SQL_ALL_SCHEMAS),
210210
(long)cnt_sch)) {
211-
ERR("filtering by schemas is not supported.");
211+
ERRH(stmt, "filtering by schemas is not supported.");
212212
RET_HDIAG(stmt, SQL_STATE_IM001, "schema filtering not supported", 0);
213213
}
214214

@@ -218,7 +218,7 @@ SQLRETURN EsSQLColumnsW
218218
if (cchTableName == SQL_NTS) {
219219
cnt_tab = wcslen(table);
220220
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_tab) {
221-
ERRSTMT(stmt, "table identifier name '" LTPDL "' too long "
221+
ERRH(stmt, "table identifier name '" LTPDL "' too long "
222222
"(%d. max=%d).", cnt_tab, table, cnt_tab,
223223
ESODBC_MAX_IDENTIFIER_LEN);
224224
RET_HDIAG(stmt, SQL_STATE_HY090, "table name too long", 0);
@@ -236,7 +236,7 @@ SQLRETURN EsSQLColumnsW
236236
if (cchColumnName == SQL_NTS) {
237237
cnt_col = wcslen(column);
238238
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_col) {
239-
ERRSTMT(stmt, "column identifier name '" LTPDL "' too long "
239+
ERRH(stmt, "column identifier name '" LTPDL "' too long "
240240
"(%d. max=%d).", cnt_col, column, cnt_col,
241241
ESODBC_MAX_IDENTIFIER_LEN);
242242
RET_HDIAG(stmt, SQL_STATE_HY090, "column name too long", 0);
@@ -260,7 +260,7 @@ SQLRETURN EsSQLColumnsW
260260
(int)cnt_tab, table, (int)cnt_col, column);
261261
}
262262
if (pos <= 0) {
263-
ERRSTMT(stmt, "failed to print 'columns' catalog SQL.");
263+
ERRH(stmt, "failed to print 'columns' catalog SQL.");
264264
RET_HDIAGS(stmt, SQL_STATE_HY000);
265265
}
266266

@@ -288,7 +288,7 @@ SQLRETURN EsSQLSpecialColumnsW
288288
{
289289
// TODO: is there a "rowid" equivalent: ID uniquely a ROW in the table?
290290
// or unique indexes equivalents
291-
WARN("no special columns available.");
291+
WARNH(hstmt, "no special columns available.");
292292
STMT_FORCE_NODATA(STMH(hstmt));
293293
return SQL_SUCCESS;
294294
}
@@ -309,7 +309,7 @@ SQLRETURN EsSQLForeignKeysW(
309309
_In_reads_opt_(cchFkTableName) SQLWCHAR* szFkTableName,
310310
SQLSMALLINT cchFkTableName)
311311
{
312-
WARN("no foreign keys supported.");
312+
WARNH(hstmt, "no foreign keys supported.");
313313
STMT_FORCE_NODATA(STMH(hstmt));
314314
return SQL_SUCCESS;
315315
}
@@ -323,7 +323,7 @@ SQLRETURN SQL_API EsSQLPrimaryKeysW(
323323
_In_reads_opt_(cchTableName) SQLWCHAR* szTableName,
324324
SQLSMALLINT cchTableName)
325325
{
326-
WARN("no primary keys supported.");
326+
WARNH(hstmt, "no primary keys supported.");
327327
STMT_FORCE_NODATA(STMH(hstmt));
328328
return SQL_SUCCESS;
329329
}

0 commit comments

Comments
 (0)