mirror of
https://github.com/apache/sqoop.git
synced 2025-05-03 15:00:45 +08:00
SQOOP-166. Postgresql identifiers should be quoted
(James Grant via Arvind Prabhakar) From: Arvind Prabhakar <arvind@cloudera.com> git-svn-id: https://svn.apache.org/repos/asf/incubator/sqoop/trunk@1150017 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9b10f9b2c4
commit
9219504fd8
@ -50,6 +50,23 @@ protected PostgresqlManager(final SqoopOptions opts, boolean ignored) {
|
||||
super(DRIVER_CLASS, opts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeColName(String colName) {
|
||||
return escapeIdentifier(colName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeTableName(String tableName) {
|
||||
return escapeIdentifier(tableName);
|
||||
}
|
||||
|
||||
protected String escapeIdentifier(String identifier) {
|
||||
if (identifier == null) {
|
||||
return null;
|
||||
}
|
||||
return "\"" + identifier.replace("\"", "\"\"") + "\"";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
if (this.hasOpenConnection()) {
|
||||
|
@ -121,7 +121,7 @@ public void setUp() {
|
||||
// Try to remove the table first. DROP TABLE IF EXISTS didn't
|
||||
// get added until pg 8.3, so we just use "DROP TABLE" and ignore
|
||||
// any exception here if one occurs.
|
||||
st.executeUpdate("DROP TABLE " + TABLE_NAME);
|
||||
st.executeUpdate("DROP TABLE " + manager.escapeTableName(TABLE_NAME));
|
||||
} catch (SQLException e) {
|
||||
LOG.info("Couldn't drop table " + TABLE_NAME + " (ok)");
|
||||
LOG.info(e.toString());
|
||||
@ -129,19 +129,20 @@ public void setUp() {
|
||||
connection.rollback();
|
||||
}
|
||||
|
||||
st.executeUpdate("CREATE TABLE " + TABLE_NAME + " ("
|
||||
+ "id INT NOT NULL PRIMARY KEY, "
|
||||
+ "name VARCHAR(24) NOT NULL, "
|
||||
+ "start_date DATE, "
|
||||
+ "salary FLOAT, "
|
||||
+ "dept VARCHAR(32))");
|
||||
st.executeUpdate("CREATE TABLE " + manager.escapeTableName(TABLE_NAME)
|
||||
+ " ("
|
||||
+ manager.escapeColName("id") + " INT NOT NULL PRIMARY KEY, "
|
||||
+ manager.escapeColName("name") + " VARCHAR(24) NOT NULL, "
|
||||
+ manager.escapeColName("start_date") + " DATE, "
|
||||
+ manager.escapeColName("salary") + " FLOAT, "
|
||||
+ manager.escapeColName("dept") + " VARCHAR(32))");
|
||||
|
||||
st.executeUpdate("INSERT INTO " + TABLE_NAME + " VALUES("
|
||||
+ "1,'Aaron','2009-05-14',1000000.00,'engineering')");
|
||||
st.executeUpdate("INSERT INTO " + TABLE_NAME + " VALUES("
|
||||
+ "2,'Bob','2009-04-20',400.00,'sales')");
|
||||
st.executeUpdate("INSERT INTO " + TABLE_NAME + " VALUES("
|
||||
+ "3,'Fred','2009-01-23',15.00,'marketing')");
|
||||
st.executeUpdate("INSERT INTO " + manager.escapeTableName(TABLE_NAME)
|
||||
+ " VALUES(1,'Aaron','2009-05-14',1000000.00,'engineering')");
|
||||
st.executeUpdate("INSERT INTO " + manager.escapeTableName(TABLE_NAME)
|
||||
+ " VALUES(2,'Bob','2009-04-20',400.00,'sales')");
|
||||
st.executeUpdate("INSERT INTO " + manager.escapeTableName(TABLE_NAME)
|
||||
+ " VALUES(3,'Fred','2009-01-23',15.00,'marketing')");
|
||||
connection.commit();
|
||||
} catch (SQLException sqlE) {
|
||||
LOG.error("Encountered SQL Exception: " + sqlE);
|
||||
|
Loading…
Reference in New Issue
Block a user