Permalink
Browse files

Implemented multiQuery.

  • Loading branch information...
1 parent 247269d commit bcb6e779eac20128690fe323b666fa60c42ea5fc @Cryptovirus Cryptovirus committed May 12, 2012
Showing with 31 additions and 3 deletions.
  1. +27 −2 Database.java
  2. +4 −1 Makefile
View
@@ -90,12 +90,37 @@ public ResultSet searchMulti(String tableName, String term) throws SQLException
String column = fkeys.get(i);
column = column.subString(0, column.length()-3);
relatives.add(tableMap.get(column));
+ fkeys.set(i, column);
}
// Build the query
String selectQuery = "SELECT * FROM "+tableName;
- for(int i=0; i<relatives.size(); i++){
- selectQuery += " LEFT JOIN " + relatives.
+ for(int i=0; i<fkeys.size(); i++){
+ selectQuery += " LEFT JOIN " + fkeys.get(i) + " ON ("
+ + tableName + "." + fkeys.get(i) + "_id"
+ + " = " + fkeys.get(i) + "."
+ + relatives.get(i).getPKey() + ")";
+ }
+ selectQuery += " WHERE ";
+ for(int i=0; i<columns.size(); i++){
+ selectQuery += tableName + "." + columns.get(i)+" LIKE ? OR ";
+ }
+ for(int i=0; i<fkeys.size(); i++){
+ columns = relatives.get(i).getColumns();
+ for(int j=0; j<columns.size(); j++){
+ selectQuery += fkeys.get(i) + "." + columns.get(j)+" LIKE ? OR ";
+ }
+ }
+ // Remove extra end section
+ selectQuery = selectQuery.substring(0, selectQuery.length()-4);
+ // Create the prepared statement
+ PreparedStatement selectStatement = con.prepareStatement(selectQuery);
+ // Fill in the requisite values
+ for(int i=0; i<columns.size(); i++){
+ selectStatement.setString(i+1, "%"+term+"%");
}
+ // Execute the query and return the result
+ ResultSet result = selectStatement.executeQuery();
+ return result;
}
public ResultSet update(String tableName, ArrayList<String> newValues) throws SQLException {
View
@@ -1,8 +1,11 @@
all: IGDB.java
javac IGDB.java
-run:
+run-win:
java -cp quaqua.jar\;mysql-connector-java-5.1.20-bin.jar\;. IGDB
+
+run-linux:
+ java -cp quaqua.jar\:mysql-connector-java-5.1.20-bin.jar\:. IGDB
clean:
rm *.class

0 comments on commit bcb6e77

Please sign in to comment.