Пример #1
0
        private string CreateParameterWithValue(object parValue, string destColumnName)
        {
            var par = new T();

            if (ConnectionType == ConnectionManagerType.Oracle && parValue is Enum) //Enums don't work obviously
            {
                par.Value = (int)parValue;
            }
            else
            {
                par.Value = parValue;
            }

            string dbTypeString = "";

            if (AddDbTypesFromDefinition)
            {
                dbTypeString = TableData.GetDataTypeName(destColumnName);
                par.DbType   = DataTypeConverter.GetDBType(dbTypeString);
                var size = DataTypeConverter.GetStringLengthFromCharString(dbTypeString);
                if (size > 0)
                {
                    par.Size = size;
                }
                if (TryConvertParameterData)
                {
                    TryConvertParameter(parValue, par, dbTypeString);
                }
            }

            Parameters.Add(par);
            string parname;

            if (UseNamedParameters)
            {
                parname           = $"{ParameterPlaceholder}P{ParameterNameCount++}";
                par.ParameterName = parname;
            }
            else
            {
                parname = "?";
            }

            //For Db2: https://stackoverflow.com/questions/13381898/how-to-resolve-sql0418n-error/13382197#13382197
            if (AddDbTypesFromDefinition && AddParameterCastInSql)
            {
                parname = $"CAST ({parname} AS {dbTypeString})";
            }
            else if (AddDbTypesFromDefinition && ConnectionType == ConnectionManagerType.Postgres &&
                     dbTypeString.ToLower().StartsWith("json"))
            {
                parname = $"CAST ({parname} AS {dbTypeString})";
            }
            return(parname);
        }
Пример #2
0
        private string CreateParameterWithValue(object parValue, int colIndex)
        {
            var par = new T();

            if (ConnectionType == ConnectionManagerType.Oracle && parValue is Enum) //Enums don't work obviously
            {
                par.Value = (int)parValue;
            }
            else
            {
                par.Value = parValue;
            }

            if (AddDbTypesFromDefinition)
            {
                var dbtypestring = TableData.GetDataTypeName(colIndex);
                par.DbType = DataTypeConverter.GetDBType(dbtypestring);
                par.Size   = DataTypeConverter.GetStringLengthFromCharString(dbtypestring);
                if (TryConvertParameterData)
                {
                    TryConvertParameter(parValue, par, dbtypestring);
                }
            }

            Parameters.Add(par);
            if (UseNamedParameters)
            {
                string parName = $"{ParameterPlaceholder}P{ParameterNameCount++}";
                par.ParameterName = parName;
                return(parName);
            }
            else
            {
                return("?");
            }
        }