Skip to content

Commit 6414769

Browse files
committed
[SQLite] Do not use the DBMS to determine CASTs results
While this worked well, this was a non-systematic small experiment.
1 parent 542bb52 commit 6414769

File tree

1 file changed

+2
-43
lines changed

1 file changed

+2
-43
lines changed

src/sqlancer/sqlite3/ast/SQLite3Cast.java

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.math.BigDecimal;
44
import java.sql.Connection;
5-
import java.sql.Statement;
65
import java.util.Optional;
76
import java.util.regex.Pattern;
87

@@ -235,54 +234,14 @@ public static SQLite3Constant castToText(SQLite3Constant cons) {
235234
return SQLite3Constant.createTextConstant("Inf");
236235
} else if (cons.asDouble() == Double.NEGATIVE_INFINITY) {
237236
return SQLite3Constant.createTextConstant("-Inf");
237+
} else {
238+
return null;
238239
}
239-
return castRealToText(cons);
240-
// if (true) {
241-
// throw new IgnoreMeException();
242-
// }
243-
// NumberFormat fmt = NumberFormat.getInstance();
244-
// fmt.setGroupingUsed(false);
245-
// fmt.setMaximumIntegerDigits(10);
246-
// fmt.setMinimumFractionDigits(1);
247-
// fmt.setRoundingMode(RoundingMode.UNNECESSARY);
248-
// int digits;
249-
// if (cons.asDouble() < 0) {
250-
// digits = 15;
251-
// } else {
252-
// digits = 15;
253-
// }
254-
// fmt.setMaximumFractionDigits(digits);
255-
// try {
256-
// String s = fmt.format(cons.asDouble());
257-
// if (s.contentEquals("")) {
258-
// throw new IgnoreMeException();
259-
// }
260-
// return SQLite3Constant.createTextConstant(s);
261-
// } catch (Exception e) {
262-
// throw new IgnoreMeException();
263-
// }
264240
}
265241
if (cons.getDataType() == SQLite3DataType.INT) {
266242
return SQLite3Constant.createTextConstant(String.valueOf(cons.asInt()));
267243
}
268-
// if (cons.getDataType() == SQLite3DataType.BINARY) {
269-
// try {
270-
// return SQLite3Constant.createTextConstant(new String(cons.asBinary(), "UTF-8").replaceAll("\\p{C}", ""));
271-
// } catch (UnsupportedEncodingException e) {
272-
// throw new AssertionError(e);
273-
// }
274-
// }
275244
return null;
276-
// throw new AssertionError();
277-
}
278-
279-
private static synchronized SQLite3Constant castRealToText(SQLite3Constant cons) throws AssertionError {
280-
try (Statement s = castDatabase.createStatement()) {
281-
String castResult = s.executeQuery("SELECT CAST(" + cons.asDouble() + " AS TEXT)").getString(1);
282-
return SQLite3Constant.createTextConstant(castResult);
283-
} catch (Exception e) {
284-
throw new AssertionError(e);
285-
}
286245
}
287246

288247
public static SQLite3Constant asBoolean(SQLite3Constant val) {

0 commit comments

Comments
 (0)