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

Data conversions: numeric types #9

Merged
merged 15 commits into from
Jun 20, 2018
Merged

Data conversions: numeric types #9

merged 15 commits into from
Jun 20, 2018

Conversation

bpintea
Copy link
Collaborator

@bpintea bpintea commented Jun 18, 2018

This PR continues the data conversion development item with conversions for the the integers and float point types.

The JSON library that reads ES' replies to queries transforms all the integers received into either long long or double types. The driver handles the conversion from these types to the type the application would like them converted to (within the allowed possibilities): strings (ansi/unicode), integers, floats, bit, binary and numeric.

bpintea added 9 commits June 10, 2018 12:30
The refactoring avoid calculating the lenght of the writen wide char
string, since that's nearly always known before the call.
This only needs to happen when all indicator buffers are NULL. -> use
REC_IS_BOUND for this.
Also fixed a typo that was checking twice for ARD record type (insead of
ARD or APD).
this allows for faster log lines related to one test
Converting between ES/SQL and SQL C types will now work.
these changes belong to the set in 063b8d4.
- also, pipe all conversions of boolean through longlogn conversion,
except the strings ones.
- add unit testing for them
- small refactoring of ints conversions to reduce code duplication
@bpintea bpintea requested review from droberts195 and edsavage June 18, 2018 13:46
@bpintea bpintea mentioned this pull request Jun 18, 2018
Closed
Copy link
Collaborator

@edsavage edsavage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few typos lurking (lenght ;-) ) but otherwise LGTM

@bpintea
Copy link
Collaborator Author

bpintea commented Jun 19, 2018

Thanks, fixed them.
(It feels like I should maybe add a commit hook for lenght :-) .)

Copy link
Contributor

@droberts195 droberts195 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few minor comments. If you want to address some of them in followups that's fine.

driver/handles.c Outdated
(SQLLEN)(intptr_t)ValuePtr);
/* rec field's type is signed :/; a negative is dangerous l8r */
if ((SQLLEN)(intptr_t)ValuePtr < 0) {
ERRH(desc, "octet length attribute can't be negative (%lu)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SQLLEN is signed, so should %lu be changed to %ld? And, as above, it might avoid future portability problems to case to long rather than SQLLEN on the line below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks.
I'm trying to use the SQL C types and put asserts wherever this would be critical.
The SQLLEN is defined as an INT64 (for _WIN64), so a long long.
So yes, the logging descriptors for ints would need some extending/rework for 32bits, indeed (but I'd like to have a look into it sooner).

driver/util.c Outdated
SQLRETURN write_wstr(SQLHANDLE hnd, SQLWCHAR *dest, wstr_st *src,
SQLSMALLINT /*B*/avail, SQLSMALLINT /*B*/*usedp)
{
size_t awail;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a bit of a trap to have variables avail and awail in the same method. Maybe rename awail to wideAvail?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Fixed, thanks.

driver/util.c Outdated

INFOH(hnd, "not enough buffer size to write required string (plus "
"terminator): `" LWPD "` [%zd]; available: %d.",
LWSTR(src), src->cnt, awail);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awail is size_t, so I think the last format should be %zu?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks.

std::wstring wstr(nameLen, L' ');
ASSERT_TRUE(mbstowcs(&wstr[0], testName, nameLen + 1) != (size_t)-1);
ret = ATTACH_SQL(stmt, &wstr[0], nameLen);
ASSERT_TRUE(SQL_SUCCEEDED(ret));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the test files are indented with spaces. Would it be better to use either tabs or spaces consistently through the whole repo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might, yes. GoogleTest framework uses spaces for indenting so I've just continued that, but yes, it would be more logical to be consistent within the repo. I'll apply this change at a later point.

build.bat Outdated
@@ -1,4 +1,4 @@
@echo off
echo off
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does removing the @ mean that echo off itself now gets printed to the console? (It would have done 25 years ago but maybe not now.) If so, was removing it intentional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed, @ (still) mutes the statement itself (in my cmd shell).
But the removal wasn't quite intentional, I've added it back, thanks!

@bpintea bpintea merged commit fbd1e00 into elastic:master Jun 20, 2018
@bpintea bpintea deleted the feature/numeric_conversions branch June 20, 2018 12:52
@bpintea bpintea added >feature Applicable to PRs adding new functionality v6.5.0 labels May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>feature Applicable to PRs adding new functionality v6.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants