Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add case commit, rollback and correct exception throw #7

Merged
merged 1 commit into from
Jul 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 22 additions & 2 deletions windows/RNSqlite2Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ private static bool isEnd(String str)
return str.TrimStart().StartsWith("end", StringComparison.OrdinalIgnoreCase);
}

private static bool isCommit(String str)
{
return str.TrimStart().StartsWith("commit", StringComparison.OrdinalIgnoreCase);
}

private static bool isRollback(String str)
{
return str.TrimStart().StartsWith("rollback", StringComparison.OrdinalIgnoreCase);
}

[ReactMethod]
public void exec(string dbName, JArray queries, bool readOnly, IPromise promise)
{
Expand Down Expand Up @@ -171,7 +181,7 @@ public void exec(string dbName, JArray queries, bool readOnly, IPromise promise)
TRANSACTIONS[dbName] = db.BeginTransaction();
results[i] = EMPTY_RESULT;
}
else if (isEnd(sql))
else if (isEnd(sql) || isCommit(sql))
{
if (TRANSACTIONS[dbName] != null)
{
Expand All @@ -181,6 +191,16 @@ public void exec(string dbName, JArray queries, bool readOnly, IPromise promise)
}
results[i] = EMPTY_RESULT;
}
else if (isRollback(sql))
{
if (TRANSACTIONS[dbName] != null)
{
TRANSACTIONS[dbName].Rollback();
TRANSACTIONS[dbName].Dispose();
TRANSACTIONS[dbName] = null;
}
results[i] = EMPTY_RESULT;
}
else
{ // update/insert/delete
if (readOnly)
Expand Down Expand Up @@ -407,7 +427,7 @@ private static List<Object> convertPluginResultToArray(SQLitePLuginResult result
catch (Exception e)
{
debug("insert or update or delete error", e.Message);
return EMPTY_RESULT;
throw new Exception(e.Message);
}
finally
{
Expand Down