GetEscapedName() public méthode

public GetEscapedName ( string name ) : string
name string
Résultat string
        public static DbCommand BuildInsertCommand(
            this DbCommand cmd,
            object obj,
            string tableName,
            DbSettings dbSettings,
            string[] includeFields,
            string[] excludeFields
            )
        {
            IMappingConfigurator config = new AddDbCommandsMappingConfig(
                dbSettings,
                includeFields,
                excludeFields,
                "insertop_inc_" + includeFields.ToCSV("_") + "_exc_" + excludeFields.ToCSV("_")
                );

            var mapper = ObjectMapperManager.DefaultInstance.GetMapperImpl(
                obj.GetType(),
                typeof(DbCommand),
                config
                );

            string[] fields = mapper.StroredObjects.OfType <SrcReadOperation>().Select(m => m.Source.MemberInfo.Name).ToArray();

            var cmdStr =
                "INSERT INTO "
                + tableName +
                "("
                + fields
                .Select(f => dbSettings.GetEscapedName(f))
                .ToCSV(",")
                + ") VALUES ("
                + fields
                .Select(f => dbSettings.GetParamName(f))
                .ToCSV(",")
                + ")"
            ;

            cmd.CommandText = cmdStr;
            cmd.CommandType = System.Data.CommandType.Text;

            mapper.Map(obj, cmd, null);
            return(cmd);
        }
        public static DbCommand BuildInsertCommand(
            this DbCommand cmd,
            object obj,
            string tableName,
            DbSettings dbSettings,
            string[] includeFields,
            string[] excludeFields
            )
        {
            IMappingConfigurator config = new AddDbCommandsMappingConfig(
                    dbSettings,
                    includeFields,
                    excludeFields,
                    "insertop_inc_" + includeFields.ToCSV("_") + "_exc_" + excludeFields.ToCSV("_")
            );

            var mapper = ObjectMapperManager.DefaultInstance.GetMapperImpl(
                obj.GetType(),
                typeof(DbCommand),
                config
            );

            string[] fields = mapper.StroredObjects.OfType<SrcReadOperation>().Select(m => m.Source.MemberInfo.Name).ToArray();

            var cmdStr =
                "INSERT INTO "
                + tableName +
                "("
                + fields
                    .Select(f => dbSettings.GetEscapedName(f))
                    .ToCSV(",")
                + ") VALUES ("
                + fields
                    .Select( f => dbSettings.GetParamName(f))
                    .ToCSV(",")
                + ")"
                ;
            cmd.CommandText = cmdStr;
            cmd.CommandType = System.Data.CommandType.Text;

            mapper.Map(obj, cmd, null);
            return cmd;
        }
        public static bool BuildUpdateCommand(
            this DbCommand cmd,
            object obj,
            string tableName,
            IEnumerable<string> idFieldNames,
            IEnumerable<string> includeFields,
            IEnumerable<string> excludeFields,
            ObjectsChangeTracker changeTracker,
            DbSettings dbSettings
            )
        {
            if(idFieldNames == null)
            {
                idFieldNames = new string[0];
            }
            idFieldNames = idFieldNames.Select (n => n.ToUpper()).ToArray();

            if (changeTracker != null)
            {
                var changedFields = changeTracker.GetChanges(obj);
                if (changedFields != null)
                {
                    if (includeFields == null)
                    {
                        includeFields = changedFields.Select(c => c.name).ToArray();
                    }
                    else
                    {
                        includeFields = includeFields.Intersect(changedFields.Select(c => c.name)).ToArray();
                    }
                }
            }
            if (includeFields != null)
            {
                includeFields = includeFields.Concat(idFieldNames);
            }
            IMappingConfigurator config = new AddDbCommandsMappingConfig(
                    dbSettings,
                    includeFields,
                    excludeFields,
                    "updateop_inc_" + includeFields.ToCSV("_") + "_exc_" + excludeFields.ToCSV("_")
            );

            var mapper = ObjectMapperManager.DefaultInstance.GetMapperImpl(
                obj.GetType(),
                typeof(DbCommand),
                config
            );

            string[] fields = mapper
                .StroredObjects
                .OfType<SrcReadOperation>()
                .Select( m => m.Source.MemberInfo.Name )
                .Where( f => !idFieldNames.Contains(f) )
                .ToArray();

            if (fields.Length == 0)
            {
                return false;
            }

            var cmdStr =
                "UPDATE " +
                tableName +
                " SET " +
                fields
                    .Select(
                        f => dbSettings.GetEscapedName(f) + "=" + dbSettings.GetParamName(f)
                    )
                    .ToCSV(",") +
                " WHERE " +
                idFieldNames.Select(fn => dbSettings.GetEscapedName(fn) + "=" + dbSettings.GetParamName(fn)).ToCSV(" AND ")
                ;
            cmd.CommandText = cmdStr;
            cmd.CommandType = System.Data.CommandType.Text;

            mapper.Map(obj, cmd, null);
            return true;
        }
