Skip to content

Data conversions: numeric types #9

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

Merged
merged 15 commits into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ if (${WIN32})
# (this will allow RelWithDebInfo buliding and still be able to test it)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /DTEST_API=")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_RELEASE} /DTEST_API=")

# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DNDEBUG")
else (${WIN32})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
endif (${WIN32})
Expand Down
35 changes: 28 additions & 7 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ if /i not [%ARG:type=%] == [%ARG%] (
call:BUILDTYPE
) else (
echo Invoked without 'type', default applied (see usage^).
set MSBUILD_ARGS=/p:Configuration=Debug
set CFG_INTDIR=Debug
)

REM absence of nobuild: invoke BUILD "function";
Expand All @@ -106,9 +108,9 @@ if /i [%ARG:nobuild=%] == [%ARG%] (
echo Invoked with 'nobuild', building skipped.
)

REM presence of 'test': invoke TEST "function"
if /i not [%ARG:test=%] == [%ARG%] (
call:TEST
REM presence of 'test': invoke TESTS "function"
if /i not [%ARG:tests=%] == [%ARG%] (
call:TESTS
) else (
REM Invoked without 'test': tests running skipped.
)
Expand Down Expand Up @@ -237,11 +239,12 @@ REM USAGE function: output a usage message
echo exports : dump the exported symbols in the DLL after - and
echo only if - building the driver.
echo all : build all artifacts (driver and tests^).
echo test : run all the defined tests: invoke the 'all' build,
echo tests : run all the defined tests: invoke the 'all' build,
echo then the 'tests' build.
echo suites : compile and run each test individually, stopping at the
echo first failure; the 'all' or 'test' targets must be
echo built beforehand.
echo suite=S : compile and run one test, S, individually.
echo copy : copy the driver into the test dir (%INSTALL_DIR%^).
echo regadd : register the driver into the registry;
echo (needs Administrator privileges^).
Expand Down Expand Up @@ -387,7 +390,7 @@ REM BUILD function: build various targets
%CMAKE% !CMAKE_ARGS! ..
)

