示例#1
0
 public override string BuildInsertCommand(string tableName, DbParameterAccessor[] accessors) {
     string insertCommand = base.BuildInsertCommand(tableName, accessors);
     //insertCommand = paramNameRegex.Replace(insertCommand, "?");
     //string blah = Regex.Replace(insertCommand, paramNameRegex.ToString(), "?");
     Console.WriteLine("MySqlEnvironment.BuildInsertCommand:{0}", insertCommand);
     return insertCommand;
 }
示例#2
0
 public static DbParameterAccessor CloneWithSameParameter(DbParameterAccessor dbacc)
 {
     DbParameterAccessor clone = new DbParameterAccessor(dbacc.DbParameter, dbacc.dotNetType, dbacc.position, dbacc.actualSqlType);
     clone.dbFieldName = dbacc.dbFieldName;
     clone.isBoundToCheckOperation = dbacc.isBoundToCheckOperation;
     return clone;
 }
示例#3
0
        public static DbParameterAccessor CloneWithSameParameter(DbParameterAccessor dbacc)
        {
            DbParameterAccessor clone = new DbParameterAccessor(dbacc.DbParameter, dbacc.dotNetType, dbacc.position, dbacc.actualSqlType);

            clone.dbFieldName             = dbacc.dbFieldName;
            clone.isBoundToCheckOperation = dbacc.isBoundToCheckOperation;
            return(clone);
        }
示例#4
0
		public static DbParameterAccessor Clone(DbParameterAccessor dbacc, IDbEnvironment environment)
		{
			DbParameter cloneP=environment.DbProviderFactory.CreateParameter();
			cloneP.ParameterName=dbacc.DbParameter.ParameterName;
			cloneP.DbType= dbacc.DbParameter.DbType;
			cloneP.Direction= dbacc.DbParameter.Direction;
			cloneP.Size= dbacc.DbParameter.Size;
			cloneP.SourceColumn = dbacc.DbParameter.SourceColumn;
			cloneP.Value=dbacc.DbParameter.Value;
			DbParameterAccessor clone=new DbParameterAccessor(cloneP, dbacc.dotNetType,dbacc.position, dbacc.actualSqlType);
			clone.dbFieldName=dbacc.dbFieldName;
			clone.isBoundToCheckOperation=dbacc.isBoundToCheckOperation;            
            return clone;
		}
示例#5
0
        public static DbParameterAccessor Clone(DbParameterAccessor dbacc, IDbEnvironment environment)
        {
            DbParameter cloneP = environment.DbProviderFactory.CreateParameter();

            cloneP.ParameterName = dbacc.DbParameter.ParameterName;
            cloneP.DbType        = dbacc.DbParameter.DbType;
            cloneP.Direction     = dbacc.DbParameter.Direction;
            cloneP.Size          = dbacc.DbParameter.Size;
            cloneP.SourceColumn  = dbacc.DbParameter.SourceColumn;
            cloneP.Value         = dbacc.DbParameter.Value;
            DbParameterAccessor clone = new DbParameterAccessor(cloneP, dbacc.dotNetType, dbacc.position, dbacc.actualSqlType);

            clone.dbFieldName             = dbacc.dbFieldName;
            clone.isBoundToCheckOperation = dbacc.isBoundToCheckOperation;
            return(clone);
        }
示例#6
0
        public void SortAccessorsInRightOrder()
        {
            //Prepare
            var accessorsToOrder = new DbParameterAccessor[4];
            accessorsToOrder[0]=new DbParameterAccessor(new SqlParameter(), typeof(string), 1, "String");
            accessorsToOrder[3]=new DbParameterAccessor(new SqlParameter(), typeof(string), 3, "String");
            accessorsToOrder[2]=new DbParameterAccessor(new SqlParameter(), typeof(string), 5, "String");
            accessorsToOrder[1]=new DbParameterAccessor(new SqlParameter(), typeof(string), 7, "String");
            
            //Execute
            DbParameterAccessor[] resultingAccessors = ExecuteProcedure.SortAccessors(accessorsToOrder);

            //Verify
            Assert.AreEqual(1, resultingAccessors[0].Position);
            Assert.AreEqual(3, resultingAccessors[1].Position);
            Assert.AreEqual(5, resultingAccessors[2].Position);
            Assert.AreEqual(7, resultingAccessors[3].Position);
        }
 public override String BuildInsertCommand(String tableName, DbParameterAccessor[] accessors)
 {
     StringBuilder sb = new StringBuilder("insert into ");
     sb.Append(tableName).Append("(");
     String comma = "";
     StringBuilder values = new StringBuilder();
     foreach (DbParameterAccessor accessor in accessors)
     {
         sb.Append(comma);
         values.Append(comma);
         sb.Append("[").Append(accessor.DbParameter.SourceColumn).Append("]");
         values.Append(ParameterPrefix).Append(accessor.DbParameter.ParameterName);
         comma = ",";
     }
     sb.Append(") values (");
     sb.Append(values);
     sb.Append(")");
     return sb.ToString();
 }
