Skip to content

Commit

Permalink
Merge pull request #7 from zerglingno1/master
Browse files Browse the repository at this point in the history
Add case commit, rollback and correct exception throw
  • Loading branch information
hnq90 committed Jul 17, 2017
2 parents 6cc2635 + 3142683 commit b6692e2
Showing 1 changed file with 22 additions and 2 deletions.
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

0 comments on commit b6692e2

Please sign in to comment.