Exemple #4
0
        /// <summary>
        /// Builds the update command.
        /// </summary>
        /// <param name="cmd">The CMD.</param>
        /// <param name="obj">The obj.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="idFieldNames">The id field names.</param>
        /// <param name="includeFields">The include fields.</param>
        /// <param name="excludeFields">The exclude fields.</param>
        /// <param name="changeTracker">The change tracker.</param>
        /// <param name="dbSettings">The db settings.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        public static bool BuildUpdateCommand(
            this DbCommand cmd,
            object obj,
            string tableName,
            IEnumerable <string> idFieldNames,
            IEnumerable <string> includeFields,
            IEnumerable <string> excludeFields,
            ObjectsChangeTracker changeTracker,
            DbSettings dbSettings
            )
        {
            if (idFieldNames == null)
            {
                idFieldNames = new string[0];
            }
            idFieldNames = idFieldNames.Select(n => n.ToUpper()).ToArray();

            if (changeTracker != null)
            {
                var changedFields = changeTracker.GetChanges(obj);
                if (changedFields != null)
                {
                    if (includeFields == null)
                    {
                        includeFields = changedFields.Select(c => c.name).ToArray();
                    }
                    else
                    {
                        includeFields = includeFields.Intersect(changedFields.Select(c => c.name)).ToArray();
                    }
                }
            }
            if (includeFields != null)
            {
                includeFields = includeFields.Concat(idFieldNames);
            }
            IMappingConfigurator config = new AddDbCommandsMappingConfig(
                dbSettings,
                includeFields,
                excludeFields,
                "updateop_inc_" + includeFields.ToCSV("_") + "_exc_" + excludeFields.ToCSV("_")
                );

            var mapper = ObjectMapperManager.DefaultInstance.GetMapperImpl(
                obj.GetType(),
                typeof(DbCommand),
                config
                );

            string[] fields = mapper
                              .StroredObjects
                              .OfType <SrcReadOperation>()
                              .Select(m => m.Source.MemberInfo.Name)
                              .Where(f => !idFieldNames.Contains(f))
                              .ToArray();

            if (fields.Length == 0)
            {
                return(false);
            }

            var cmdStr =
                "UPDATE " +
                tableName +
                " SET " +
                fields
                .Select(
                    f => dbSettings.GetEscapedName(f.ToUpper()) + "=" + dbSettings.GetParamName(f.ToUpper())
                    )
                .ToCSV(",") +
                " WHERE " +
                idFieldNames.Select(fn => dbSettings.GetEscapedName(fn) + "=" + dbSettings.GetParamName(fn)).ToCSV(" AND ")
            ;

            cmd.CommandText = cmdStr;
            cmd.CommandType = System.Data.CommandType.Text;

            mapper.Map(obj, cmd, null);
            return(true);
        }