예제 #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>());
            }
        }
예제 #2
0
 // Execute the Query.
 public bool Execute()
 {
     try
     {
         // Lets now execute the query.
         // Here we will Execute the Query.
         if (statement != null)
         {
             // Lets now run the Statement.
             SQLiteCommand dbSess = cdb.GetSession();
             // Reset the Session so it is clean.
             dbSess.Reset();
             // Create the SQL Statement.
             Console.WriteLine("Statement : " + statement);
             dbSess.CommandText = statement;
             Console.WriteLine("Execution CommandText");
             // Lets prepare the statement.
             dbSess.Prepare();
             Console.WriteLine("Execution Prepared");
             // Lets Execute the Query.
             int created = dbSess.ExecuteNonQuery();
             Console.WriteLine("Execution Completed : " + created);
             dbSess.Dispose();
             Console.WriteLine("Execution Disposed");
             AddStatus("Execution Completed");
             return(created >= 0);
         }
         else
         {
             // The Statement was empty.
             return(false);
         }
     }
     catch (Exception e)
     {
         // There was an Error.
         AddStatus("Execution Err : " + e.Message);
         Console.WriteLine("Execution Err : " + e.Message);
         return(false);
     }
 }
예제 #3
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);
            }
        }
예제 #4
0
        // Here we will run an internal executor to run the actual execution of the statement.
        private int InternalExecutor()
        {
            try
            {
                // Here we will Execute the Statement, and bind the Params.
                // Lets create the Statement.
                if (IsSuccessful())
                {
                    // Reset the Session So if Any uncompleted Call does'nt interupt this call.
                    SQLiteCommand dbSess = cdb.GetSession();
                    dbSess.Reset();

                    // Check if the table is a syncable table.
                    if (CloudDB.IsSyncable(tableName))
                    {
                        // The table is a syncable table.
                        // Lets Add the RLS system.
                        if (rlsID == 0 || rlsType == 0)
                        {
                            // The table is a syncable table, but the RLS Values are not provided.
                            // So we will not let it complete the process.
                            isError = true;
                            AddStatus("User NOT Authenticated to Write in this RLS");
                        }
                        else
                        {
                            // The user has provided the RLS Data.
                            PutColumnInternal(new ColumnData("rls_id_", rlsID));
                            PutColumnInternal(new ColumnData("rls_type_", rlsType));
                        }

                        // Now lets generate the Sync ID.
                        if (GetSyncID() == null || GetSyncID().Trim().Length != 36)
                        {
                            // The sync id has not been set.
                            // Lets set it.
                            SetSyncID(Guid.NewGuid().ToString());
                        }
                        PutColumnInternal(new ColumnData("sync_id_", GetSyncID()));

                        // Lets set the Update Time.
                        try
                        {
                            if (updateTimeI == 0)
                            {
                                // Lets Create an Update Time.
                                updateTimeI = Helper.CurrentTimeMillis();
                            }
                            PutColumnInternal(new ColumnData("update_time_", updateTimeI));
                        }
                        catch (Exception er)
                        {
                            // There was an Error.
                        }
                    }
                    else
                    {
                        // Lets set the Other Data Points if they are given explicitly.
                        if (updateTimeI != 0)
                        {
                            PutColumnInternal(new ColumnData("update_time_", updateTimeI));
                        }
                    }

                    // Set the Tenant ID.
                    if (CloudDB.IsMultiTenant(tableName))
                    {
                        // The table is multi-tenant.
                        PutColumnInternal(new ColumnData("tenant_id_", tenantID));
                    }

                    // The Insert Statement Generating was succesful, we can run the Statement.
                    string sql = GetSQL();
                    breadCrumb.BC.Debug("INSERT SQL : " + sql);
                    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();
                    int inserted = -1;

                    // Lets Execute the Query.
                    // The user is not asking to create a reader, just to insert the value.
                    inserted = dbSess.ExecuteNonQuery();

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

                    // If the data is to be synced with the server, we will sync it with the server.
                    if (syncable)
                    {
                        // The data is to be synced with the Cloud Server.
                        CloudSync.Sync(this);
                    }
                    return(inserted);
                }
                else
                {
                    // The Insert Statement Generation was not successful.
                    return(-1);
                }
            }
            catch (Exception e)
            {
                // THere was an Error.
                Console.WriteLine("Err : " + e.Message + " : " + e.StackTrace);
                AddStatus("Err : " + e.Message + " : " + e.StackTrace);
                return(-1);
            }
        }