if /i not [%ARG:test=%] == [%ARG%] (
if /i not [%ARG:tests=%] == [%ARG%] (
echo Building all the project (including tests^).
MSBuild ALL_BUILD.vcxproj %MSBUILD_ARGS%
) else if /i not [%ARG:all=%] == [%ARG%] (
Expand All @@ -408,6 +411,24 @@ REM BUILD function: build various targets
goto:eof
)
)
) else if /i not [%ARG:suite==%] == [%ARG%] (
REM cycle through the args, look for 'suite' token and use the
REM follow-up item
set prev=
for %%a in (%ARG:"=%) do (
if /i [!prev!] == [suite] (
set SUITE=%%a
echo Building and running one suite: !SUITE!
echo MSBuild test\%%a.vcxproj %MSBUILD_ARGS%
MSBuild test\%%a.vcxproj %MSBUILD_ARGS%
if not ERRORLEVEL 1 (
test\%CFG_INTDIR%\%%a.exe
)
goto:eof
) else (
set prev=%%a
)
)
) else (
echo Building the driver only.
REM file name expansion, cmd style...
Expand All @@ -420,8 +441,8 @@ REM BUILD function: build various targets

goto:eof

REM TEST function: run the compiled tests
:TEST
REM TESTS function: run the compiled tests
:TESTS
REM if called with nobuild, but test, this will trigger the build
if not exist RUN_TESTS.vcxproj (
call:BUILD
Expand Down
21 changes: 11 additions & 10 deletions driver/catalogue.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ SQLSMALLINT copy_current_catalog(esodbc_dbc_st *dbc, SQLWCHAR *dest,
SQLLEN row_cnt;
SQLLEN ind_len = SQL_NULL_DATA;
SQLWCHAR buff[ESODBC_MAX_IDENTIFIER_LEN];
SQLWCHAR *catalog;
wstr_st catalog;

if (! SQL_SUCCEEDED(EsSQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt))) {
ERRH(dbc, "failed to alloc a statement handle.");
Expand All @@ -76,7 +76,7 @@ SQLSMALLINT copy_current_catalog(esodbc_dbc_st *dbc, SQLWCHAR *dest,
goto end;
} else if (row_cnt <= 0) {
WARNH(stmt, "Elasticsearch returned no current catalog.");
catalog = MK_WPTR(""); /* empty string, it's not quite an error */
catalog = MK_WSTR(""); /* empty string, it's not quite an error */
} else {
DBGH(stmt, "Elasticsearch catalogs rows count: %ld.", row_cnt);
if (1 < row_cnt) {
Expand All @@ -95,18 +95,19 @@ SQLSMALLINT copy_current_catalog(esodbc_dbc_st *dbc, SQLWCHAR *dest,
}
if (ind_len <= 0) {
WARNH(dbc, "NULL catalog received."); /*tho maybe != NULL_DATA */
catalog = MK_WPTR("");
catalog = MK_WSTR("");
} else {
catalog = buff;
DBGH(dbc, "current catalog (first value returned): `" LWPD "`.",
catalog);
catalog = (wstr_st) {
buff, ind_len
};
DBGH(dbc, "current catalog (first value returned): `" LWPDL "`.",
LWSTR(&catalog));
}
}

if (! SQL_SUCCEEDED(write_wptr(&dbc->hdr.diag, dest, catalog, room,
&used))) {
ERRH(dbc, "failed to copy catalog: `" LWPD "`.", catalog);
used = -1; /* write_wptr() can change pointer, and still fail */
if (! SQL_SUCCEEDED(write_wstr(dbc, dest, &catalog, room, &used))) {
ERRH(dbc, "failed to copy catalog: `" LWPDL "`.", LWSTR(&catalog));
used = -1; /* write_wstr() can change pointer, and still fail */
}

end:
Expand Down
4 changes: 2 additions & 2 deletions driver/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -1571,8 +1571,8 @@ static void *copy_types_rows(estype_row_st *type_row, SQLULEN rows_fetched,

/* warn if scales extremes are different */
if (types[i].maximum_scale != types[i].minimum_scale) {
ERR("type `" LWPDL "` returned with non-equal max/min "
"scale: %d/%d.", LWSTR(&types[i].type_name),
INFO("type `" LWPDL "` returned with non-equal max/min "
"scale: %d/%d -- using the max.", LWSTR(&types[i].type_name),
types[i].maximum_scale, types[i].minimum_scale);
}

Expand Down
9 changes: 7 additions & 2 deletions driver/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@
#define ESODBC_MAX_CONCURRENT_ACTIVITIES 16
/* maximum identifer length */
/* TODO: review@alpha */
/* match 'keyword' ES type lenght */
/* match 'keyword' ES type length */
#define ESODBC_MAX_IDENTIFIER_LEN 256

/* 20 = len("18446744073709551616"), 1 << (sizeof(uint64_t) * 8bits) */
#define ESODBC_PRECISION_UINT64 20
/* 19 = len("9223372036854775808"), 1 << 63 */
#define ESODBC_PRECISION_INT64 19


/*
* Not authoriative (there's actually no formal limit), but pretty informed:
Expand Down Expand Up @@ -324,7 +329,7 @@
#define ESODBC_ES_TO_CSQL_DOUBLE SQL_C_DOUBLE
#define ESODBC_ES_TO_SQL_DOUBLE SQL_DOUBLE
/* 16: ??? -> SQL_C_TINYINT */
#define ESODBC_ES_TO_CSQL_BOOLEAN SQL_C_STINYINT
#define ESODBC_ES_TO_CSQL_BOOLEAN SQL_C_STINYINT /* TODO: _C_BIT? */
#define ESODBC_ES_TO_SQL_BOOLEAN ESODBC_SQL_BOOLEAN
/* 12: SQL_VARCHAR -> SQL_C_WCHAR */
#define ESODBC_ES_TO_CSQL_KEYWORD SQL_C_WCHAR /* XXX: CBOR needs _CHAR */
Expand Down
Loading