Core/DB: Some DB improvements

This commit is contained in:
hondacrx
2018-05-22 11:05:16 -04:00
parent 0be2dc08e2
commit dbd62e5c6f
23 changed files with 360 additions and 294 deletions
+38 -2
View File
@@ -16,11 +16,15 @@
*/
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Framework.Database
{
public class PreparedStatement
{
public string CommandText;
public Dictionary<int, object> Parameters = new Dictionary<int, object>();
public PreparedStatement(string commandText)
{
CommandText = commandText;
@@ -35,8 +39,40 @@ namespace Framework.Database
{
Parameters.Clear();
}
}
public string CommandText;
public Dictionary<int, object> Parameters = new Dictionary<int, object>();
public class PreparedStatementTask : ISqlOperation
{
PreparedStatement m_stmt;
bool _needsResult;
TaskCompletionSource<SQLResult> m_result;
public PreparedStatementTask(PreparedStatement stmt, bool needsResult = false)
{
m_stmt = stmt;
_needsResult = needsResult;
if (needsResult)
m_result = new TaskCompletionSource<SQLResult>();
}
public bool Execute<T>(MySqlBase<T> mySqlBase)
{
if (_needsResult)
{
SQLResult result = mySqlBase.Query(m_stmt);
if (result == null)
{
m_result.SetResult(new SQLResult());
return false;
}
m_result.SetResult(result);
return true;
}
return mySqlBase.DirectExecute(m_stmt);
}
public Task<SQLResult> GetFuture() { return m_result.Task; }
}
}