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

Removing CR/LF from column names

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