Skip to content

Commit 928c116

Browse files
authored
Merge pull request #4 from bpintea/feature/handle_logging
improve logging configuration and usage
2 parents 4af617b + acdd847 commit 928c116

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
@@ -55,7 +55,7 @@ SQLRETURN EsSQLTablesW(
5555
if (NameLength1 == SQL_NTS) {
5656
cnt_cat = wcslen(catalog);
5757
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_cat) {
58-
ERRSTMT(stmt, "catalog identifier name '" LTPDL "' too long "
58+
ERRH(stmt, "catalog identifier name '" LTPDL "' too long "
5959
"(%d. max=%d).", cnt_cat, catalog, cnt_cat,
6060
ESODBC_MAX_IDENTIFIER_LEN);
6161
RET_HDIAG(stmt, SQL_STATE_HY090, "catalog name too long", 0);
@@ -73,7 +73,7 @@ SQLRETURN EsSQLTablesW(
7373
if (NameLength2 == SQL_NTS) {
7474
cnt_sch = wcslen(schema);
7575
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_sch) {
76-
ERRSTMT(stmt, "schema identifier name '" LTPDL "' too long "
76+
ERRH(stmt, "schema identifier name '" LTPDL "' too long "
7777
"(%d. max=%d).", cnt_sch, schema, cnt_sch,
7878
ESODBC_MAX_IDENTIFIER_LEN);
7979
RET_HDIAG(stmt, SQL_STATE_HY090, "schema name too long", 0);
@@ -89,7 +89,7 @@ SQLRETURN EsSQLTablesW(
8989
/* TODO: server support needed for sch. name filtering */
9090
if (cnt_sch && wszmemcmp(schema, MK_WPTR(SQL_ALL_SCHEMAS),
9191
(long)cnt_sch)) {
92-
ERR("filtering by schemas is not supported.");
92+
ERRH(stmt, "filtering by schemas is not supported.");
9393
RET_HDIAG(stmt, SQL_STATE_IM001, "schema filtering not supported", 0);
9494
}
9595

@@ -99,7 +99,7 @@ SQLRETURN EsSQLTablesW(
9999
if (NameLength3 == SQL_NTS) {
100100
cnt_tab = wcslen(table);
101101
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_tab) {
102-
ERRSTMT(stmt, "table identifier name '" LTPDL "' too long "
102+
ERRH(stmt, "table identifier name '" LTPDL "' too long "
103103
"(%d. max=%d).", cnt_tab, table, cnt_tab,
104104
ESODBC_MAX_IDENTIFIER_LEN);
105105
RET_HDIAG(stmt, SQL_STATE_HY090, "table name too long", 0);
@@ -122,7 +122,7 @@ SQLRETURN EsSQLTablesW(
122122
pos = swprintf(wbuf, sizeof(wbuf)/sizeof(wbuf[0]), SQL_TABLES,
123123
(int)cnt_cat, catalog, (int)cnt_tab, table);
124124
if (pos <= 0) {
125-
ERRSTMT(stmt, "failed to print 'tables' catalog SQL.");
125+
ERRH(stmt, "failed to print 'tables' catalog SQL.");
126126
RET_HDIAGS(stmt, SQL_STATE_HY000);
127127
}
128128

@@ -164,7 +164,7 @@ SQLRETURN EsSQLColumnsW
164164
if (cchCatalogName == SQL_NTS) {
165165
cnt_cat = wcslen(catalog);
166166
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_cat) {
167-
ERRSTMT(stmt, "catalog identifier name '" LTPDL "' too long "
167+
ERRH(stmt, "catalog identifier name '" LTPDL "' too long "
168168
"(%d. max=%d).", cnt_cat, catalog, cnt_cat,
169169
ESODBC_MAX_IDENTIFIER_LEN);
170170
RET_HDIAG(stmt, SQL_STATE_HY090, "catalog name too long", 0);
@@ -181,7 +181,7 @@ SQLRETURN EsSQLColumnsW
181181
if (cchSchemaName == SQL_NTS) {
182182
cnt_sch = wcslen(schema);
183183
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_sch) {
184-
ERRSTMT(stmt, "schema identifier name '" LTPDL "' too long "
184+
ERRH(stmt, "schema identifier name '" LTPDL "' too long "
185185
"(%d. max=%d).", cnt_sch, schema, cnt_sch,
186186
ESODBC_MAX_IDENTIFIER_LEN);
187187
RET_HDIAG(stmt, SQL_STATE_HY090, "schema name too long", 0);
@@ -197,7 +197,7 @@ SQLRETURN EsSQLColumnsW
197197
/* TODO: server support needed for sch. name filtering */
198198
if (cnt_sch && wszmemcmp(schema, MK_WPTR(SQL_ALL_SCHEMAS),
199199
(long)cnt_sch)) {
200-
ERR("filtering by schemas is not supported.");
200+
ERRH(stmt, "filtering by schemas is not supported.");
201201
RET_HDIAG(stmt, SQL_STATE_IM001, "schema filtering not supported", 0);
202202
}
203203

@@ -207,7 +207,7 @@ SQLRETURN EsSQLColumnsW
207207
if (cchTableName == SQL_NTS) {
208208
cnt_tab = wcslen(table);
209209
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_tab) {
210-
ERRSTMT(stmt, "table identifier name '" LTPDL "' too long "
210+
ERRH(stmt, "table identifier name '" LTPDL "' too long "
211211
"(%d. max=%d).", cnt_tab, table, cnt_tab,
212212
ESODBC_MAX_IDENTIFIER_LEN);
213213
RET_HDIAG(stmt, SQL_STATE_HY090, "table name too long", 0);
@@ -225,7 +225,7 @@ SQLRETURN EsSQLColumnsW
225225
if (cchColumnName == SQL_NTS) {
226226
cnt_col = wcslen(column);
227227
if (ESODBC_MAX_IDENTIFIER_LEN < cnt_col) {
228-
ERRSTMT(stmt, "column identifier name '" LTPDL "' too long "
228+
ERRH(stmt, "column identifier name '" LTPDL "' too long "
229229
"(%d. max=%d).", cnt_col, column, cnt_col,
230230
ESODBC_MAX_IDENTIFIER_LEN);
231231
RET_HDIAG(stmt, SQL_STATE_HY090, "column name too long", 0);
@@ -249,7 +249,7 @@ SQLRETURN EsSQLColumnsW
249249
(int)cnt_tab, table, (int)cnt_col, column);
250250
}
251251
if (pos <= 0) {
252-
ERRSTMT(stmt, "failed to print 'columns' catalog SQL.");
252+
ERRH(stmt, "failed to print 'columns' catalog SQL.");
253253
RET_HDIAGS(stmt, SQL_STATE_HY000);
254254
}
255255

@@ -277,7 +277,7 @@ SQLRETURN EsSQLSpecialColumnsW
277277
{
278278
// TODO: is there a "rowid" equivalent: ID uniquely a ROW in the table?
279279
// or unique indexes equivalents
280-
WARN("no special columns available.");
280+
WARNH(hstmt, "no special columns available.");
281281
STMT_FORCE_NODATA(STMH(hstmt));
282282
return SQL_SUCCESS;
283283
}
@@ -298,7 +298,7 @@ SQLRETURN EsSQLForeignKeysW(
298298
_In_reads_opt_(cchFkTableName) SQLWCHAR* szFkTableName,
299299
SQLSMALLINT cchFkTableName)
300300
{
301-
WARN("no foreign keys supported.");
301+
WARNH(hstmt, "no foreign keys supported.");
302302
STMT_FORCE_NODATA(STMH(hstmt));
303303
return SQL_SUCCESS;
304304
}
@@ -312,7 +312,7 @@ SQLRETURN SQL_API EsSQLPrimaryKeysW(
312312
_In_reads_opt_(cchTableName) SQLWCHAR* szTableName,
313313
SQLSMALLINT cchTableName)
314314
{
315-
WARN("no primary keys supported.");
315+
WARNH(hstmt, "no primary keys supported.");
316316
STMT_FORCE_NODATA(STMH(hstmt));
317317
return SQL_SUCCESS;
318318
}

0 commit comments

Comments
 (0)