protected override IDbDataParameter OnParameterCreated(IDbDataParameter parameter, IDacParameter dacParameter)
        {
            var dbParam = (SqlParameter)parameter;
            var setSize = false;

            if (DbSchemaInfo.Parameters.ShouldBeDateTime(dacParameter))
            {
                dbParam.DbType = DbType.DateTime;
                return dbParam;
            }

            if (DbSchemaInfo.Parameters.ShouldBeNonUnicodeString(dacParameter))
            {
                dbParam.SqlDbType = SqlDbType.VarChar;
                setSize = true;
            }
            else if (DbSchemaInfo.Parameters.ShouldBeUnicodeString(dacParameter))
            {
                dbParam.SqlDbType = SqlDbType.NVarChar;
                setSize = true;
            }

            if (setSize)
            {
                dbParam.Size = (dacParameter.Value.ToStringOrNull() ?? string.Empty).Length;
                return dbParam;
            }

            return dbParam;
        }
Ejemplo n.º 2
0
        protected override IDbDataParameter OnParameterCreated(IDbDataParameter parameter, IDacParameter dacParameter)
        {
            var dbParam = (SqlCeParameter)parameter;

            if (DbSchemaInfo.Parameters.ShouldBeDateTime(dacParameter))
            {
                dbParam.DbType = DbType.DateTime;
                return dbParam;
            }

            if (DbSchemaInfo.Parameters.ShouldBeJson(dacParameter))
            {
                dbParam.SqlDbType = SqlDbType.NText;
                dbParam.Size = (dacParameter.Value.ToStringOrNull() ?? string.Empty).Length;
                return dbParam;
            }

            if (DbSchemaInfo.Parameters.ShouldBeUnicodeString(dacParameter))
            {
                dbParam.SqlDbType = SqlDbType.NVarChar;
                var len = (dacParameter.Value.ToStringOrNull() ?? string.Empty).Length;
                if (len > MaxLenOfStringBeforeEscalating)
                    throw new SisoDbException(ExceptionMessages.SqlCe4_ToLongIndividualStringValue);

                dbParam.Size = len;
                return dbParam;
            }

            return dbParam;
        }
Ejemplo n.º 3
0
 public static bool ShouldBeNonUnicodeString(IDacParameter param)
 {
     return param.Name.StartsWith(DbNameParamPrefix, Sys.StringComparision)
         || param.Name.StartsWith(TableNameParamPrefix, Sys.StringComparision)
         || param.Name.StartsWith(EntityNameParamPrefix, Sys.StringComparision)
         || param.Name.Equals(StringValueForValueTypeIndexParamName);
 }
Ejemplo n.º 4
0
 public static bool ShouldBeNonUnicodeString(IDacParameter param)
 {
     return(param.Name.StartsWith(DbNameParamPrefix, Sys.StringComparision) ||
            param.Name.StartsWith(TableNameParamPrefix, Sys.StringComparision) ||
            param.Name.StartsWith(EntityNameParamPrefix, Sys.StringComparision) ||
            param.Name.Equals(StringValueForValueTypeIndexParamName));
 }
        public SqlWhereCriteria(string criteriaString, IDacParameter[] parameters)
        {
            Ensure.That(criteriaString, "criteriaString").IsNotNullOrWhiteSpace();
            Ensure.That(parameters, "parameters").IsNotNull();

            _isEmpty = false;
            _criteriaString = criteriaString;
            _parameters = parameters;
        }
Ejemplo n.º 6
0
        public DbQuery(string sql, IDacParameter[] parameters)
        {
            Ensure.That(sql, "sql").IsNotNullOrWhiteSpace();
            Ensure.That(parameters, "parameters").IsNotNull();

            _isEmpty = false;
            _sql = sql;
            _parameters = new ReadOnlyCollection<IDacParameter>(parameters.Distinct().ToList());
        }
Ejemplo n.º 7
0
            public static bool ShouldBeNonUnicodeString(IDacParameter param)
            {
                const StringComparison c = StringComparison.OrdinalIgnoreCase;

                return param.Name.StartsWith(DbNameParamPrefix, c)
                    || param.Name.StartsWith(TableNameParamPrefix, c)
                    || param.Name.StartsWith(EntityNameParamPrefix, c)
                    || param.Name.Equals(StringValueForValueTypeIndexParamName);
            }
