-
Notifications
You must be signed in to change notification settings - Fork 21
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
Inserting to a column CLOB, fill all clob with x00 #187
Comments
In the dbstmt.cc code When using a 2D array for parameters, for a clob we need to use 0 or 1 bind indicator, since there is no CLOB indicator at line ~2601
I see that param[i].ind = SQL_NTS; can be the part of the problem |
Are you adding the 00 to fill to clob size or are you saying that nodejs-idb-connector is? |
nodejs-idb-connector/cli is adding the clob x00 to fill all the clob. |
std::string string = value.ToString().Utf8Value();
const char *cString = string.c_str();
param[i].buf = (char *)calloc(std::max(static_cast<size_t>(param[i].paramSize), str_length) + 1, sizeof(char));
if (param[i].io != SQL_PARAM_OUTPUT) {
strcpy((char*)param[i].buf, cString);
} I the code you referenced, the data that is copied in from Node.js is converted to a std::string and then we access it as a C-style null-terminated string, then we copy it to an internal buffer which is initialized to all null. The copy is also a C-style string copy. And we also set the indicator to tell CLI that the data is null-terminated. Any single one of these steps would mess up inserting null bytes, but all together there's overwhelmingly no way this would cause the data to be padded with null bytes. Though, I could see maybe this should be changed so that if a user did put embedded null bytes in their JS string that they would get inserted whereas today the data would be truncated incorrectly which is the opposite of your problem. It must be somewhere else within the idb-connector code which is causing your issue. Or else the problem is within CLI itself. |
The problem I end with a lot of x'00' values, and I was only inserting a small string. I think the problem is that when you use 1D array params, the CLOB is written to the correct size with no many nulls embeded at the end. For 1D array params it end at this case :
The only difference I see is that param[i].ind has a different value than SQL_NTS. |
Must be this code then: // value is '' -> output param
param[i].ind = param[i].paramSize; Since the code within the You are passing in something like |
I tested with the same javascript string, I got different results ( works well with 1D array params but not with 2 array params ) |
Can you provide example JS code which can recreate the problem? |
In this case 'select LENGTH(MYCLOB) from MYTABLE' returns me 1MB. |
Hello @abamara 👋🏿 Why are you are using There should be |
Hi, If I use db.SQL_CLOB, I get this error ; BIND INDICATOR FOR PARAMETER 4IS INVALID db.SQL_ALL_TYPES is equivalent to 0. |
@abmusse I can't recall how the idb-connector bind code works, but if the type passed in by the user is passed as the target type on SQLBindCol, then this will not work properly for SQL_CLOB as that requires binding as a LOB struct, IIRC. |
Using db.SQL_CLOB wouldn't work as you've seen. Yes SQL_ALL_TYPES and CLOB alias are equivalent both are 0 so these would go down same code path. I was unsure what SQL_ALL_TYPES was defined to but looks like its the same as CLOB. In the case of 2-D array the user passes in This will later be used in the SQLBindParameter call. nodejs-idb-connector/src/db2ia/dbstmt.cc Lines 2601 to 2619 in 6db9a2d
In the case of the 1D Array we handle CLOBs differently: nodejs-idb-connector/src/db2ia/dbstmt.cc Lines 2747 to 2763 in 6db9a2d
We set the indicator to the parameter size that was retrieved from SQLDescribeParam call. So perhaps using SQL_NTS is causing the weird behavior? |
Well, I see that we don't set |
Hi
Inserting to a CLOB column, fill all clob with x00 at the end.
When inserting a row, using bindParameters with and targeting a table with a CLOB it add 00 to fill all clob size.
If my CLOB is defined with a size 1MB, select LENGTH(MYCLOB) from MYTABLE return 1MB and not the size of my actual data.
If I use a 2D array bindParameters( [ ['mytext', db.IN, db.SQL_ALL_TYPE] ] ) it fill the full CLOB with x00.
So the select LENGTH(MYCLOB) form MYTABLE returns 1MB
If I use a 1D array bindParameters( ['mytext'] ) it doesn't fill the CLOB column with x00
So the select LENGTH(MYCLOB) form MYTABLE returns only the actual data I inserted.
The text was updated successfully, but these errors were encountered: