| 
					
				 | 
			
			
				@@ -9,7 +9,8 @@ import me.km.databank.DataBank; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import me.km.scheduler.SnuviScheduler; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class DatabankCommands { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public static void registerFunctions(ScriptManager sm, SnuviScheduler scheduler, DataBank dataBank) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public static void registerFunctions(ScriptManager sm, SnuviScheduler scheduler, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            DataBank dataBank) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         sm.registerFunction("databank.prepare", (sc, in) -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             PreparedStatement p = dataBank.prepareUnsafeStatement(in[0].getString(sc)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if(in.length <= 1 || in[1].getBoolean(sc)) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -32,12 +33,18 @@ public class DatabankCommands { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         sm.registerConsumer("databank.setbool", (sc, in) -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ((PreparedStatement) in[0].get(sc)).setBoolean(in[1].getInt(sc), in[2].getBoolean(sc)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        sm.registerFunction("databank.getint", (sc, in) -> (double) ((ResultSet) in[0].get(sc)).getInt(in[1].getInt(sc))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        sm.registerFunction("databank.getlong", (sc, in) -> (double) ((ResultSet) in[0].get(sc)).getLong(in[1].getInt(sc))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        sm.registerFunction("databank.getdouble", (sc, in) -> ((ResultSet) in[0].get(sc)).getDouble(in[1].getInt(sc))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        sm.registerFunction("databank.getstring", (sc, in) -> ((ResultSet) in[0].get(sc)).getString(in[1].getInt(sc))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        sm.registerFunction("databank.getbool", (sc, in) -> ((ResultSet) in[0].get(sc)).getBoolean(in[1].getInt(sc))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        sm.registerFunction("databank.execute", (sc, in) -> ((PreparedStatement) in[0].get(sc)).executeQuery()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sm.registerFunction("databank.getint", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                (sc, in) -> (double) ((ResultSet) in[0].get(sc)).getInt(in[1].getInt(sc))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sm.registerFunction("databank.getlong", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                (sc, in) -> (double) ((ResultSet) in[0].get(sc)).getLong(in[1].getInt(sc))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sm.registerFunction("databank.getdouble", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                (sc, in) -> ((ResultSet) in[0].get(sc)).getDouble(in[1].getInt(sc))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sm.registerFunction("databank.getstring", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                (sc, in) -> ((ResultSet) in[0].get(sc)).getString(in[1].getInt(sc))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sm.registerFunction("databank.getbool", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                (sc, in) -> ((ResultSet) in[0].get(sc)).getBoolean(in[1].getInt(sc))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sm.registerFunction("databank.execute", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                (sc, in) -> ((PreparedStatement) in[0].get(sc)).executeQuery()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         sm.registerConsumer("databank.workerexecute", (sc, in) -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             final PreparedStatement p = (PreparedStatement) in[0].get(sc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             StackTrace lines = sc.getStackTrace(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -46,16 +53,18 @@ public class DatabankCommands { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     p.execute(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } catch(SQLException ex) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    scheduler.scheduleTask(() -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        sc.getScriptManager().getLogger().print("Worker error", ex, function, sc.getName(), sc, lines); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    scheduler.scheduleTask("worker execute 1", () -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        sc.getScriptManager().getLogger().print("Worker error", ex, function, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                sc.getName(), sc, lines); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 sc.removeCloseable(p); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     p.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } catch(SQLException ex) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    scheduler.scheduleTask(() -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        sc.getScriptManager().getLogger().print("Worker error", ex, function, sc.getName(), sc, lines); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    scheduler.scheduleTask("worker execute 2", () -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        sc.getScriptManager().getLogger().print("Worker error", ex, function, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                sc.getName(), sc, lines); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }); 
			 |