Ejemplo n.º 8
0
        public DbQuery(string sql, IDacParameter[] parameters, bool isCacheable)
        {
            Ensure.That(sql, "sql").IsNotNullOrWhiteSpace();
            Ensure.That(parameters, "parameters").IsNotNull();

            _isEmpty = false;
            _sql = sql;
            _parameters = parameters.Distinct().ToArray();
            _isCacheable = isCacheable;
        }
Ejemplo n.º 9
0
 public bool Equals(IDacParameter other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.Name, Name));
 }
        protected virtual IDbDataParameter OnParameterCreated(IDbDataParameter parameter, IDacParameter dacParameter)
        {
            var dbParam = (SqlParameter)parameter;
            var setSize = false;

            if (DbSchemaInfo.Parameters.ShouldBeMultivalue(dacParameter))
            {
                var arrayDacParam = (ArrayDacParameter) dacParameter;
                return SqlServerTableParams.Create(
                    arrayDacParam.Name, 
                    arrayDacParam.MemberDataType, 
                    arrayDacParam.MemberDataTypeCode, 
                    (object[])dacParameter.Value);
            }

            if(DbSchemaInfo.Parameters.ShouldBeGeography(dacParameter))
            {
                dbParam.SqlDbType = SqlDbType.Udt;
                dbParam.UdtTypeName = "geography";
                return dbParam;
            }

            if (DbSchemaInfo.Parameters.ShouldBeDateTime(dacParameter))
            {
                dbParam.DbType = DbType.DateTime2;
                return dbParam;
            }

            if (DbSchemaInfo.Parameters.ShouldBeIntegerNumber(dacParameter))
            {
                dbParam.DbType = DbType.Int64;
                return dbParam;
            }

            //Order is important. Non Unicoe first, since Unicode is fallback
            if (DbSchemaInfo.Parameters.ShouldBeNonUnicodeString(dacParameter))
            {
                dbParam.SqlDbType = SqlDbType.VarChar;
                setSize = true;
            }
            else if (DbSchemaInfo.Parameters.ShouldBeUnicodeString(dacParameter))
            {
                dbParam.SqlDbType = SqlDbType.NVarChar;
                setSize = true;
            }

            if (setSize)
                dbParam.Size = (dacParameter.Value.ToStringOrNull() ?? string.Empty).Length;

            return dbParam;
        }
        protected virtual IDbCommand CreateCommand(IDbConnection connection, CommandType commandType, string sql, IDbTransaction transaction = null, IDacParameter[] parameters = null)
        {
            var cmd = connection.CreateCommand();
            if (transaction != null)
                cmd.Transaction = transaction;

            cmd.CommandType = commandType;
            cmd.UpdatedRowSource = UpdateRowSource.None;

            if (!string.IsNullOrWhiteSpace(sql))
                cmd.CommandText = sql;

            AddCommandParametersTo(cmd, parameters);

            return cmd;
        }
        protected virtual void OnMakeGeoValid2008(IStructureSchema schema, IDacParameter sidParam)
        {
            var sql = SqlStatements.GetSql("GetGeo").Inject(schema.GetSpatialTableName());
            var geo = GetGeograpy(sql, sidParam);

            if (geo.STIsValid())
            {
                return;
            }

            geo = geo.MakeValid();

            var geoParam = new GeographyDacParameter(GeoParamName, geo);

            sql = SqlStatements.GetSql("UpdateGeo").Inject(schema.GetSpatialTableName());
            Session.DbClient.ExecuteNonQuery(sql, sidParam, geoParam);
        }
