Exemplo n.º 1
0
        protected override String GetCompleteSql(Object[] args)   // for Procedure Call
        {
            String        sql  = this.Sql;
            Object        dto  = GetArgumentDto(args);
            StringBuilder sb   = new StringBuilder(100);
            int           size = _procedureMetaData.ParameterTypeSize;

            if (size == 0 || dto == null)
            {
                return("call " + sql + "()"); // Because the procedure name is SQL at CSharp!
            }
            StringBuilder tmpSb = new StringBuilder();

            for (int i = 0; i < size; i++)
            {
                InternalProcedureParameterType ppt = _procedureMetaData.GetParameterType(i);
                if (ppt.IsReturnType)
                {
                    continue;
                }
                tmpSb.append(", ?");
            }
            if (tmpSb.length() > 0)
            {
                tmpSb.delete(0, ", ".Length);
            }
            sql = "call " + sql + "(" + tmpSb.toString() + ")"; // Because the procedure name is SQL at CSharp!
            if (_procedureMetaData.HasReturnParameterType)
            {
                sql = "? = " + sql;
            }
            int pos  = 0;
            int pos2 = 0;

            for (int i = 0; i < size; i++)
            {
                InternalProcedureParameterType ppt = _procedureMetaData.GetParameterType(i);
                pos2 = sql.IndexOf('?', pos);
                if (pos2 < 0)
                {
                    break;
                }
                sb.append(sql.Substring(pos, (pos2 - pos)));
                pos = pos2 + 1;
                if (ppt.IsInType)
                {
                    sb.append(GetBindVariableText(ppt.GetValue(dto)));
                }
                else
                {
                    sb.append(sql.Substring(pos2, 1));
                }
            }
            sb.append(sql.Substring(pos));
            return(sb.toString());
        }
Exemplo n.º 2
0
        protected void BindParamters(IDbCommand command, Object dto)
        {
            int size = _procedureMetaData.ParameterTypeSize;

            for (int i = 0; i < size; i++)
            {
                InternalProcedureParameterType ppt = _procedureMetaData.GetParameterType(i);
                if (ppt.IsReturnType)
                {
                    continue;
                }
                String parameterName        = ppt.ParameterName;
                InternalBindVariableType vt = GetBindVariableType(command);
                switch (vt)
                {
                case InternalBindVariableType.QuestionWithParam:
                    parameterName = "?" + parameterName;
                    break;

                case InternalBindVariableType.ColonWithParam:
                    if ("OracleCommand".Equals(command.GetType().Name))
                    {
                        parameterName = string.Empty + parameterName;
                    }
                    else
                    {
                        parameterName = ":" + parameterName;
                    }
                    break;

                default:
                    parameterName = "@" + parameterName;
                    break;
                }

                DbType           dbType    = GetDbValueType(ppt.ParameterPropertyType);
                IDbDataParameter parameter = command.CreateParameter();
                parameter.ParameterName = parameterName;
                parameter.Direction     = ppt.ParameterDirectionType;
                parameter.Value         = ppt.GetValue(dto);
                parameter.DbType        = dbType;

                // If this setting is valid on MySQL, the exception occured.
                if (!"MySqlCommand".Equals(command.GetType().Name))
                {
                    parameter.Size = 4096;
                }

                if ("OleDbCommand".Equals(command.GetType().Name) && dbType == DbType.String)
                {
                    OleDbParameter oleDbParam = parameter as OleDbParameter;
                    oleDbParam.OleDbType = OleDbType.VarChar;
                }
                else if ("SqlCommand".Equals(command.GetType().Name) && dbType == DbType.String)
                {
                    SqlParameter sqlDbParam = parameter as SqlParameter;
                    sqlDbParam.SqlDbType = SqlDbType.VarChar;
                }
                command.Parameters.Add(parameter);
            }
        }