Beispiel #1
0
 public virtual IDbDataParameter AddParameter(IDbCommand command, DbParamInfo prmInfo)
 {
     var prm = command.CreateParameter();
       var typeInfo = prmInfo.TypeInfo;
       prm.DbType = typeInfo.VendorDbType.DbType;
       prm.Direction = prmInfo.Direction;
       prm.ParameterName = prmInfo.Name;
       if (typeInfo.Precision > 0) prm.Precision = typeInfo.Precision;
       if (typeInfo.Scale > 0) prm.Scale = typeInfo.Scale;
       if (typeInfo.Size > 0) prm.Size = (int) typeInfo.Size;
       prm.Value = prmInfo.DefaultValue;
       command.Parameters.Add(prm);
       return prm;
 }
Beispiel #2
0
        private DbParamInfo AddParameter(DbParamInfo parameter)
        {
            Parameters.Add(parameter);
            switch (parameter.Direction)
            {
            case ParameterDirection.Output:
            case ParameterDirection.InputOutput:
                OutputParameters.Add(parameter);
                break;

            case ParameterDirection.ReturnValue:
                ReturnValueParameter = parameter;
                break;
            }
            return(parameter);
        }
Beispiel #3
0
 public override IDbDataParameter AddParameter(IDbCommand command, DbParamInfo prmInfo)
 {
     var prm = (MySqlParameter)base.AddParameter(command, prmInfo);
       prm.MySqlDbType = (MySqlDbType)prmInfo.TypeInfo.VendorDbType.VendorDbType;
       return prm;
 }
Beispiel #4
0
 private DbParamInfo AddParameter(DbParamInfo parameter)
 {
     Parameters.Add(parameter);
       switch (parameter.Direction) {
     case ParameterDirection.Output:
     case ParameterDirection.InputOutput:
       OutputParameters.Add(parameter);
       break;
     case ParameterDirection.ReturnValue:
       ReturnValueParameter = parameter;
       break;
       }
       return parameter;
 }
Beispiel #5
0
        //Creates default implementation for servers that do not support array parameters.
        // The command is implemented as templated SQL
        public virtual DbCommandInfo BuildSelectByKeyArrayCommand(EntityCommand entityCommand)
        {
            const string SqlSelectByFkTemplate = @"
            SELECT {0} {1}
              FROM {2}
              WHERE {3}
              {4}";
              var table = DbModel.LookupDbObject<DbTableInfo>(entityCommand.TargetEntityInfo, throwNotFound: true);
              var dbKey = DbModel.LookupDbObject<DbKeyInfo>(entityCommand.SelectKey);
              if (dbKey.KeyColumns.Count > 1)
            return null;
              var keyCol = dbKey.KeyColumns[0].Column.ColumnName;
              var cmdName = ModelConfig.NamingPolicy.ConstructDbCommandName(entityCommand, table.TableName, "SelectByArrayOf_", keyCol);
              var descrTag = GetDbCommandDescriptiveTag(entityCommand);
              var cmdInfo = new DbCommandInfo(entityCommand, cmdName, table, DbExecutionType.Reader, null, descrTag);
              cmdInfo.IsTemplatedSql = true;

              //Build column list
              var outColumns = table.Columns.GetSelectable();
              var strColumns = outColumns.GetSqlNameList();
              //build WHERE clause

              var whereExpr = '"' + keyCol + '"' + " IN ({0})"; //this {0} will remain in a template
              if (!string.IsNullOrWhiteSpace(entityCommand.Filter))
            whereExpr = whereExpr + " AND " + ProcessFilter(entityCommand, table);
              string orderByExpr = null;
              if (dbKey.KeyType == KeyType.PrimaryKey)
            orderByExpr = null;
              else
            orderByExpr = BuildOrderBy(table.DefaultOrderBy);
              string strTop = string.Empty;
              var sql = string.Format(SqlSelectByFkTemplate, strTop, strColumns, table.FullName, whereExpr, orderByExpr);
              sql = sql.Trim() + ";";
              cmdInfo.Sql = sql;
              cmdInfo.EntityMaterializer = CreateEntityMaterializer(table, outColumns);
              //Create parameter for just-in-time formatting of SQL
              var entPrm = entityCommand.Parameters[0];
              Type elemType;
              Util.Check(entPrm.DataType.IsListOfDbPrimitive(out elemType), "Parameter is not list of primitives.");
              var elemTypeInfo = GetDbTypeInfo(elemType, 0);
              Util.Check(elemTypeInfo != null, "Failed to get db type information for type {0}.", elemType);
              var prm = new DbParamInfo(entPrm, "(array)", 0);
              prm.ToLiteralConverter = (list) => ConvertList(list, elemTypeInfo);
              cmdInfo.Parameters.Add(prm);
              return cmdInfo;
        }
 private bool BatchShouldUseParameterFor(DbParamInfo paramInfo, object value)
 {
     if (paramInfo.Direction != ParameterDirection.Input)
     return true;
       if (value == DBNull.Value)
     return false;
       var t = value.GetType();
       if (t == typeof(string)) {
     var str = (string)value;
     return str.Length > MaxLiteralLength;
       }
       if (t == typeof(byte[])) {
     var bytes = (byte[])value;
     return bytes.Length > MaxLiteralLength;
       }
       return false;
 }
Beispiel #7
0
 public override IDbDataParameter AddParameter(IDbCommand command, DbParamInfo prmInfo)
 {
     var prm = (SqlParameter)base.AddParameter(command, prmInfo);
       prm.SqlDbType = (SqlDbType)prmInfo.TypeInfo.VendorDbType.VendorDbType;
       //Set User type name
       switch(prm.SqlDbType) {
     case SqlDbType.Udt:
       prm.UdtTypeName = prmInfo.TypeInfo.SqlTypeSpec;
       break;
     case SqlDbType.Structured:
       prm.TypeName = prmInfo.TypeInfo.SqlTypeSpec;
       break;
       }
       return prm;
 }