Skip to content

Commit

Permalink
Fix drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
ebocher committed Sep 18, 2020
1 parent a94f2e4 commit b06fb05
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,19 @@ public static void importTable(Connection connection, String fileName, Value opt
boolean deleteTable = false;
if (option instanceof ValueBoolean) {
deleteTable = option.getBoolean();
final String name = URIUtilities.fileFromString(fileName).getName();
String tableName = name.substring(0, name.lastIndexOf(".")).toUpperCase();
if (tableName.matches("^[a-zA-Z][a-zA-Z0-9_]*$")) {
importTable(connection, fileName, tableName, null, deleteTable);
} else {
throw new SQLException("The file name contains unsupported characters");
}
} else if (option instanceof ValueVarchar) {
tableReference = option.getString();
importTable(connection, fileName, tableReference, null, deleteTable);
} else if (!(option instanceof ValueNull)) {
throw new SQLException("Supported optional parameter is boolean or varchar");
}
importTable(connection, fileName, tableReference, null, deleteTable);
}

public static void importTable(Connection connection, String fileName, String tableReference, Value option) throws IOException, SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public SHPRead() {
"\n path of the file, table name"+
"\n path of the file, true for delete the table with the same file name"+
"\n path of the file, table name, true to delete the table name"+
"\n path of the file, table name, true to delete the table name"+
"\n path of the file, table name, encoding chartset"+
"\n path of the file, table name, encoding chartset, true to delete the table name");
}
Expand Down Expand Up @@ -112,12 +111,19 @@ public static void importTable(Connection connection, String fileName, Value opt
boolean deleteTable = false;
if(option instanceof ValueBoolean){
deleteTable = option.getBoolean();
String name = URIUtilities.fileFromString(fileName).getName();
String tableName = name.substring(0, name.lastIndexOf(".")).toUpperCase();
if (tableName.matches("^[a-zA-Z][a-zA-Z0-9_]*$")) {
importTable(connection, fileName, tableName, null, deleteTable);
} else {
throw new SQLException("The file name contains unsupported characters");
}
}else if (option instanceof ValueVarchar){
tableReference = option.getString();
importTable(connection, fileName, tableReference, null, false);
}else if (!(option instanceof ValueNull)){
throw new SQLException("Supported optional parameter is boolean or varchar");
}
importTable(connection, fileName, tableReference, null, false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,12 @@ public void exportQueryImportFileOption() throws SQLException, IOException {
stat.execute("DROP TABLE IF EXISTS IMPORT_LINEAL;");
stat.execute("CALL GeoJSONRead('target/lineal_export.geojson', 'IMPORT_LINEAL', true)");

try (ResultSet res = stat.executeQuery("SELECT COUNT(*) FROM IMPORT_LINEAL;")) {
res.next();
assertEquals(1, res.getInt(1));
}
stat.execute("CALL GeoJSONRead('target/lineal_export.geojson', true)");

try (ResultSet res = stat.executeQuery("SELECT COUNT(*) FROM IMPORT_LINEAL;")) {
res.next();
assertEquals(1, res.getInt(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,14 @@ public void testSelectWriteRead2() throws Exception {
GeometryAsserts.assertGeometryEquals("SRID=4326;MULTIPOLYGON (((0 10.000000000000007, 0.19214719596769747 11.950903220161292, 0.7612046748871375 13.826834323650909, 1.6853038769745545 15.555702330196034, 2.928932188134537 17.071067811865486, 4.444297669803992 18.314696123025463, 6.173165676349122 19.238795325112875, 8.04909677983874 19.807852804032308, 10.000000000000025 20, 11.950903220161308 19.8078528040323, 13.826834323650925 19.238795325112857, 15.555702330196048 18.314696123025435, 17.071067811865497 17.07106781186545, 18.31469612302547 15.555702330195993, 19.238795325112882 13.826834323650862, 19.80785280403231 11.950903220161244, 20 10, 19.807852804032304 8.049096779838717, 19.238795325112868 6.173165676349102, 18.314696123025453 4.444297669803978, 17.071067811865476 2.9289321881345254, 15.555702330196024 1.6853038769745474, 13.826834323650898 0.7612046748871322, 11.950903220161283 0.1921471959676957, 10 0, 8.049096779838719 0.1921471959676957, 6.173165676349103 0.7612046748871322, 4.44429766980398 1.6853038769745474, 2.9289321881345254 2.9289321881345245, 1.6853038769745474 4.444297669803978, 0.7612046748871322 6.173165676349106, 0.19214719596769392 8.049096779838722, 0 10.000000000000007)))",geom);
res.close();
stat.execute("DROP TABLE IF EXISTS TABLE_POINTS_READ");
stat.execute("CALL SHPRead('target/points.shp', true);");
res = stat.executeQuery("SELECT * FROM POINTS;");
res.next();
geom = (Geometry) res.getObject("THE_GEOM");
assertEquals(4326, geom.getSRID());
GeometryAsserts.assertGeometryEquals("SRID=4326;MULTIPOLYGON (((0 10.000000000000007, 0.19214719596769747 11.950903220161292, 0.7612046748871375 13.826834323650909, 1.6853038769745545 15.555702330196034, 2.928932188134537 17.071067811865486, 4.444297669803992 18.314696123025463, 6.173165676349122 19.238795325112875, 8.04909677983874 19.807852804032308, 10.000000000000025 20, 11.950903220161308 19.8078528040323, 13.826834323650925 19.238795325112857, 15.555702330196048 18.314696123025435, 17.071067811865497 17.07106781186545, 18.31469612302547 15.555702330195993, 19.238795325112882 13.826834323650862, 19.80785280403231 11.950903220161244, 20 10, 19.807852804032304 8.049096779838717, 19.238795325112868 6.173165676349102, 18.314696123025453 4.444297669803978, 17.071067811865476 2.9289321881345254, 15.555702330196024 1.6853038769745474, 13.826834323650898 0.7612046748871322, 11.950903220161283 0.1921471959676957, 10 0, 8.049096779838719 0.1921471959676957, 6.173165676349103 0.7612046748871322, 4.44429766980398 1.6853038769745474, 2.9289321881345254 2.9289321881345245, 1.6853038769745474 4.444297669803978, 0.7612046748871322 6.173165676349106, 0.19214719596769392 8.049096779838722, 0 10.000000000000007)))",geom);
res.close();
stat.execute("DROP TABLE IF EXISTS POINTS");
}
}

Expand Down

0 comments on commit b06fb05

Please sign in to comment.