提交 1b67892f authored 作者: Owner's avatar Owner

Removing CR/LF from column names

上级 bd8ffe80
...@@ -102,7 +102,6 @@ public class CommandContainer extends Command { ...@@ -102,7 +102,6 @@ public class CommandContainer extends Command {
int updateCount = prepared.update(); int updateCount = prepared.update();
prepared.trace(startTimeNanos, updateCount); prepared.trace(startTimeNanos, updateCount);
setProgress(DatabaseEventListener.STATE_STATEMENT_END); setProgress(DatabaseEventListener.STATE_STATEMENT_END);
System.out.println("CommandContainer.update.end");
return updateCount; return updateCount;
} }
...@@ -115,14 +114,11 @@ public class CommandContainer extends Command { ...@@ -115,14 +114,11 @@ public class CommandContainer extends Command {
ResultInterface result = prepared.query(maxrows); ResultInterface result = prepared.query(maxrows);
prepared.trace(startTimeNanos, result.isLazy() ? 0 : result.getRowCount()); prepared.trace(startTimeNanos, result.isLazy() ? 0 : result.getRowCount());
setProgress(DatabaseEventListener.STATE_STATEMENT_END); setProgress(DatabaseEventListener.STATE_STATEMENT_END);
System.out.println("CommandContainer.query.end");
return result; return result;
} }
@Override @Override
public void stop() { public void stop() {
System.out.println("CommandContainer.stop.stop");
super.stop();
// Clean up after the command was run in the session. // Clean up after the command was run in the session.
// Must restart query (and dependency construction) to reuse. // Must restart query (and dependency construction) to reuse.
if (prepared.getCteCleanups() != null) { if (prepared.getCteCleanups() != null) {
...@@ -130,14 +126,11 @@ public class CommandContainer extends Command { ...@@ -130,14 +126,11 @@ public class CommandContainer extends Command {
// check if view was previously deleted as their name is set to // check if view was previously deleted as their name is set to
// null // null
if (view.getName() != null) { if (view.getName() != null) {
System.out.println("!!!!!!!removeLocalTempTable.worked="+view.getName());
session.removeLocalTempTable(view); session.removeLocalTempTable(view);
} }
else{
System.out.println("!!!!!!!removeLocalTempTable=(null local name)"+view.toString());
}
} }
} }
super.stop();
} }
@Override @Override
......
...@@ -5156,7 +5156,6 @@ public class Parser { ...@@ -5156,7 +5156,6 @@ public class Parser {
Query query = parseSelectUnion(); Query query = parseSelectUnion();
query.setPrepareAlways(true); query.setPrepareAlways(true);
query.setNeverLazy(true); query.setNeverLazy(true);
System.out.println("class="+query.getClass());
p = query; p = query;
} }
else if(readIf("INSERT")) { else if(readIf("INSERT")) {
...@@ -5297,11 +5296,11 @@ public class Parser { ...@@ -5297,11 +5296,11 @@ public class Parser {
// No easy way to determine if this is a recursive query up front, so we just compile // No easy way to determine if this is a recursive query up front, so we just compile
// it twice - once without the flag set, and if we didn't see a recursive term, // it twice - once without the flag set, and if we didn't see a recursive term,
// then we just compile it again. // then we just compile it again.
System.out.println("parseSingleCommonTableExpression.querySQL="+querySQL);
TableView view = new TableView(schema, id, tempViewName, querySQL, TableView view = new TableView(schema, id, tempViewName, querySQL,
parameters, columnTemplateList.toArray(new Column[0]), session, parameters, columnTemplateList.toArray(new Column[0]), session,
allowRecursiveQueryDetection, false); allowRecursiveQueryDetection, false);
if (!view.isRecursiveQueryDetected() && allowRecursiveQueryDetection) { if (!view.isRecursiveQueryDetected() && allowRecursiveQueryDetection) {
session.removeLocalTempTable(view);
view = new TableView(schema, id, tempViewName, querySQL, parameters, view = new TableView(schema, id, tempViewName, querySQL, parameters,
columnTemplateList.toArray(new Column[0]), session, columnTemplateList.toArray(new Column[0]), session,
false/* recursive */, false); false/* recursive */, false);
......
...@@ -445,10 +445,6 @@ public abstract class Prepared { ...@@ -445,10 +445,6 @@ public abstract class Prepared {
* Get the temporary views created for CTE's. * Get the temporary views created for CTE's.
*/ */
public List<TableView> getCteCleanups() { public List<TableView> getCteCleanups() {
System.out.println("getCteCleanups:"+cteCleanups);
if(cteCleanups!=null){
System.out.println("getCteCleanups:"+cteCleanups.size());
}
return cteCleanups; return cteCleanups;
} }
......
...@@ -843,13 +843,9 @@ public class Select extends Query { ...@@ -843,13 +843,9 @@ public class Select extends Query {
for (int i = 0; i < expressions.size(); i++) { for (int i = 0; i < expressions.size(); i++) {
Expression e = expressions.get(i); Expression e = expressions.get(i);
String columnName = ColumnNamer.getColumnName(e,i,null); String columnName = ColumnNamer.getColumnName(e,i,null);
if(!ColumnNamer.isReasonableColumnName(e.getAlias())){ if(!ColumnNamer.isAllowableColumnName(e.getAlias())){
System.out.println("Added alias="+columnName);
e = new Alias(e,columnName,true); e = new Alias(e,columnName,true);
} }
else{
System.out.println("Acceptable column name="+columnName);
}
expressions.set(i, e.optimize(session)); expressions.set(i, e.optimize(session));
} }
if (condition != null) { if (condition != null) {
......
...@@ -364,7 +364,6 @@ public class Session extends SessionWithState { ...@@ -364,7 +364,6 @@ public class Session extends SessionWithState {
table.getSQL()+" AS "+table.getName()); table.getSQL()+" AS "+table.getName());
} }
modificationId++; modificationId++;
System.out.println("addLocalTempTable.worked="+table.getName()+table.toString());
localTempTables.put(table.getName(), table); localTempTables.put(table.getName(), table);
} }
......
...@@ -417,13 +417,6 @@ public class TableView extends Table { ...@@ -417,13 +417,6 @@ public class TableView extends Table {
@Override @Override
public void removeChildrenAndResources(Session session) { public void removeChildrenAndResources(Session session) {
System.out.println("invalidating="+getName());
try{
throw new RuntimeException("snapshot");
}
catch(RuntimeException e){
e.printStackTrace();
}
removeViewFromTables(); removeViewFromTables();
super.removeChildrenAndResources(session); super.removeChildrenAndResources(session);
database.removeMeta(session, getId()); database.removeMeta(session, getId());
...@@ -447,8 +440,6 @@ public class TableView extends Table { ...@@ -447,8 +440,6 @@ public class TableView extends Table {
@Override @Override
public String getSQL() { public String getSQL() {
if (isTemporary()) { if (isTemporary()) {
System.out.println("table view name="+getName());
System.out.println(this.toString()+".getSQL().querySQL="+querySQL);
return "(\n" + StringUtils.indent(querySQL) + ")"; return "(\n" + StringUtils.indent(querySQL) + ")";
} }
return super.getSQL(); return super.getSQL();
...@@ -512,11 +503,8 @@ public class TableView extends Table { ...@@ -512,11 +503,8 @@ public class TableView extends Table {
private void removeViewFromTables() { private void removeViewFromTables() {
if (tables != null) { if (tables != null) {
System.out.println("removeViewFromTables.tables="+tables);
System.out.println("removeViewFromTables.this="+this);
for (Table t : tables) { for (Table t : tables) {
t.removeView(this); t.removeView(this);
System.out.println("removeViewFromTables.tables."+t.getName()+"="+t.getViews());
} }
tables.clear(); tables.clear();
} }
......
...@@ -13,13 +13,16 @@ public class ColumnNamer { ...@@ -13,13 +13,16 @@ public class ColumnNamer {
} }
if (columnName==null && columnExp.getAlias()!=null){ if (columnName==null && columnExp.getAlias()!=null){
columnName = columnExp.getAlias(); columnName = columnExp.getAlias();
if(!isReasonableColumnName(columnName)){ if(!isAllowableColumnName(columnName)){
columnName = null; columnName = null;
} }
} }
if (columnName==null && columnExp.getColumnName()!=null){ if (columnName==null && columnExp.getColumnName()!=null){
columnName = columnExp.getColumnName(); columnName = columnExp.getColumnName();
if(!isReasonableColumnName(columnName)){ if(!isAllowableColumnName(columnName)){
columnName = columnName.replace('\n', ' ').replace('\r', ' ');
}
if(!isAllowableColumnName(columnName)){
columnName = null; columnName = null;
} }
} }
...@@ -29,15 +32,16 @@ public class ColumnNamer { ...@@ -29,15 +32,16 @@ public class ColumnNamer {
return columnName; return columnName;
} }
private static Pattern reasonableNamePatternRE = Pattern.compile("[A-Z_][A-Z0-9_]*"); //private static final Pattern reasonableNameCharactersPatternRE = Pattern.compile("[a-zA-Z0-9_'\\(\\)\\*,\\.\\+\\-\\*/:=\\<\\>!\\|@ \\t\\?\"\\$]*");
public static boolean isReasonableColumnName(String proposedName){ public static boolean isAllowableColumnName(String proposedName){
if (proposedName == null){ if (proposedName == null){
return false; return false;
} }
Matcher m = reasonableNamePatternRE.matcher(proposedName.toUpperCase()); if(proposedName.contains("\n") || proposedName.contains("\r")){
boolean isReasonableName = m.matches(); return false;
return isReasonableName; }
return true;
} }
} }
...@@ -9,7 +9,6 @@ import java.sql.Connection; ...@@ -9,7 +9,6 @@ import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.Statement; import java.sql.Statement;
import org.h2.jdbc.JdbcSQLException; import org.h2.jdbc.JdbcSQLException;
import org.h2.test.TestBase; import org.h2.test.TestBase;
...@@ -219,7 +218,7 @@ public class TestGeneralCommonTableQueries extends TestBase { ...@@ -219,7 +218,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
assertEquals(n, rs.getInt(1)); assertEquals(n, rs.getInt(1));
} }
assertEquals("X",rs.getMetaData().getColumnLabel(1)); assertEquals("X",rs.getMetaData().getColumnLabel(1));
assertEquals("_unnamed_column_2_",rs.getMetaData().getColumnLabel(2)); assertEquals("'T1'",rs.getMetaData().getColumnLabel(2));
assertFalse(rs.next()); assertFalse(rs.next());
...@@ -511,32 +510,39 @@ public class TestGeneralCommonTableQueries extends TestBase { ...@@ -511,32 +510,39 @@ public class TestGeneralCommonTableQueries extends TestBase {
+"FROM A \n" +"FROM A \n"
+"GROUP BY A.val"; +"GROUP BY A.val";
for(int queryTries: new int[]{1,2,3}){ for(@SuppressWarnings("unused") int queryRunTries: new int[]{1,2,3}){
System.out.println("Try#"+queryTries);
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute(SETUP_SQL); stat.execute(SETUP_SQL);
stat.close();
prep = conn.prepareStatement(WITH_QUERY); prep = conn.prepareStatement(WITH_QUERY);
rs = prep.executeQuery(); rs = prep.executeQuery();
for(int columnIndex = 1; columnIndex <= rs.getMetaData().getColumnCount(); columnIndex++){ for(int columnIndex = 1; columnIndex <= rs.getMetaData().getColumnCount(); columnIndex++){
System.out.print("|"+rs.getMetaData().getColumnLabel(columnIndex)); // previously the column label was null or had \n or \r in the string
} assertTrue(rs.getMetaData().getColumnLabel(columnIndex)!=null);
System.out.println(); assertFalse(rs.getMetaData().getColumnLabel(columnIndex).contains("\n"));
assertFalse(rs.getMetaData().getColumnLabel(columnIndex).contains("\r"));
}
int rowNdx=0;
while (rs.next()) { while (rs.next()) {
//assertTrue(rs.next()); StringBuffer buf = new StringBuffer();
//assertContains("ab",rs.getString(1));
//assertEquals(rs.getString(1),keyLetter);
//assertTrue(rs.getInt(2)!=0);
for(int columnIndex = 1; columnIndex <= rs.getMetaData().getColumnCount(); columnIndex++){ for(int columnIndex = 1; columnIndex <= rs.getMetaData().getColumnCount(); columnIndex++){
System.out.print("|"+rs.getString(columnIndex)); buf.append("|"+rs.getString(columnIndex));
} }
System.out.println(); String[] expectedRow =new String[]{"|meat|null","|fruit|3","|veg|2"};
} assertEquals(expectedRow[rowNdx], buf.toString());
rowNdx++;
}
assertEquals(3,rowNdx);
rs.close();
prep.close();
} }
conn.close(); conn.close();
//System.out.println("conn.close();");
deleteDb("commonTableExpressionQueries"); deleteDb("commonTableExpressionQueries");
//System.out.println("deleteDb(commonTableExpressionQueries);");
} }
} }
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论