示例#8
0
        public override String BuildInsertCommand(String tableName, DbParameterAccessor[] accessors)
        {
            StringBuilder sb = new StringBuilder("insert into ");
            sb.Append(tableName).Append("(");
            String comma = "";
            String retComma = "";

            StringBuilder values = new StringBuilder();
            StringBuilder retNames = new StringBuilder();
            StringBuilder retValues = new StringBuilder();

            foreach (DbParameterAccessor accessor in accessors)
            {
                if (!accessor.IsBoundToCheckOperation)
                {
                    sb.Append(comma);
                    values.Append(comma);
                    sb.Append(accessor.DbParameter.SourceColumn);
                    values.Append(":").Append(accessor.DbParameter.ParameterName);
                    comma = ",";
                }
                else
                {
                    retNames.Append(retComma);
                    retValues.Append(retComma);
                          retNames.Append(accessor.DbParameter.SourceColumn);
                    retValues.Append(":").Append(accessor.DbParameter.ParameterName);
                    retComma = ",";
                }
            }
            sb.Append(") values (");
            sb.Append(values);
            sb.Append(")");
            if (retValues.Length > 0)
            {
                sb.Append(" returning ").Append(retNames).Append(" into ").Append(retValues);
            }
            return sb.ToString();
        }
示例#9
0
        private Dictionary <string, DbParameterAccessor> ReadIntoParams(SchemaObjectName tableOrViewname, string query)
        {
            Dictionary <string, DbParameterAccessor> accessorDictionary = new Dictionary <string, DbParameterAccessor>();
            int       position = 0;
            DbCommand dc       = CurrentConnection.CreateCommand();

            dc.Transaction = CurrentTransaction;
            dc.CommandText = query;
            dc.CommandType = CommandType.Text;

            AddSchemaAndTablenameParametersToCommand(dc, tableOrViewname);

            using (DbDataReader reader = dc.ExecuteReader())
            {
                while (reader.Read())
                {
                    DbParameterAccessor accessor = MySqlTypeConverter.BuildDbParameterAccessorFrom(reader, position++);
                    Console.WriteLine("DbParameter DbFieldName={0}", accessor.DbFieldName);
                    accessorDictionary.Add(accessor.DbFieldName.ToLowerInvariant(), accessor);
                }
            }

            return(accessorDictionary);
        }
 public virtual String BuildInsertCommand(String tableName, DbParameterAccessor[] accessors)
 {
     var sb = new StringBuilder("insert into ");
     sb.Append(tableName).Append("(");
     var separator = "";
     var values = new StringBuilder();
     foreach (var accessor in accessors)
     {
         sb.Append(separator);
         values.Append(separator);
         sb.Append(BuildColumnName(accessor.DbParameter.SourceColumn));
         values.Append(ParameterPrefix).Append(accessor.DbParameter.ParameterName);
         separator = ",";
     }
     sb.Append(") values (");
     sb.Append(values);
     sb.Append(")");
     return sb.ToString();
 }
 public virtual String BuildUpdateCommand(String tableName, DbParameterAccessor[] updateAccessors, DbParameterAccessor[] selectAccessors)
 {
     if (updateAccessors.Length == 0)
     {
         throw new ApplicationException("must have at least one field to update. Have you forgotten = after the column name?");
     }
     var s = new StringBuilder("update ").Append(tableName).Append(" set ");
     for (var i = 0; i < updateAccessors.Length; i++)
     {
         if (i > 0) s.Append(", ");
         s.Append(BuildColumnName(updateAccessors[i].DbParameter.SourceColumn)).Append("=");
         s.Append(ParameterPrefix).Append(updateAccessors[i].DbParameter.ParameterName);
     }
     s.Append(" where ");
     for (var i = 0; i < selectAccessors.Length; i++)
     {
         if (i > 0) s.Append(" and ");
         s.Append(BuildColumnName(selectAccessors[i].DbParameter.SourceColumn)).Append("=");
         s.Append(ParameterPrefix).Append(selectAccessors[i].DbParameter.ParameterName);
     }
     return s.ToString();
 }