Example #1
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);
            }
        }