Merge branch 'develop'

This commit is contained in:
Alex
2019-05-20 14:30:00 -04:00
6 changed files with 89 additions and 39 deletions
+9 -9
View File
@@ -35,7 +35,7 @@ public class DatabaseDriver
driver.Connect();
// Require a global table if it doesn't exist already
driver.ExecuteStatement("CREATE TABLE IF NOT EXISTS " + globalTableName + " (" + globalKeyName + " text PRIMARY KEY, " + globalValueName + " text);");
driver.ExecuteStatement("CREATE TABLE IF NOT EXISTS " + globalTableName + " (" + globalKeyName + " text PRIMARY KEY, " + globalValueName + " text);", null);
return true;
}
@@ -75,15 +75,15 @@ public class DatabaseDriver
// Prototype formatting for key updating
private void UpdateKey(String key, String value)
{
String command = "UPDATE " + globalTableName + " SET " + globalValueName + " = '" + value + "' WHERE " + globalKeyName + "= '" + key + "';";
driver.ExecuteStatement(command);
String command = "UPDATE " + globalTableName + " SET " + globalValueName + " = ? WHERE " + globalKeyName + " = ?;";
driver.ExecuteStatement(command, new String[] { key, value });
}
// Protoype updating for seeing if a key exists
private boolean HasKey(String key)
{
String command = "SELECT COUNT(1) as count FROM " + globalTableName + " WHERE " + globalKeyName + " = '" + key + "';";
ResultSet set = driver.ExecuteReturningStatement(command);
String command = "SELECT COUNT(1) as count FROM " + globalTableName + " WHERE " + globalKeyName + " = ?;";
ResultSet set = driver.ExecuteReturningStatement(command, new String[] { key });
String out = ResultAsString(set, "count");
return out.charAt(0) == '1';
}
@@ -91,16 +91,16 @@ public class DatabaseDriver
// Prototype for getting a key
private String GetKey(String key)
{
String command = "SELECT " + globalValueName + " as searchedKey FROM " + globalTableName +" WHERE " + globalKeyName + "= \'" + key + "\';";
ResultSet set = driver.ExecuteReturningStatement(command);
String command = "SELECT " + globalValueName + " as searchedKey FROM " + globalTableName +" WHERE " + globalKeyName + " = ?;";
ResultSet set = driver.ExecuteReturningStatement(command, new String[] { key });
return ResultAsString(set, "searchedKey");
}
// Prototype for creating a key
private void CreateKey(String key, String value)
{
String command = "INSERT INTO " + globalTableName + " (GlobalKey, GlobalValue) VALUES ('" + key + "', '" + value + "');";
driver.ExecuteStatement(command);
String command = "INSERT INTO " + globalTableName + " (GlobalKey, GlobalValue) VALUES (?, ?);";
driver.ExecuteStatement(command, new String[] { key, value });
}
// Transforms a result into a string if possible.
+23 -7
View File
@@ -1,5 +1,6 @@
package dataStructures;
import java.util.Iterator;
import java.util.Vector;
import core.DatabaseTrackedObject;
@@ -23,15 +24,30 @@ public class KittyTrackedVector extends DatabaseTrackedObject
databaseID = differentiator + readableName + UniqueID;
}
// Mirrored behavior
public boolean contains(String role)
// See if the string is contined in the vector, regardless of case.
public boolean containsIgnoreCase(String str)
{
return allowedRole.contains(role);
Iterator<String> value = allowedRole.iterator();
while (value.hasNext())
{
if(value.next().equalsIgnoreCase(str))
return true;
}
public void add(String role)
return false;
}
// Mirrored behavior
public boolean contains(String str)
{
allowedRole.add(role);
return allowedRole.contains(str);
}
public void add(String str)
{
allowedRole.add(str);
this.MarkDirty();
}
@@ -50,9 +66,9 @@ public class KittyTrackedVector extends DatabaseTrackedObject
return allowedRole.get(index);
}
public void remove(String role)
public void remove(String str)
{
allowedRole.remove(role);
allowedRole.remove(str);
this.MarkDirty();
}
+4 -3
View File
@@ -13,7 +13,8 @@ public abstract class JDBCDriver
public abstract boolean Disconnect();
// Executes a SQL command with the database. Returns if it was executed successfully, or in the
// case of the returning statement, returns the ResultSet.
public abstract boolean ExecuteStatement(String statement);
public abstract ResultSet ExecuteReturningStatement(String statement);
// case of the returning statement, returns the ResultSet. Args are placed into the prepared statement
// in place of each '?' places into it.
public abstract boolean ExecuteStatement(String command, String[] args);
public abstract ResultSet ExecuteReturningStatement(String command, String[] args);
}
+2 -2
View File
@@ -17,13 +17,13 @@ public class JDBCDriverMySQL extends JDBCDriver
}
@Override
public boolean ExecuteStatement(String statement) {
public boolean ExecuteStatement(String statement, String[] args) {
// TODO Auto-generated method stub
return false;
}
@Override
public ResultSet ExecuteReturningStatement(String statement) {
public ResultSet ExecuteReturningStatement(String statement, String[] args) {
// TODO Auto-generated method stub
return null;
}
+2 -2
View File
@@ -17,13 +17,13 @@ public class JDBCDriverPostgreSQL extends JDBCDriver
}
@Override
public boolean ExecuteStatement(String statement) {
public boolean ExecuteStatement(String statement, String[] args) {
// TODO Auto-generated method stub
return false;
}
@Override
public ResultSet ExecuteReturningStatement(String statement) {
public ResultSet ExecuteReturningStatement(String statement, String[] args) {
// TODO Auto-generated method stub
return null;
}
+47 -14
View File
@@ -3,6 +3,7 @@ package network;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
@@ -63,54 +64,86 @@ public class JDBCDriverSQLite extends JDBCDriver
}
@Override
public ResultSet ExecuteReturningStatement(String sql)
public ResultSet ExecuteReturningStatement(String command, String[] args)
{
if(connection == null)
return null;
if(sql == null || sql.length() == 0)
if(command == null || command.length() == 0)
return null;
try
{
Statement statement = connection.createStatement();
ResultSet set = statement.executeQuery(sql);
if(args != null && args.length > 0)
{
PreparedStatement statement = connection.prepareStatement(command);
for(int i = 0; i < args.length; ++i)
statement.setString(i + 1, args[i]);
ResultSet set = statement.executeQuery();
return set;
}
else
{
Statement statement = connection.createStatement();
ResultSet set = statement.executeQuery(command);
return set;
}
}
catch (SQLException e)
{
try {
try
{
GlobalLog.Fatal(e.getMessage());
} catch (Exception e1) {
// TODO Auto-generated catch block
}
catch (Exception e1)
{
e1.printStackTrace();
}
return null;
}
}
public boolean ExecuteStatement(String sql)
public boolean ExecuteStatement(String command, String[] args)
{
if(connection == null)
return false;
if(sql == null || sql.length() == 0)
if(command == null || command.length() == 0)
return false;
try
{
Statement statement = connection.createStatement();
boolean executed = statement.execute(sql);
if(args != null && args.length > 0)
{
PreparedStatement statement = connection.prepareStatement(command);
for(int i = 0; i < args.length; ++i)
statement.setString(i + 1, args[i]);
boolean executed = statement.execute();
return executed;
}
else
{
Statement statement = connection.createStatement();
boolean executed = statement.execute(command);
return executed;
}
}
catch (SQLException e)
{
try {
try
{
GlobalLog.Fatal(e.getMessage());
} catch (Exception e1) {
// TODO Auto-generated catch block
}
catch (Exception e1)
{
e1.printStackTrace();
}
return false;
}
}