private static List <Object> pluginResultsToPrimitiveData(SQLitePLuginResult[] results)
        {
            List <Object> list = new List <Object>();

            for (int i = 0; i < results.Count(); i++)
            {
                SQLitePLuginResult result = results[i];
                List <Object>      arr    = convertPluginResultToArray(result);
                list.Add(arr);
            }
            return(list);
        }
        private static List <Object> convertPluginResultToArray(SQLitePLuginResult result)
        {
            List <Object> data = new List <Object>();

            if (result.error != null)
            {
                data.Add(result.error.Message);
            }
            else
            {
                data.Add(null);
            }
            data.Add((long)result.insertId);
            data.Add((int)result.rowsAffected);

            // column names
            data.Add(result.columns);
            data.Add(result.rows);

            return(data);
        }
        public void exec(string dbName, List <JSValue> queriesJS, bool readOnly, IReactPromise <string> promise)
        {
            JArray queries = JArray.FromObject(ParseJsList(queriesJS));

            debug("test called: " + dbName);
            SqliteConnection db = getDatabase(dbName);

            try
            {
                int numQueries = queries.Count;
                SQLitePLuginResult[] results = new SQLitePLuginResult[numQueries];
                if (TRANSACTIONS[dbName] == null)
                {
                    db.Open();
                }
                for (int i = 0; i < numQueries; i++)
                {
                    var    sqlQuery = queries[i];
                    string sql      = sqlQuery[0].ToString();
                    try
                    {
                        if (isSelect(sql))
                        {
                            results[i] = doSelectInBackgroundAndPossiblyThrow(sql, sqlQuery[1].ToList(), db, TRANSACTIONS[dbName]);
                        }
                        else if (isBegin(sql))
                        {
                            //Handle begin without end
                            if (TRANSACTIONS[dbName] != null)
                            {
                                TRANSACTIONS[dbName].Rollback();
                                TRANSACTIONS[dbName].Dispose();
                                TRANSACTIONS[dbName] = null;
                            }
                            TRANSACTIONS[dbName] = db.BeginTransaction();
                            results[i]           = EMPTY_RESULT;
                        }
                        else if (isEnd(sql) || isCommit(sql))
                        {
                            if (TRANSACTIONS[dbName] != null)
                            {
                                TRANSACTIONS[dbName].Commit();
                                TRANSACTIONS[dbName].Dispose();
                                TRANSACTIONS[dbName] = null;
                            }
                            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)
                            {
                                results[i] = new SQLitePLuginResult(EMPTY_ROWS, EMPTY_COLUMNS, 0, 0, new ReadOnlyException());
                            }
                            else
                            {
                                results[i] = doUpdateInBackgroundAndPossiblyThrow(sql, sqlQuery[1].ToList(), db, TRANSACTIONS[dbName]);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        if (RNSqlite2Module.DEBUG_MODE)
                        {
                            Console.WriteLine(e.ToString());
                        }
                        if (TRANSACTIONS[dbName] != null)
                        {
                            TRANSACTIONS[dbName].Rollback();
                            TRANSACTIONS[dbName].Dispose();
                            TRANSACTIONS[dbName] = null;
                        }
                        results[i] = new SQLitePLuginResult(EMPTY_ROWS, EMPTY_COLUMNS, 0, 0, e);
                    }
                }

                List <Object> data = pluginResultsToPrimitiveData(results);
                promise.Resolve(JsonConvert.SerializeObject(data));
            }
            catch (Exception e)
            {
                promise.Reject(new ReactError {
                    Exception = e
                });

                if (TRANSACTIONS[dbName] != null)
                {
                    TRANSACTIONS[dbName].Rollback();
                    TRANSACTIONS[dbName].Dispose();
                    TRANSACTIONS[dbName] = null;
                }
            }
            finally
            {
                if (TRANSACTIONS[dbName] == null)
                {
                    db.Close();
                }
            }
        }