Beispiel #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());
        }
Beispiel #2
0
        protected Object HandleOutParameters(IDbCommand dbCommand, Object dto, Object returnValue)
        {
            if (dto == null)
            {
                return(null);
            }
            int size = _procedureMetaData.ParameterTypeSize;

            for (int i = 0; i < size; i++)
            {
                InternalProcedureParameterType ppt = _procedureMetaData.GetParameterType(i);
                if (ppt.IsOutType)
                {
                    Object value = ((IDataParameter)dbCommand.Parameters[i]).Value;
                    if (value is IDataReader)  // Not support yet
                    {
                        IDataReader reader = (IDataReader)value;
                        throw new NotImplementedException("The result set of procedure is not implemented: " + reader);
                        //     IDataReaderHandler handler = CreateOutParameterResultSetHandler(ppt, reader);
                        //     try {
                        //         value = handler.Handle(reader);
                        //     } finally {
                        //         if (reader != null) {
                        //             reader.Close();
                        //         }
                        //     }
                    }
                    if (!(value is DBNull))
                    {
                        ppt.SetValue(dto, value);
                    }
                    // [Under Review]: @jflute If it's DBNull, what can I do for you?
                }
                else if (ppt.IsReturnType)
                {
                    ppt.SetValue(dto, returnValue);
                }
            }
            return(dto);
        }
Beispiel #3
0
 protected IDataReaderHandler CreateOutParameterResultSetHandler(InternalProcedureParameterType ppt, IDataReader reader)
 {
     // return new InternalMapListResultSetHandler();
     return(null);
 }
Beispiel #4
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);
            }
        }