Ejemplo n.º 13
0
        public virtual void SingleInsertOfUniqueIndex(IStructureIndex uniqueStructureIndex, IStructureSchema structureSchema)
        {
            var sql = StringExtensions.Inject(SqlStatements.GetSql("SingleInsertOfUniqueIndex"), structureSchema.GetUniquesTableName(),
                                              UniqueStorageSchema.Fields.StructureId.Name,
                                              UniqueStorageSchema.Fields.UqStructureId.Name,
                                              UniqueStorageSchema.Fields.UqMemberPath.Name,
                                              UniqueStorageSchema.Fields.UqValue.Name);

            var parameters = new IDacParameter[4];

            parameters[0] = new DacParameter(UniqueStorageSchema.Fields.StructureId.Name, uniqueStructureIndex.StructureId.Value);
            parameters[1] = (uniqueStructureIndex.IndexType == StructureIndexType.UniquePerType)
                                ? new DacParameter(UniqueStorageSchema.Fields.UqStructureId.Name, DBNull.Value)
                                : new DacParameter(UniqueStorageSchema.Fields.UqStructureId.Name, uniqueStructureIndex.StructureId.Value);
            parameters[2] = new DacParameter(UniqueStorageSchema.Fields.UqMemberPath.Name, uniqueStructureIndex.Path);
            parameters[3] = new DacParameter(UniqueStorageSchema.Fields.UqValue.Name, UniquesChecksumGenerator.Instance.Generate(uniqueStructureIndex));

            ExecuteNonQuery(sql, parameters);
        }
        protected virtual IDbDataParameter OnParameterCreated(IDbDataParameter parameter, IDacParameter dacParameter)
        {
            var dbParam = (SqlParameter)parameter;
            var setSize = false;

            if (DbSchemas.Parameters.ShouldBeMultivalue(dacParameter))
            {
                var arrayDacParam = (ArrayDacParameter) dacParameter;
                return SqlServerTableParams.Create(
                    arrayDacParam.Name, 
                    arrayDacParam.MemberDataType, 
                    arrayDacParam.MemberDataTypeCode, 
                    (object[])dacParameter.Value);
            }

            if (DbSchemas.Parameters.ShouldBeDateTime(dacParameter))
            {
                dbParam.DbType = DbType.DateTime2;
                return dbParam;
            }

            if (DbSchemas.Parameters.ShouldBeNonUnicodeString(dacParameter))
            {
                dbParam.SqlDbType = SqlDbType.VarChar;
                setSize = true;
            }
            else if (DbSchemas.Parameters.ShouldBeUnicodeString(dacParameter))
            {
                dbParam.SqlDbType = SqlDbType.NVarChar;
                setSize = true;
            }

            if(setSize)
            {
                dbParam.Size = (dacParameter.Value.ToStringOrNull() ?? string.Empty).Length;
                return dbParam;
            }

            return dbParam;
        }
Ejemplo n.º 15
0
 protected virtual void OnVisitParam(IDacParameter param, StringBuilder content)
 {
     content.AppendFormat("{0}={1};\r\n", param.Name, SisoEnvironment.StringConverter.AsString(param.Value));
 }
Ejemplo n.º 16
0
 public static bool ShouldBeIntegerNumber(IDacParameter param)
 {
     return param.Value is int || param.Value is long  || param.Value is short || param.Value is byte;
 }
Ejemplo n.º 17
0
 public static bool ShouldBeDateTime(IDacParameter param)
 {
     return param.Value is DateTime;
 }
Ejemplo n.º 18
0
 public static bool ShouldBeGeography(IDacParameter param)
 {
     return param is GeographyDacParameter;
 }
Ejemplo n.º 19
0
 public static bool ShouldBeDateTime(IDacParameter param)
 {
     return(param.Value is DateTime);
 }
        protected virtual void OnMakeGeoValid(IStructureSchema schema, IDacParameter sidParam)
        {
            var sql = SqlStatements.GetSql("MakeGeoValid").Inject(schema.GetSpatialTableName());

            Session.DbClient.ExecuteNonQuery(sql, sidParam);
        }
        protected virtual IDbDataParameter OnParameterCreated(IDbDataParameter parameter, IDacParameter dacParameter)
        {
            var dbParam = (SqlParameter)parameter;
            var setSize = false;

            if (DbSchemaInfo.Parameters.ShouldBeMultivalue(dacParameter))
            {
                var arrayDacParam = (ArrayDacParameter)dacParameter;
                return(SqlServerTableParams.Create(
                           arrayDacParam.Name,
                           arrayDacParam.MemberDataType,
                           arrayDacParam.MemberDataTypeCode,
                           (object[])dacParameter.Value));
            }

            if (DbSchemaInfo.Parameters.ShouldBeGeography(dacParameter))
            {
                dbParam.SqlDbType   = SqlDbType.Udt;
                dbParam.UdtTypeName = "geography";
                return(dbParam);
            }

            if (DbSchemaInfo.Parameters.ShouldBeDateTime(dacParameter))
            {
                dbParam.DbType = DbType.DateTime2;
                return(dbParam);
            }

            if (DbSchemaInfo.Parameters.ShouldBeIntegerNumber(dacParameter))
            {
                dbParam.DbType = DbType.Int64;
                return(dbParam);
            }

            //Order is important. Non Unicoe first, since Unicode is fallback
            if (DbSchemaInfo.Parameters.ShouldBeNonUnicodeString(dacParameter))
            {
                dbParam.SqlDbType = SqlDbType.VarChar;
                setSize           = true;
            }
            else if (DbSchemaInfo.Parameters.ShouldBeUnicodeString(dacParameter))
            {
                dbParam.SqlDbType = SqlDbType.NVarChar;
                setSize           = true;
            }

            if (setSize)
            {
                dbParam.Size = (dacParameter.Value.ToStringOrNull() ?? string.Empty).Length;
            }

            return(dbParam);
        }
