public static IAsyncOperation <string> executeSql(long connectionId, [ReadOnlyArray()] object[] args)
        {
            return(Task.Run <string>(() =>
            {
                try
                {
                    var query = (string)args[0];
                    var queryParams = (object[])args[1];

                    var connection = SQLiteConnectionManager.GetConnecionById(connectionId);

                    var cmd = connection.CreateCommand(query, queryParams);
                    List <Dictionary <string, object> > rows = cmd.ExecuteQuery <Dictionary <string, object> >();

                    var resultSet = new SqlResultSet();
                    for (var i = 0; i < rows.Count; i++)
                    {
                        resultSet.Rows.Add(ReadResultSetRow(rows[i]));
                    }

                    resultSet.RowsAffected = SQLite3.Changes(connection.Handle);
                    resultSet.InsertId = SQLite3.LastInsertRowid(connection.Handle);
                    return Serialize(typeof(SqlResultSet), resultSet);
                }
                catch (Exception ex)
                {
                    // You can't access the original message text from JavaScript code.
                    // http://msdn.microsoft.com/en-US/library/windows/apps/br230301.aspx#ThrowingExceptions
                    // so we return it via custom object
                    return Serialize(typeof(InvocationError), new InvocationError(ex));
                }
            }).AsAsyncOperation());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes SQL query.
        /// </summary>
        /// <param name="options"></param>
        public void executeSql(string options)
        {
            lock (_locker)
            {
                var args       = JsonHelper.Deserialize <List <string> >(options);
                var callbackId = args[3];
                try
                {
                    var connectionId = int.Parse(args[0]);

                    var query       = args[1];
                    var queryParams = string.IsNullOrEmpty(args[2])
                        ? new object[0]
                        : JsonHelper.Deserialize <object[]>(args[2]);

                    var resultSet   = new SqlResultSet();
                    var dbResultSet = _dbConnections[connectionId].Query2(query, queryParams);

                    resultSet.RowColumns.AddRange(dbResultSet.ColumnNames);
                    foreach (var row in dbResultSet)
                    {
                        resultSet.Rows.Add(row.Values);
                    }

                    resultSet.InsertId     = SQLite3.LastInsertRowid(_dbConnections[connectionId].Handle);
                    resultSet.RowsAffected = SQLite3.Changes(_dbConnections[connectionId].Handle);
                    DispatchCommandResult(new PluginResult(PluginResult.Status.OK, resultSet), callbackId);
                }
                catch (Exception ex)
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new SQliteError(ex)), callbackId);
                }
            }
        }
Ejemplo n.º 3
0
        public static string executeSql(long connectionId, [ReadOnlyArray()] object[] args)
        {
            try
            {
                var query       = (string)args[0];
                var queryParams = (object[])args[1];

                var cmd = _dbConnections[connectionId].CreateCommand();
                cmd.CommandText = query;
                foreach (var queryParam in queryParams)
                {
                    var parameter = cmd.CreateParameter();
                    parameter.Value = queryParam;
                    cmd.Parameters.Add(parameter);
                }

                var reader = cmd.ExecuteReader();

                var resultSet = new SqlResultSet();
                while (reader.Read())
                {
                    resultSet.Rows.Add(ReadResultSetRow(reader));
                }

                resultSet.RowsAffected = reader.RecordsAffected;
                resultSet.InsertId     = _dbConnections[connectionId].LastInsertRowId;
                return(Serialize(typeof(SqlResultSet), resultSet));
            }
            catch (Exception ex)
            {
                // You can't access the original message text from JavaScript code.
                // http://msdn.microsoft.com/en-US/library/windows/apps/br230301.aspx#ThrowingExceptions
                // so we return it via custom object
                return(Serialize(typeof(InvocationError), new InvocationError(ex)));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Executes SQL query.
        /// </summary>
        /// <param name="options"></param>
        public void executeSql(string options)
        {
            lock (_locker)
            {
                var args = JsonHelper.Deserialize<List<string>>(options);
                var callbackId = args[3];
                try
                {
                    var connectionId = int.Parse(args[0]);

                    var query = args[1];
                    var queryParams = string.IsNullOrEmpty(args[2])
                        ? new object[0]
                        : JsonHelper.Deserialize<object[]>(args[2]);

                    var resultSet = new SqlResultSet();
                    var dbResultSet = _dbConnections[connectionId].Query2(query, queryParams);

                    resultSet.RowColumns.AddRange(dbResultSet.ColumnNames);
                    foreach (var row in dbResultSet)
                    {
                        resultSet.Rows.Add(row.Values);
                    }

                    resultSet.InsertId = SQLite3.LastInsertRowid(_dbConnections[connectionId].Handle);
                    resultSet.RowsAffected = SQLite3.Changes(_dbConnections[connectionId].Handle);
                    DispatchCommandResult(new PluginResult(PluginResult.Status.OK, resultSet), callbackId);
                }
                catch (Exception ex)
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new SQliteError(ex)), callbackId);
                }
            }
        }