Using Oracle, we are doing some simple selects from a table that has CHAR[x] fields. We are using null-terminated char* strings and have run into some snags reconciling differences in padding between the two datatypes.
As an example, say we have a field SOME_FIELD in SOME_TABLE defined to be CHAR[3]. Given the following statement:
SELECT * FROM SOME_TB
WHERE SOME_FIELD=:var<char[4]>
Even saying one value of SOME_FIELD is "AB ", sending an unpadded "AB" will match no fields in the database. Since OCI can handle the difference without padding, I'm confident that the OTL can also. I just dont know how. What is the cleanest way other users have found to deal with this problem?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
SELECT * FROM SOME_TB
WHERE SOME_FIELD=
RPAD(:var<char[4]>,
VSIZE(SOME_FIELD),
' ')
OTL should have had a "padded char[xxx]" type, say, charz[XXX], but it doesn't in reality, because of low demand. Also, it's more difficult to implement the "fixed size string" semantic in C++ itself, since all string comparisons are "variable-length" based.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I have the same problem with fixed-length field CHAR[x] used in WHERE clause. Unfortunately I cannot modify SQL statement. Would it be possible to fix this in OTL? You mentioned that there is a problem with implementing this. What kind of problem is it? Maybe I could fix it if you would give me some hint how to do this?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Using Oracle, we are doing some simple selects from a table that has CHAR[x] fields. We are using null-terminated char* strings and have run into some snags reconciling differences in padding between the two datatypes.
As an example, say we have a field SOME_FIELD in SOME_TABLE defined to be CHAR[3]. Given the following statement:
SELECT * FROM SOME_TB
WHERE SOME_FIELD=:var<char[4]>
Even saying one value of SOME_FIELD is "AB ", sending an unpadded "AB" will match no fields in the database. Since OCI can handle the difference without padding, I'm confident that the OTL can also. I just dont know how. What is the cleanest way other users have found to deal with this problem?
This will do the trick:
SELECT * FROM SOME_TB
WHERE SOME_FIELD=
RPAD(:var<char[4]>,
VSIZE(SOME_FIELD),
' ')
OTL should have had a "padded char[xxx]" type, say, charz[XXX], but it doesn't in reality, because of low demand. Also, it's more difficult to implement the "fixed size string" semantic in C++ itself, since all string comparisons are "variable-length" based.
Thanks Sergei, this will do just fine!
Hi,
I have the same problem with fixed-length field CHAR[x] used in WHERE clause. Unfortunately I cannot modify SQL statement. Would it be possible to fix this in OTL? You mentioned that there is a problem with implementing this. What kind of problem is it? Maybe I could fix it if you would give me some hint how to do this?