Ejemplo n.º 22
0
 public static bool ShouldBeMultivalue(IDacParameter param)
 {
     return(param is ArrayDacParameter);
 }
Ejemplo n.º 23
0
 public static bool ShouldBeGeography(IDacParameter param)
 {
     return(param is GeographyDacParameter);
 }
 protected virtual void OnVisitParam(IDacParameter param, StringBuilder content)
 {
     content.AppendFormat("{0}={1};\r\n", param.Name, SisoEnvironment.StringConverter.AsString(param.Value));
 }
Ejemplo n.º 25
0
 public bool Equals(IDacParameter other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.Name, Name);
 }
Ejemplo n.º 26
0
 public static bool ShouldBeJson(IDacParameter param)
 {
     return(param.Name.Equals(JsonParam, Sys.StringComparision));
 }
Ejemplo n.º 27
0
 public static bool ShouldBeUnicodeString(IDacParameter param)
 {
     return(param.Value is string);
 }
Ejemplo n.º 28
0
 public static bool ShouldBeUnicodeString(IDacParameter param)
 {
     return param.Value is string;
 }
Ejemplo n.º 29
0
 public static bool ShouldBeJson(IDacParameter param)
 {
     return param.Name.Equals(JsonParam, Sys.StringComparision);
 }
Ejemplo n.º 30
0
        protected override IDbDataParameter OnParameterCreated(IDbDataParameter parameter, IDacParameter dacParameter)
        {
            var dbParam = (SqlCeParameter)parameter;

            if (DbSchemaInfo.Parameters.ShouldBeDateTime(dacParameter))
            {
                dbParam.DbType = DbType.DateTime;
                return(dbParam);
            }

            if (DbSchemaInfo.Parameters.ShouldBeJson(dacParameter))
            {
                dbParam.SqlDbType = SqlDbType.NText;
                dbParam.Size      = (dacParameter.Value.ToStringOrNull() ?? string.Empty).Length;
                return(dbParam);
            }

            if (DbSchemaInfo.Parameters.ShouldBeUnicodeString(dacParameter))
            {
                dbParam.SqlDbType = SqlDbType.NVarChar;
                var len = (dacParameter.Value.ToStringOrNull() ?? string.Empty).Length;
                if (len > MaxLenOfStringBeforeEscalating)
                {
                    throw new SisoDbException(ExceptionMessages.SqlCe4_ToLongIndividualStringValue);
                }

                dbParam.Size = len;
                return(dbParam);
            }

            return(dbParam);
        }
Ejemplo n.º 31
0
 public static bool ShouldBeJson(IDacParameter param)
 {
     return param.Name.Equals(JsonParam, StringComparison.OrdinalIgnoreCase);
 }
Ejemplo n.º 32
0
 public static bool ShouldBeMultivalue(IDacParameter param)
 {
     return param is ArrayDacParameter;
 }
        protected override IDbDataParameter OnParameterCreated(IDbDataParameter parameter, IDacParameter dacParameter)
        {
            var dbParam = (SqlParameter)parameter;
            var setSize = false;

            if (DbSchemaInfo.Parameters.ShouldBeDateTime(dacParameter))
            {
                dbParam.DbType = DbType.DateTime;
                return(dbParam);
            }

            if (DbSchemaInfo.Parameters.ShouldBeNonUnicodeString(dacParameter))
            {
                dbParam.SqlDbType = SqlDbType.VarChar;
                setSize           = true;
            }
            else if (DbSchemaInfo.Parameters.ShouldBeUnicodeString(dacParameter))
            {
                dbParam.SqlDbType = SqlDbType.NVarChar;
                setSize           = true;
            }

            if (setSize)
            {
                dbParam.Size = (dacParameter.Value.ToStringOrNull() ?? string.Empty).Length;
                return(dbParam);
            }

            return(dbParam);
        }
Ejemplo n.º 34
0
 public static bool ShouldBeIntegerNumber(IDacParameter param)
 {
     return(param.Value is int || param.Value is long || param.Value is short || param.Value is byte);
 }