好吧,我已经在sqlite脚本上创建了一个功能插件。问题是当我尝试在线程上执行此操作时。我没有错误消息,代码没有传递行#34;使用(_dbTransaction = dbConnection.BeginTransaction())"。以下是代码(OBS:我使用Unity 5.3.2p1):
private void CheckExistingDataThread(string p_tableName, List<Dictionary<string, string>> p_listData, string[] p_whereKeys)
{
Debug.Log("CheckExistingDataThread");
using (_dbConnection = new SqliteConnection(_dbURI))
{
Debug.Log("Database Loaded");
using (_dbCommand = _dbConnection.CreateCommand())
{
Debug.Log("Command Created");
using (_dbTransaction = _dbConnection.BeginTransaction())
{
Debug.Log("Transaction Started");
_dbCommand.Connection = _dbConnection;
_dbCommand.Transaction = _dbTransaction;
for (int i = 0; i < p_listData.Count; i ++)
{
string __sql = string.Empty;
__sql = "SELECT COUNT() FROM " + p_tableName + " WHERE ";
for (int k = 0; k < p_whereKeys.Length; k ++)
{
if (k < p_whereKeys.Length - 1)
{
__sql += p_whereKeys[k] + " = \"" + p_listData[i][p_whereKeys[k]] + "\" AND ";
}
else
{
__sql += p_whereKeys[k] + " = \"" + p_listData[i][p_whereKeys[k]] + "\"";
}
}
//Debug.Log(__sql);
_dbCommand.CommandText = __sql;
try
{
using (_dbReader = _dbCommand.ExecuteReader())
{
while(_dbReader.Read())
{
int __value = _dbReader.GetInt32(0);
if (__value > 0)
{
UpdateTableData(p_tableName, p_listData[i], p_whereKeys);
}
else
{
InsertTableData(p_tableName, p_listData[i]);
}
}
}
}
catch(SqliteException sqle)
{
Debug.Log("Exception " + sqle);
}
}
}
_dbTransaction.Commit();
}
_dbConnection.Close();
}
}