Example #1
0
        // This method will be used to execute the statement, but will only be called by another method in the class.
        private void InternalExecution()
        {
            try
            {
                // Set the Select Listener with Cloud Sync.
                CloudSync.SetSelectListener(this);
                // Here we will Execute the Query.
                // Reset the Session so it is clean.
                if (IsSuccessful())
                {
                    SQLiteCommand dbSess = cdb.GetSession();
                    dbSess.Reset();
                    // Create the SQL Statement.
                    string sql = GetSQL();
                    dbSess.CommandText = sql;

                    // Bind the Params.
                    foreach (string paramName in bindObjs.Keys)
                    {
                        // Bind the Params.
                        SQLiteParameter sqlParam = new SQLiteParameter(paramName, bindObjs[paramName]);
                        // Add the Param to the Command.
                        dbSess.Parameters.Add(sqlParam);
                    }
                    // Lets prepare the statement.
                    dbSess.Prepare();
                    // Lets Execute the Query.
                    SQLiteDataReader sdr = dbSess.ExecuteReader();
                    // Check if the user is waiting for the result.
                    onDataResult?.Invoke(CloudDB.SQLiteReaderToRows(sdr));
                }
                else
                {
                    // The Select was not Successful.
                    onDataResult?.Invoke(new List <Row>());
                }
            }
            catch (Exception e)
            {
                // There was an Error.
                AddStatus("Execution Err : " + e.StackTrace + " ::: " + e.Message);
                onDataResult?.Invoke(new List <Row>());
            }
        }
Example #2
0
        // This method will handle the actual execution and will me called.
        private void InternalExecutor()
        {
            try
            {
                // Here we will Execute the Query.
                if (IsSuccessful())
                {
                    SQLiteCommand dbSess = cdb.GetSession();

                    // Lets set the deleted time. (This will be used to reject any deletes trying to be run twice)
                    deletedTimeI = Helper.CurrentTimeMillis();

                    try
                    {
                        // Here we will Generate the SQL Statement.
                        // Add the RLS System.
                        if (CloudDB.IsSyncable(tableName))
                        {
                            // The table required RLS.
                            if (rlsID == 0)
                            {
                                // The user should not be allowed to execute this statement.
                                AddStatus("RLS NOT Provided");
                            }
                            else
                            {
                                // The RLS is Provided
                                AddWhere(new Where("rls_id_", Where.Type.EQUAL, rlsID));
                                AddWhere(new Where("rls_type_", Where.Type.EQUAL, rlsType));
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        // There was an Error.
                        isError = true;
                        AddStatus("SQL Security : " + e.Message);
                    }

                    // Lets create the Statement.
                    dbSess.CommandText = GetSQL();
                    // Bind the Params of the Where clause.
                    foreach (string paramName in whereBindObjs.Keys)
                    {
                        // Bind the Params.
                        SQLiteParameter sqlParam = new SQLiteParameter(paramName, whereBindObjs[paramName]);
                        // Add the Param to the Command.
                        dbSess.Parameters.Add(sqlParam);
                    }
                    // Lets prepare the statement.
                    dbSess.Prepare();
                    // Lets Get the Data that will be deleted.
                    List <Row> deletedRows = new List <Row>();
                    try
                    {
                        // Lets get the updated rows.
                        // Lets Create the Statement to read from the updated table.
                        StringBuilder sqlBuilder = new StringBuilder();
                        sqlBuilder.Append("SELECT * FROM ")
                        .Append(tableName)
                        .Append(" WHERE ")
                        .Append(whereClauseBuilder);
                        // Lets Get the Session Object.
                        SQLiteCommand readSess = cdb.GetSession();
                        // Create the Statement.
                        readSess.CommandText = sqlBuilder.ToString();
                        // Bind the Columns Params.
                        foreach (string paramName in whereBindObjs.Keys)
                        {
                            // Bind the Params.
                            SQLiteParameter sqlParam = new SQLiteParameter(paramName, whereBindObjs[paramName]);
                            // Add the Param to the Command.
                            readSess.Parameters.Add(sqlParam);
                        }
                        // Lets Prepare the Statement.
                        readSess.Prepare();
                        // Lets execute the query.
                        SQLiteDataReader sdr = readSess.ExecuteReader();
                        // Lets read the data and add the data to the Rows List.
                        deletedRows = CloudDB.SQLiteReaderToRows(sdr);
                        // Reset the Session.
                        readSess.Reset();
                    }
                    catch (Exception e)
                    {
                        // There was an Error.
                    }
                    // Lets Execute the Query.
                    // The user is not asking to create a reader, just to insert the value.
                    int deletedRowsNum = dbSess.ExecuteNonQuery();

                    // Send to the Receiver if the user has set a insert result listener.
                    onDataDeleted?.Invoke(deletedRows);

                    try
                    {
                        // Checking about the deleted rows.
                        if (deletedRows.Count == deletedRowsNum)
                        {
                            AddStatus("All the Deletes worked perfectly.");
                        }
                        else if (deletedRows.Count > deletedRowsNum)
                        {
                            AddStatus("All the Rows Required didn't get deleted");
                        }
                        else
                        {
                            AddStatus("All the Rows Deleted, have not been sent to the user.");
                        }
                    } catch (Exception er)
                    {
                        // There was an Error
                    }

                    // Reset the Session if another similar query is to be run.
                    dbSess.Dispose();

                    // If the data is to be synced with the server, we will sync it with the server.
                    if (syncable && deletedRowsNum > 0)
                    {
                        // The data is to be synced with the Cloud Server.
                        CloudSync.Sync(this, deletedRows);
                    }
                }
                else
                {
                    // The Delete System Failed somewhere.
                    AddStatus("Err : Delete Failure");
                }
            }
            catch (Exception e)
            {
                // There was an Error.
                AddStatus("Err : " + e.Message + " : " + e.StackTrace);
            }
        }