Skip to content

Commit 3e79ce2

Browse files
author
Rishitha Kalicheti
committed
cleanup sending dummy byte, and use isnull instead (in cdb2api, and cdb2jdbc)
adding len 1 sanity check for compatability with other drivers Signed-off-by: Rishitha Kalicheti <rkalicheti1@bloomberg.com>
1 parent b345adb commit 3e79ce2

File tree

4 files changed

+10
-18
lines changed

4 files changed

+10
-18
lines changed

cdb2api/cdb2api.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7083,13 +7083,7 @@ static void cdb2_bind_param_helper(cdb2_hndl_tp *hndl, int type, const void *var
70837083
bindval->value.len = 0;
70847084
bindval->has_isnull = 1;
70857085
bindval->isnull = 1;
7086-
} else if (type == CDB2_CSTRING && length == 0) {
7087-
/* R6 and old R7 ignore isnull for cstring and treat a 0-length string
7088-
as NULL. So we send 1 dummy byte here to be backward compatible with
7089-
an old backend. */
7090-
bindval->value.data = (unsigned char *)"";
7091-
bindval->value.len = 1;
7092-
} else if (type == CDB2_BLOB && length == 0) {
7086+
} else if ((type == CDB2_BLOB || type == CDB2_CSTRING) && length == 0) {
70937087
bindval->value.data = (unsigned char *)"";
70947088
bindval->value.len = 0;
70957089
bindval->has_isnull = 1;

cdb2jdbc/src/main/java/com/bloomberg/comdb2/jdbc/Comdb2PreparedStatement.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,6 @@ public void setString(int parameterIndex, String x) throws SQLException {
142142
byte[] data;
143143
if (x == null)
144144
data = null;
145-
else if (x.length() == 0)
146-
/* R6 and old R7 ignore the isnull flag for cstring and hence always
147-
treat a 0-length string as NULL. We have to send a zero byte here
148-
to be backward compatible. */
149-
data = new byte[1];
150145
else
151146
data = x.getBytes();
152147
bindParameter(parameterIndex, Constants.Types.CDB2_CSTRING, data);

tests/sp_perf.test/t1.expected

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
[create table t (b blob)] rc 0
33
(version='t')
44
[create procedure p version 't' {
5-
local function main()
5+
local function main(str)
66
local t = db:table("t")
7-
local b = db:cast("text", 'blob')
7+
local b = db:cast(str, 'blob')
88
return t:insert({b=b})
99
end
1010
}] rc 0
11-
[exec procedure p()] rc 0
11+
[exec procedure p("text")] rc 0
12+
[exec procedure p("")] rc 0
1213
(b=x'74657874')
14+
(b=x'')
1315
[select * from t] rc 0

tests/sp_perf.test/t1.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
drop table if exists t
33
create table t (b blob)$$
44
create procedure p version 't' {
5-
local function main()
5+
local function main(str)
66
local t = db:table("t")
7-
local b = db:cast("text", 'blob')
7+
local b = db:cast(str, 'blob')
88
return t:insert({b=b})
99
end
1010
}$$
11-
exec procedure p()
11+
exec procedure p("text")
12+
exec procedure p("")
1213
select * from t

0 commit comments

Comments
 (0)