From 1874e543ab4325ae106acc87c2b4db032fb4671a Mon Sep 17 00:00:00 2001 From: Zac Spitzer Date: Tue, 2 Jul 2024 09:06:45 +0200 Subject: [PATCH] LDEV-4867 remove debugging --- .../java/lucee/commons/lang/ParserString.java | 27 +++++-------------- .../java/lucee/runtime/db/HSQLDBHandler.java | 7 +---- .../main/java/lucee/runtime/db/SQLImpl.java | 8 ++---- .../java/lucee/runtime/sql/SelectParser.java | 13 ++------- .../main/java/lucee/runtime/tag/Query.java | 12 +-------- .../runtime/tag/util/QueryParamConverter.java | 3 +-- test/tickets/LDEV2754.cfc | 2 +- 7 files changed, 14 insertions(+), 58 deletions(-) diff --git a/core/src/main/java/lucee/commons/lang/ParserString.java b/core/src/main/java/lucee/commons/lang/ParserString.java index 413094451f6..85cf0a40355 100644 --- a/core/src/main/java/lucee/commons/lang/ParserString.java +++ b/core/src/main/java/lucee/commons/lang/ParserString.java @@ -19,7 +19,6 @@ package lucee.commons.lang; import lucee.commons.io.SystemUtil; -import lucee.aprint; /** * Der CFMLString ist eine Hilfe fuer die Transformer, er repraesentiert den CFML Code und bietet @@ -62,10 +61,10 @@ public ParserString(String text) { } /** - * Diesen Konstruktor kann er CFML Code als Zeichenkette uebergeben werden. + * This constructor allows stripping comments from SQL Text * - * @param text CFML Code - * @param doIgnoreComments treat comments as space + * @param text SQL Text + * @param doIgnoreComments strip sql comments from text */ public ParserString(String text, boolean doIgnoreComments) { init(text, doIgnoreComments); @@ -78,7 +77,7 @@ public ParserString(String text, boolean doIgnoreComments) { * @param str */ protected void init(String str, boolean doIgnoreComments) { - if (doIgnoreComments) str = stripComments(str); + if (doIgnoreComments) str = stripSqlComments(str); int len = str.length(); text = new char[len]; lcText = new char[len]; @@ -712,23 +711,16 @@ public boolean removeSpace() { } return (start < pos); } - /* - * MARK: stripcomment - * - */ /** * Strip out all sql comments * * @return SQL text with comments stripped out */ - public String stripComments(String sql) { + public String stripSqlComments(String sql) { char c; int sqlLen = sql.length(); StringBuilder sb = new StringBuilder(); - // aprint.out( "-----stripComments START---" ); - // aprint.out( sql ); - for (int i = 0; i < sqlLen; i++) { c = sql.charAt(i); if ( i < (sqlLen - 1)) { @@ -736,7 +728,7 @@ public String stripComments(String sql) { if (c == '/' && sql.charAt(i + 1) == '*') { int end = sql.indexOf("*/", i + 2); if (end != -1) { - i = end + 1; // TODO why 1 here, not 2? + i = end + 1; continue; } } @@ -752,14 +744,7 @@ public String stripComments(String sql) { } } sb.append(c); - //aprint.out( "@" + i ); - //aprint.out( sb.toString() ); } - /* - aprint.out( "" ); - aprint.out( sb.toString() ); - aprint.out( "-----stripComments END---" ); - */ return sb.toString().trim(); } diff --git a/core/src/main/java/lucee/runtime/db/HSQLDBHandler.java b/core/src/main/java/lucee/runtime/db/HSQLDBHandler.java index 2892adc72bc..158473ec957 100644 --- a/core/src/main/java/lucee/runtime/db/HSQLDBHandler.java +++ b/core/src/main/java/lucee/runtime/db/HSQLDBHandler.java @@ -56,7 +56,6 @@ import lucee.runtime.type.QueryImpl; import lucee.runtime.type.dt.TimeSpan; import lucee.runtime.type.util.CollectionUtil; -import lucee.aprint; /** * class to reexecute queries on the resultset object inside the cfml environment @@ -268,18 +267,15 @@ public QueryImpl execute(PageContext pc, final SQL sql, int maxrows, int fetchsi if (spe.getCause() != null && spe.getCause() instanceof IllegalQoQException) { throw Caster.toPageException(spe); } - aprint.out(spe); prettySQL = SQLPrettyfier.prettyfie(sql.getSQLString(), true); - //aprint.out("---prettyfie----"); - //aprint.out(prettySQL); + try { QueryImpl query = executer.execute(pc, sql, prettySQL, maxrows); query.setExecutionTime(stopwatch.time()); return query; } catch (Exception ex) { - aprint.out(ex); } } @@ -345,7 +341,6 @@ public QueryImpl execute(PageContext pc, final SQL sql, int maxrows, int fetchsi } catch (ParseException e) { - aprint.out(sql); throw new DatabaseException(e.getMessage(), null, sql, null); } diff --git a/core/src/main/java/lucee/runtime/db/SQLImpl.java b/core/src/main/java/lucee/runtime/db/SQLImpl.java index 4262e0e1d26..c59178c99a5 100644 --- a/core/src/main/java/lucee/runtime/db/SQLImpl.java +++ b/core/src/main/java/lucee/runtime/db/SQLImpl.java @@ -144,12 +144,8 @@ public String toString() { sb.append(c); } else if (!inQuotes && c == '?') { - if ((index + 1) > items.length){ - //System.out.println( sb.toString() ); - throw new RuntimeException("There are more question marks [" + (index+1) - + "] in the SQL than params defined [" + items.length - + "], in the SQL String: [" + strSQL + "]"); - } + if ((index + 1) > items.length) throw new RuntimeException("There are more question marks [" + (index+1) + + "] in the SQL than params defined [" + items.length + "], in the SQL String: [" + strSQL + "]"); if (items[index].isNulls()) sb.append("null"); else sb.append(SQLCaster.toString(items[index])); index++; diff --git a/core/src/main/java/lucee/runtime/sql/SelectParser.java b/core/src/main/java/lucee/runtime/sql/SelectParser.java index 8d6b20366e1..6902427bd15 100644 --- a/core/src/main/java/lucee/runtime/sql/SelectParser.java +++ b/core/src/main/java/lucee/runtime/sql/SelectParser.java @@ -44,7 +44,6 @@ import lucee.runtime.sql.exp.value.ValueNumber; import lucee.runtime.sql.exp.value.ValueString; import lucee.runtime.type.Collection.Key; -import lucee.aprint; public class SelectParser { @@ -63,14 +62,7 @@ public class SelectParser { // select from where public Selects parse(String sql) throws SQLParserException { columnIndex = 0; - ParserString raw = new ParserString(sql.trim(), true); - /* - aprint.out("---select parser----"); - aprint.out(sql); - aprint.out( "" ); - aprint.out( raw.toString() ); - aprint.out( "" ); - */ + ParserString raw = new ParserString(sql.trim(),true); Selects selects = new Selects(); Select select = new Select(); @@ -168,8 +160,7 @@ public Selects parse(String sql) throws SQLParserException { if (raw.forwardIfCurrent(';')) raw.removeSpace(); - if (!raw.isAfterLast()) - throw new SQLParserException("Error parsing SQL statement (stop at char:" + raw.getCurrent() + ", pos: " + raw.getPos() + "), sql: [" + raw.toString() + "]"); + if (!raw.isAfterLast()) throw new SQLParserException("Error parsing SQL statement (stop at char:" + raw.getCurrent() + ", pos: " + raw.getPos() + "), sql: [" + raw.toString() + "]"); return selects; } diff --git a/core/src/main/java/lucee/runtime/tag/Query.java b/core/src/main/java/lucee/runtime/tag/Query.java index c3458c2d27a..ddb3d322af7 100755 --- a/core/src/main/java/lucee/runtime/tag/Query.java +++ b/core/src/main/java/lucee/runtime/tag/Query.java @@ -674,17 +674,7 @@ else if (data.cachedWithin == null) { // cache not found, process and cache result if needed if (queryResult == null) { // QoQ - if ("parseonly".equals(data.dbtype)) { // used for testing the query parser, doens't execute - Struct sct = new StructImpl(); - sct.setEL(KeyConstants._SQL, sqlQuery.getSQLString()); - sct.setEL(KeyConstants._source, strSQL); - if (setVars){ - if (!StringUtil.isEmpty(data.result)) pageContext.setVariable(data.result, sct); - else if (!StringUtil.isEmpty(data.name)) pageContext.setVariable(data.name, sct); - } - return EVAL_PAGE; - } - else if ("query".equals(data.dbtype)) { + if ("query".equals(data.dbtype)) { QueryImpl q = executeQoQ(pageContext, data, sqlQuery, tl); q.setTemplateLine(tl); if (data.returntype == RETURN_TYPE_ARRAY) queryResult = QueryArray.toQueryArray(q); // TODO this should be done in queryExecute diff --git a/core/src/main/java/lucee/runtime/tag/util/QueryParamConverter.java b/core/src/main/java/lucee/runtime/tag/util/QueryParamConverter.java index f66d2f4c3cf..54a082e6096 100644 --- a/core/src/main/java/lucee/runtime/tag/util/QueryParamConverter.java +++ b/core/src/main/java/lucee/runtime/tag/util/QueryParamConverter.java @@ -114,7 +114,7 @@ public static Struct toStruct(SQLItem item, boolean fns) { NamedSQLItem nsi = (NamedSQLItem) item; sct.setEL(KeyConstants._name, nsi.getName()); } - if (fns || item.getValue() != null) sct.setEL(KeyConstants._value, item.getValue() ); + if (fns || item.getValue() != null) sct.setEL(KeyConstants._value, item.getValue()); else sct.setEL(KeyConstants._value, ""); sct.setEL(KeyConstants._type, SQLCaster.toStringType(item.getType(), null)); sct.setEL(KeyConstants._scale, item.getScale()); @@ -167,7 +167,6 @@ private static SQL convert(String sql, List> items, List