Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix driver signatures #1120

Merged
merged 10 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public String getJavaStaticMethod() {
*/
public static void readAscii(Connection connection, String fileName) throws IOException, SQLException {
final String name = URIUtilities.fileFromString(fileName).getName();
String tableName = name.substring(0, name.lastIndexOf(".")).toUpperCase();
String tableName = name.substring(0, name.lastIndexOf(".")).toUpperCase().replace(".", "_");
if (tableName.matches("^[a-zA-Z][a-zA-Z0-9_]*$")) {
readAscii(connection, fileName, ValueVarchar.get(tableName));
} else {
Expand All @@ -91,7 +91,7 @@ public static void readAscii(Connection connection, String fileName, Value optio
Geometry envelope = null;
if (option instanceof ValueInteger) {
zType = option.getInt();
if (zType != 1 || zType != 2) {
if (!(zType == 1 || zType == 2)) {
throw new SQLException("Please use 1 for integer or 2 for double conversion");
}
} else if (option instanceof ValueVarchar) {
Expand Down Expand Up @@ -139,7 +139,7 @@ public static void readAscii(Connection connection, String fileName, String tabl
Geometry envelope = null;
if (option instanceof ValueInteger) {
zType = option.getInt();
if (zType != 1 || zType != 2) {
if (!(zType == 1 || zType == 2)) {
throw new SQLException("Please use 1 for integer or 2 for double conversion");
}
} else if (option instanceof ValueBoolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class AscReaderDriver {
private double xValue;
private boolean readFirst;
private double noData;
private int zType = 1;
private int zType = 2;
private boolean deleteTable = false;
private String encoding = "UTF-8";
private boolean importNodata = false;
Expand Down Expand Up @@ -281,7 +281,6 @@ private void readAsc(Connection connection, InputStream inputStream, ProgressVis
} else {
if (zType == 1) {
st.execute("CREATE TABLE " + requestedTable.toString(isH2) + "(PK SERIAL PRIMARY KEY, THE_GEOM GEOMETRY(POLYGONZ, " + srid + "),Z integer)");

} else {
st.execute("CREATE TABLE " + requestedTable.toString(isH2) + "(PK SERIAL PRIMARY KEY, THE_GEOM GEOMETRY(POLYGONZ, " + srid + "),Z double precision)");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public void exportTable(Connection connection, String tableReference, File fileN
if(deleteFiles){
Files.deleteIfExists(fileName.toPath());
}
else if(fileName.exists()){
throw new IOException("The CSV file already exist.");
}
String regex = ".*(?i)\\b(select|from)\\b.*";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(tableReference);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public void exportTable(Connection connection, String tableReference, File fileN
if(deleteFiles){
Files.deleteIfExists(fileName.toPath());
}
else if (fileName.exists()) {
throw new IOException("The dbf file already exist.");
}
String regex = ".*(?i)\\b(select|from)\\b.*";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(tableReference);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public String getJavaStaticMethod() {

public static void importTable(Connection connection, String fileName) throws IOException, SQLException {
final String name = URIUtilities.fileFromString(fileName).getName();
String tableName = name.substring(0, name.lastIndexOf(".")).toUpperCase();
String tableName = name.substring(0, name.lastIndexOf(".")).replace(".", "_").toUpperCase();
if (tableName.matches("^[a-zA-Z][a-zA-Z0-9_]*$")) {
importTable(connection, fileName, tableName, null, false);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public GeoJsonRead() {
+ "\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 All @@ -67,7 +66,7 @@ public String getJavaStaticMethod() {
*/
public static void importTable(Connection connection, String fileName) throws IOException, SQLException {
final String name = URIUtilities.fileFromString(fileName).getName();
String tableName = name.substring(0, name.lastIndexOf(".")).toUpperCase();
String tableName = name.substring(0, name.lastIndexOf(".")).replace(".", "_").toUpperCase();
if (tableName.matches("^[a-zA-Z][a-zA-Z0-9_]*$")) {
importTable(connection, fileName, tableName, null, false);
} else {
Expand All @@ -89,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 @@ -84,6 +84,8 @@ public class GeoJsonReaderDriver {
*
* @param connection
* @param fileName
* @param encoding
* @param deleteTable
*/
public GeoJsonReaderDriver(Connection connection, File fileName, String encoding, boolean deleteTable) {
this.connection = connection;
Expand Down
Loading