Exemplo n.º 1
0
        public static void Delete(this DirectDatabaseBase db, DirectModel model)
        {
            string command = string.Format("DELETE FROM {0}.{1}.{2} WHERE {2}ID={3};",
                                           db.DatabaseName, db.DatabaseScheme, model.GetTableName(),
                                           model.GetID());

            db.Execute(command);
        }
Exemplo n.º 2
0
        public static void Insert(this DirectDatabaseBase db, DirectModel model)
        {
            string command = string.Format("INSERT INTO {0}.{1}.{2} ({3}) VALUES ({4});",
                                           db.DatabaseName, db.DatabaseScheme, model.GetTableName(),
                                           model.GetPropertyNamesForInsert(), model.GetPropertyValuesForInsert());
            int?id = db.Execute(command);

            if (id.HasValue)
            {
                model.SetID(id.Value);
            }
        }
Exemplo n.º 3
0
        public static T Insert <T>(this DirectDatabaseBase db, DirectModel model) where T : DirectModel
        {
            DirectExecuteResult result = db.Execute(model.ConstructInsertQuery());

            if (result.IsSuccessfull && result.LastID.HasValue)
            {
                model.LongID = result.LastID;
                model.Snapshot.SetSnapshot();
                return((T)model);
            }
            return((T)model);
        }
Exemplo n.º 4
0
        public static void Update(this DirectDatabaseBase db, DirectModel model)
        {
            if (model.ID() <= 0)
            {
                throw new Exception("ID is not set, maybe this table was not loaded");
            }

            // UPDATE MobilePaywall.core.A SET A=1 WHERE AID=1
            string command = string.Format("UPDATE {0}.{1}.{2} SET {3} WHERE {2}ID={4};",
                                           db.DatabaseName, db.DatabaseScheme, model.GetTableName(),
                                           model.GetUpdateData(), model.GetID());

            db.Execute(command);
        }
Exemplo n.º 5
0
        public static int?Update(this DirectDatabaseBase db, DirectModel model)
        {
            if (!model.LongID.HasValue)
            {
                throw new Exception("ID is not set, maybe this table was not loaded");
            }

            DirectExecuteResult result = db.Execute(model.ConstructUpdateQuery());

            if (!result.IsSuccessfull)
            {
                return(null);
            }
            else
            {
                model.Snapshot.SetSnapshot();
                return(result.NumberOfRowsAffected);
            }
        }
        public static bool Delete(this DirectDatabaseBase db, DirectModel model)
        {
            if (!model.LongID.HasValue)
            {
                throw new Exception("THIS model has not ID");
            }

            model.OnBeforeDelete();
            string command = string.Format("DELETE FROM {0}.{1}{2} WHERE {3}={4};",
                                           db.DatabaseName, db.DatabaseSchemeString, model.GetTableName(),
                                           model.GetIdNameValue(), model.LongID.Value);
            DirectExecuteResult result = db.Execute(command);

            if (result.IsSuccessfull)
            {
                model.LongID = null;
                model.Snapshot.DeleteSnapshot();
                return(true);
            }
            return(false);
        }