Skip to content

Commit 78a2bdd

Browse files
committed
Merge commit '758801287173117eb75f1da17a6eee29683306ff'
2 parents c62ce4e + 7588012 commit 78a2bdd

4 files changed

Lines changed: 59 additions & 4 deletions

File tree

src/main/java/picoded/dstack/connector/jsql/JSql_Base.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ protected PreparedStatement prepareSqlStatment(Connection sqlConn, String qStrin
130130
ps.setDouble(pt + 1, (Double) argObj);
131131
} else if (Float.class.isInstance(argObj)) {
132132
ps.setFloat(pt + 1, (Float) argObj);
133+
} else if (Boolean.class.isInstance(argObj)){
134+
boolean bValue = (Boolean) argObj;
135+
// note that due to a bug in dstack before 26 Aug 2024,
136+
// ... all boolean values were stored as json (Core_DataType.JSON, 31)
137+
// ...thus entry is stored with the values: nVl = NULL, sVL = null, tVl = "true" or "false"
138+
// ... thus, for boolean, we need to query against tVl to support legacy values
139+
// ... this bug has been fixed in newer versions of dstack...
140+
// ... where the entry is stored with the values: nVl = 1 or 0, sVL = "true" or "false", tVl = "true" or "false"
141+
ps.setString(pt + 1, bValue ? "true" : "false");
142+
// ps.setBoolean(pt + 1, (Boolean) argObj); // this does not work, bc this transforms the value to 1/0
133143
} else if (Date.class.isInstance(argObj)) {
134144
java.sql.Date sqlDate = new java.sql.Date(((Date) argObj).getTime());
135145
ps.setDate(pt + 1, sqlDate);

src/main/java/picoded/dstack/core/Core_DataType.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ public enum Core_DataType {
5959
* String type
6060
**/
6161
STRING(25),
62-
62+
63+
/**
64+
* Boolean type
65+
*/
66+
BOOLEAN(26),
67+
6368
//
6469
// Storage types
6570
//

src/main/java/picoded/dstack/jsql/JSql_DataObjectMapUtil.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,15 @@ public static Object[] valueToValueTypeSet(Object value) {
193193
return valueTypeSet(Core_DataType.STRING.getValue(), null, shortenStringValue(value),
194194
value.toString(), EmptyArray.BYTE);
195195
}
196-
196+
197+
// Boolean type support
198+
// - stores nVl as 1 or 0
199+
// - store sVl and tVl as the string value : "true" or "false"
200+
if(value instanceof Boolean){
201+
return valueTypeSet(Core_DataType.BOOLEAN.getValue(), ((Boolean) value) ? 1 : 0, value.toString(), value.toString(),
202+
EmptyArray.BYTE);
203+
}
204+
197205
// Binary type support
198206
if (value instanceof byte[]) {
199207
return valueTypeSet(Core_DataType.BINARY.getValue(), null, null, null, (byte[]) value);
@@ -251,14 +259,36 @@ protected static Object extractNonArrayValueFromPos(JSqlResult r, int pos) {
251259
} else if (baseType == Core_DataType.TEXT.getValue()) { // Text
252260
return r.get("tVl").getString(pos);
253261
}
254-
262+
263+
//
264+
// Boolean value support
265+
//
266+
if(baseType == Core_DataType.BOOLEAN.getValue()){
267+
String tVl = r.getString("tVl");
268+
if(tVl.equalsIgnoreCase("true")){
269+
return true;
270+
}
271+
if(tVl.equalsIgnoreCase("false")){
272+
return false;
273+
}
274+
// get the value from nVl
275+
int nVl = r.getInt("nVl");
276+
if(nVl == 1){
277+
return true;
278+
}
279+
if(nVl == 0){
280+
return false;
281+
}
282+
throw new JSqlException("Invalid boolean value: tVl=" + tVl + ", nVl=" + nVl);
283+
}
284+
255285
//
256286
// Binary value
257287
//
258288
if (baseType == Core_DataType.BINARY.getValue()) {
259289
// Older base64 stroage format
260290
// return (Base64.getDecoder().decode((String) (r.get("tVl").get(pos))));
261-
291+
262292
Object rawValue = r.get("rVl").get(pos);
263293
if (rawValue instanceof java.sql.Blob) {
264294
java.sql.Blob blobData = (java.sql.Blob) rawValue;

src/main/java/picoded/dstack/jsql/JSql_DataObjectMap_QueryBuilder.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,16 @@ private Query dynamicTableQueryRewrite( //
921921
"(" + collumnTableAlias + ".sVl IS NULL OR " + replacement.toString() + ")");
922922
}
923923
}
924+
} else if (argObj instanceof Boolean) {
925+
// note that due to a bug in dstack before 26 Aug 2024,
926+
// ... all boolean values were stored as json (Core_DataType.JSON, 31)
927+
// ...thus entry is stored with the values: nVl = NULL, sVL = null, tVl = "true" or "false"
928+
// ... thus, for boolean, we need to query against tVl to support legacy values
929+
// ... this bug has been fixed in newer versions of dstack...
930+
// ... where the entry is stored with the values: nVl = 1 or 0, sVL = "true" or "false", tVl = "true" or "false"
931+
replacement = QueryFilter.basicQueryFromTokens(queryArgMap, collumnTableAlias
932+
+ ".tVl", toReplace.operatorSymbol(), ":" + toReplace.argumentName() //
933+
);
924934
}
925935

926936
// Unprocessed arg type

0 commit comments

Comments
 (0)