= Updated core documentation quickly
This commit is contained in:
@@ -12,13 +12,13 @@ import utils.LogFilter;
|
||||
// This is where we put everything and swap out the moving parts,
|
||||
// ie MySQL, PostgreSQL, SQLite, etc...
|
||||
//
|
||||
// TODO(wisp): Right now this can be messed up with SQL injection stuff if users
|
||||
// are allowed to directly touch data. Leaving it like this temporarily.
|
||||
// Right now this can be messed up with SQL injection stuff if users
|
||||
// are allowed to directly touch data. Leaving it like this temporarily,
|
||||
// and is for prototyping only!
|
||||
public class DatabaseDriver
|
||||
{
|
||||
// Config and local varaibles
|
||||
private JDBCDriver driver;
|
||||
|
||||
// Note: Changing these values can mess up the database...
|
||||
private final String globalTableName = "kitty_globals";
|
||||
private final String globalKeyName = "GlobalKey";
|
||||
private final String globalValueName = "GlobalValue";
|
||||
@@ -28,6 +28,7 @@ public class DatabaseDriver
|
||||
driver = null;
|
||||
}
|
||||
|
||||
// Set up and create a table in the database
|
||||
public boolean Connect()
|
||||
{
|
||||
driver = new JDBCDriverSQLite();
|
||||
@@ -54,7 +55,7 @@ public class DatabaseDriver
|
||||
}
|
||||
}
|
||||
|
||||
// the key will be created if it doesn't exist, and the default value returned.
|
||||
// Creates a key. The key will be created if it doesn't exist, and the default value returned.
|
||||
public String CreateGetKey(String key)
|
||||
{
|
||||
GlobalLog.Log(LogFilter.Database, "CreateGeyKey: key-" + key);
|
||||
@@ -71,41 +72,38 @@ public class DatabaseDriver
|
||||
}
|
||||
}
|
||||
|
||||
// Prototype formatting for key updating
|
||||
private void UpdateKey(String key, String value)
|
||||
{
|
||||
//GlobalLog.Log(LogFilter.Database, "Update key " + key);
|
||||
String command = "UPDATE " + globalTableName + " SET " + globalValueName + " = '" + value + "' WHERE " + globalKeyName + "= '" + key + "';";
|
||||
//GlobalLog.Log(LogFilter.Database, "Composed command: " + command);
|
||||
driver.ExecuteStatement(command);
|
||||
}
|
||||
|
||||
// Protoype updating for seeing if a key exists
|
||||
private boolean HasKey(String key)
|
||||
{
|
||||
//GlobalLog.Log(LogFilter.Database, "Has key " + key);
|
||||
String command = "SELECT COUNT(1) as count FROM " + globalTableName + " WHERE " + globalKeyName + " = '" + key + "';";
|
||||
//GlobalLog.Log(LogFilter.Database, "Composed command: " + command);
|
||||
ResultSet set = driver.ExecuteReturningStatement(command);
|
||||
String out = ResultAsString(set, "count");
|
||||
return out.charAt(0) == '1';
|
||||
}
|
||||
|
||||
// Prototype for getting a key
|
||||
private String GetKey(String key)
|
||||
{
|
||||
//GlobalLog.Log(LogFilter.Database, "Getting key " + key);
|
||||
String command = "SELECT " + globalValueName + " as searchedKey FROM " + globalTableName +" WHERE " + globalKeyName + "= \'" + key + "\';";
|
||||
//GlobalLog.Log(LogFilter.Database, "Composed command: " + command);
|
||||
ResultSet set = driver.ExecuteReturningStatement(command);
|
||||
return ResultAsString(set, "searchedKey");
|
||||
}
|
||||
|
||||
// Prototype for creating a key
|
||||
private void CreateKey(String key, String value)
|
||||
{
|
||||
//GlobalLog.Log(LogFilter.Database, "Creating Key " + key);
|
||||
String command = "INSERT INTO " + globalTableName + " (GlobalKey, GlobalValue) VALUES ('" + key + "', '" + value + "');";
|
||||
//GlobalLog.Log(LogFilter.Database, "Composed command: " + command);
|
||||
driver.ExecuteStatement(command);
|
||||
}
|
||||
|
||||
// Transforms a result into a string if possible.
|
||||
private String ResultAsString(ResultSet rs, String key)
|
||||
{
|
||||
if(rs == null)
|
||||
|
||||
Reference in New Issue
Block a user