= Updated Update statement
This commit is contained in:
@@ -15,6 +15,6 @@ public abstract class JDBCDriver
|
||||
// Executes a SQL command with the database. Returns if it was executed successfully, or in the
|
||||
// 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);
|
||||
public abstract boolean ExecuteStatement(JDBCStatementType type, String command, String[] args);
|
||||
public abstract ResultSet ExecuteReturningStatement(JDBCStatementType type, String command, String[] args);
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@ public class JDBCDriverMySQL extends JDBCDriver
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ExecuteStatement(String statement, String[] args) {
|
||||
public boolean ExecuteStatement(JDBCStatementType type, String statement, String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet ExecuteReturningStatement(String statement, String[] args) {
|
||||
public ResultSet ExecuteReturningStatement(JDBCStatementType type, String statement, String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@ public class JDBCDriverPostgreSQL extends JDBCDriver
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ExecuteStatement(String statement, String[] args) {
|
||||
public boolean ExecuteStatement(JDBCStatementType type, String statement, String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet ExecuteReturningStatement(String statement, String[] args) {
|
||||
public ResultSet ExecuteReturningStatement(JDBCStatementType type, String statement, String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class JDBCDriverSQLite extends JDBCDriver
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet ExecuteReturningStatement(String command, String[] args)
|
||||
public ResultSet ExecuteReturningStatement(JDBCStatementType type, String command, String[] args)
|
||||
{
|
||||
if(connection == null)
|
||||
return null;
|
||||
@@ -79,11 +79,21 @@ public class JDBCDriverSQLite extends JDBCDriver
|
||||
if(args != null && args.length > 0)
|
||||
{
|
||||
PreparedStatement statement = connection.prepareStatement(command);
|
||||
ResultSet set = null;
|
||||
|
||||
for(int i = 0; i < args.length; ++i)
|
||||
statement.setString(i + 1, args[i]);
|
||||
|
||||
ResultSet set = statement.executeQuery();
|
||||
switch(type)
|
||||
{
|
||||
case Select:
|
||||
set = statement.executeQuery();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception("Unsupported statement type for this function!");
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
else
|
||||
@@ -93,7 +103,7 @@ public class JDBCDriverSQLite extends JDBCDriver
|
||||
return set;
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
catch (Exception e)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -108,7 +118,7 @@ public class JDBCDriverSQLite extends JDBCDriver
|
||||
}
|
||||
}
|
||||
|
||||
public boolean ExecuteStatement(String command, String[] args)
|
||||
public boolean ExecuteStatement(JDBCStatementType type, String command, String[] args)
|
||||
{
|
||||
if(connection == null)
|
||||
return false;
|
||||
@@ -120,13 +130,34 @@ public class JDBCDriverSQLite extends JDBCDriver
|
||||
{
|
||||
if(args != null && args.length > 0)
|
||||
{
|
||||
boolean executed = false;
|
||||
PreparedStatement statement = connection.prepareStatement(command);
|
||||
GlobalLog.Log("COMMAND" + command);
|
||||
//GlobalLog.Log("COMMAND IS -- " + command);
|
||||
|
||||
for(int i = 0; i < args.length; ++i)
|
||||
{
|
||||
//GlobalLog.Log("Args: " + args[i]);
|
||||
statement.setString(i + 1, args[i]);
|
||||
|
||||
boolean executed = statement.execute();
|
||||
}
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case Create:
|
||||
executed = statement.executeUpdate() == 1;
|
||||
break;
|
||||
|
||||
case Update:
|
||||
executed = statement.executeUpdate() == 1;
|
||||
break;
|
||||
|
||||
case Insert:
|
||||
executed = statement.executeUpdate() == 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception("Unsupported statement type for this function!");
|
||||
}
|
||||
|
||||
return executed;
|
||||
}
|
||||
else
|
||||
@@ -136,7 +167,7 @@ public class JDBCDriverSQLite extends JDBCDriver
|
||||
return executed;
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
catch (Exception e)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.util.Optional;
|
||||
|
||||
public enum JDBCStatementType
|
||||
{
|
||||
Insert (0), Update(1), Select(2);
|
||||
Insert (0), Update(1), Select(2), Create(4);
|
||||
|
||||
private final int value;
|
||||
private JDBCStatementType(int value)
|
||||
|
||||
Reference in New Issue
Block a user