improved sql parser.

This commit is contained in:
wenshao
2017-06-21 12:49:49 +08:00
parent 17c22cf84a
commit a679837026
13 changed files with 952 additions and 7 deletions
@@ -29,6 +29,8 @@ import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.HashSet;
import java.util.Set;
public class MySqlUtils {
static Class<?> utilClass;
@@ -104,4 +106,24 @@ public class MySqlUtils {
}
return null;
}
private static Set<String> keywords;
public static boolean isKeyword(String name) {
if (name == null) {
return false;
}
String name_lower = name.toLowerCase();
Set<String> words = keywords;
if (words == null) {
words = new HashSet<String>();
Utils.loadFromFile("META-INF/druid/parser/mysql/keywords", words);
keywords = words;
}
return words.contains(name_lower);
}
}
@@ -15,10 +15,8 @@
*/
package com.alibaba.druid.util;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
@@ -28,6 +26,7 @@ import javax.transaction.xa.XAException;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.OracleResultSet;
import oracle.jdbc.OracleStatement;
import oracle.jdbc.driver.DatabaseError;
import oracle.jdbc.internal.OraclePreparedStatement;
import oracle.jdbc.xa.client.OracleXAConnection;
import oracle.sql.ROWID;
@@ -203,4 +202,24 @@ public class OracleUtils {
return tables.contains(table_lower);
}
private static Set<String> keywords;
public static boolean isKeyword(String name) {
if (name == null) {
return false;
}
String name_lower = name.toLowerCase();
Set<String> words = keywords;
if (words == null) {
words = new HashSet<String>();
Utils.loadFromFile("META-INF/druid/parser/oracle/keywords", words);
keywords = words;
}
return words.contains(name_lower);
}
}
@@ -0,0 +1,23 @@
/*
* Copyright 1999-2017 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.util.lang;
/**
* Created by wenshao on 20/06/2017.
*/
public interface Consumer<T> {
void accept(T t);
}