Fixed Maven Error where ID wasn't set as the database did not establish the index before the creation of the table

main
YaFedImYaEatIm 9 years ago
parent 5f576595c0
commit 267a08ce68

Binary file not shown.

@ -139,6 +139,7 @@ public class App extends Application
c.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
e.printStackTrace();
}
}

@ -375,7 +375,7 @@ public class Dataset {
ArrayList<Airline> airlinesToImport = parser.getResult();
//check for dup
int numOfDuplicates = 0;
int nextID = -1;
int nextID = 1;
//query database.
Connection c = null;
Statement stmt = null;
@ -448,7 +448,7 @@ public class Dataset {
ArrayList<Country> countriesToImport = parser.getCountryResult();
//check for dup
int numOfDuplicates = 0;
int nextID = -1;
int nextID = 1;
//query database.
Connection c = null;
Statement stmt = null;
@ -580,7 +580,7 @@ public class Dataset {
ArrayList<Route> routesToImport = parser.getResult();
//check for dup
int numOfDuplicates = 0;
int nextID = -1;
int nextID = 1;
//query database.
Connection c = null;
Statement stmt = null;
@ -654,7 +654,7 @@ public class Dataset {
String message = parser.parse();
ArrayList<FlightPoint> flightPointsToImport = parser.getResult();
//check for dup
int nextID = -1;
int nextID = 1;
//query database.
Connection c = null;
Statement stmt = null;
@ -662,12 +662,13 @@ public class Dataset {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db");
stmt = c.createStatement();
String queryName = this.name.replace("'", "''");
String IDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = '"+queryName+"_Flight_Points' LIMIT 1;";
String queryName = this.name.replace("\"", "\"\"");
String IDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = \""+queryName+"_Flight_Points\" LIMIT 1;";
ResultSet IDResult = stmt.executeQuery(IDQuery);
while(IDResult.next()){
nextID = Integer.parseInt(IDResult.getString("seq")) + 1;//for some reason sqlite3 stores incremental values as a string...
}
System.out.println(nextID);
stmt.close();
stmt = c.createStatement();
//ADDED
@ -728,10 +729,12 @@ public class Dataset {
c.close();
flightPaths.add(flightPathToAdd);
System.out.println(flightPathToAdd.getFlightPoints().get(0).getID());
updateFlightPointInfo(flightPathToAdd);
flightPathDictionary.put(flightPathToAdd.getID(), flightPathToAdd);
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
e.printStackTrace();
System.exit(0);
}
createDataLinks();
@ -1225,7 +1228,7 @@ public class Dataset {
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db");
stmt = c.createStatement();
String flightPointIDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = \""+this.name+"_Flight_Points\" LIMIT 1;";
String flightPointIDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = \""+this.name.replace("\"", "\"\"")+"_Flight_Points\" LIMIT 1;";
ResultSet pointIDRes= stmt.executeQuery(flightPointIDQuery);
while (pointIDRes.next()){
pointID = Integer.parseInt(pointIDRes.getString("seq"));

@ -32,6 +32,11 @@ public class DatasetTest {
fail("The sample file is missing");
}
assertTrue(dataset.getAirlines().size() == dataset.getAirlineDictionary().size());
try {
assertTrue(dataset.getAirlines().get(0).getID() == 1);
} catch (DataException e) {
fail("The first index of Airlines should have an id of 1 as there has been no tampering with the data yet");
}
try {
dataset.importAirport("res/Reduced Samples/Airports.txt");
@ -41,6 +46,11 @@ public class DatasetTest {
assertTrue(dataset.getAirports().size() == dataset.getAirportDictionary().size());
assertTrue(dataset.getCities().size() == dataset.getCityDictionary().size());
assertTrue(dataset.getCountries().size() == dataset.getCountryDictionary().size());
try {
assertTrue(dataset.getAirports().get(0).getID() == 1);
} catch (DataException e) {
fail("The first index of Airports should have an id of 1 as there has been no tampering with the data yet");
}
try {
dataset.importRoute("res/Reduced Samples/Routes.txt");
@ -48,6 +58,11 @@ public class DatasetTest {
fail("The sample file is missing");
}
assertTrue(dataset.getRoutes().size() == dataset.getRouteDictionary().size());
try {
assertTrue(dataset.getRoutes().get(0).getID() == 1);
} catch (DataException e) {
fail("The first index of Routes should have an id of 1 as there has been no tampering with the data yet");
}
try {
dataset.importFlight("res/Reduced Samples/NZCH-WSSS.csv");
@ -55,6 +70,11 @@ public class DatasetTest {
fail("The sample file is missing");
}
assertTrue(dataset.getFlightPaths().size() == dataset.getFlightPathDictionary().size());
try {
assertTrue(dataset.getFlightPaths().get(0).getID() == 1);
} catch (DataException e) {
fail("The first index of Flight Paths should have an id of 1 as there has been no tampering with the data yet");
}
dataset.createDataLinks();
@ -185,6 +205,8 @@ public class DatasetTest {
fail("The sample file is missing");
}
assertTrue(dataset.getFlightPaths().get(0).getFlightPoints().get(0).getID() == 1);
FlightPoint flightPoint = dataset.getFlightPaths().get(0).getFlightPoints().get(6);
FlightPoint flightPoint1 = dataset.getFlightPaths().get(0).getFlightPoints().get(5);
dataset.deleteFlightPoint(1, 5);

Loading…
Cancel
Save