コード例 #1
0
        internal static string ConstructUpdateQuery(this DirectModel model)
        {
            if (model.IntegerPrimary && !model.ID.HasValue)
            {
                throw new Exception("ID is not set, maybe this table was not loaded");
            }

            model.OnBeforeUpdate();

            string updateData = model.Snapshot.GetUpdateData();

            if (string.IsNullOrEmpty(updateData))
            {
                return(string.Empty);
            }

            // UPDATE MobilePaywall.core.A SET A=1 WHERE AID=1
            string command = string.Format(DirectModelHelper.GetDatabase(model).QueryConstructUpdateQuery,
                                           model.GetDatabase().DatabaseName, model.GetDatabase().DatabaseSchemeString, model.GetTableName(),
                                           model.Snapshot.GetUpdateData(),
                                           model.GetIdNameValue(),
                                           (model.IntegerPrimary ? model.ID.Value.ToString() : string.Format("'{0}'", model.GetStringID())));

            return(command);
        }
コード例 #2
0
        internal static string ConstructUpdateUpdatedQuery(this DirectModel model)
        {
            if (model.IntegerPrimary && !model.ID.HasValue)
            {
                throw new Exception("ID is not set, maybe this table was not loaded");
            }

            model.OnBeforeUpdate();

            // UPDATE MobilePaywall.core.A SET A=1 WHERE AID=1

            string updatedPropName = string.Empty;

            foreach (var prop in model.Snapshot.PropertySignatures)
            {
                if (prop.Name.ToLower().Equals("updated"))
                {
                    updatedPropName = prop.Name;
                }
            }

            if (string.IsNullOrEmpty(updatedPropName))
            {
                return(string.Empty);
            }

            string command = string.Format(DirectModelHelper.GetDatabase(model).QueryConstructUpdateUpdatedQuery,
                                           model.GetDatabase().DatabaseName, model.GetDatabase().DatabaseSchemeString, model.GetTableName(),
                                           updatedPropName, model.Database.ConstructDateTimeParam(DateTime.Now),
                                           model.GetIdNameValue(),
                                           (model.IntegerPrimary ? model.ID.Value.ToString() : string.Format("'{0}'", model.GetStringID())));

            return(command);
        }
コード例 #3
0
        internal static string ConstructInsertQuery(this DirectModel model)
        {
            model.OnBeforeInsert();
            string command = string.Format(DirectModelHelper.GetDatabase(model).QueryConstructInsertQuery,
                                           model.GetDatabase().DatabaseName, model.GetDatabase().DatabaseSchemeString, model.GetTableName(),
                                           model.Snapshot.GetPropertyNamesForInsert(), model.Snapshot.GetPropertyValuesForInsert());

            return(command);
        }
コード例 #4
0
ファイル: InsertUpdateDelete.cs プロジェクト: aco228/Direct
        private static DirectDatabaseBase GetDatabase(DirectModel model)
        {
            if (model.GetDatabase() != null)
            {
                return(model.GetDatabase());
            }

            switch (model.DatabaseType)
            {
            case DirectDatabaseType.MySQL:
                return(new Direct.Types.Mysql.DirectDatabaseMysql(string.Empty, string.Empty));

            case DirectDatabaseType.SQLite:
                return(new Direct.Types.SQLite.DirectDatabaseSqlLite(string.Empty, string.Empty));

            default:
                return(null);
            }
        }
コード例 #5
0
ファイル: InsertUpdateDelete.cs プロジェクト: aco228/Direct
 public static void InsertLater(this DirectModel model)
 {
     model.GetDatabase().TransactionalManager.Add(model.ConstructInsertQuery());
 }