Beispiel #1
0
        private int ExecuteNonQueryInternal(OciStatementHandle statement, bool useAutoCommit)
        {
            moreResults = -1;

            if (preparedStatement == null)
            {
                PrepareStatement(statement);
            }

            bool isNonQuery = IsNonQuery(statement);

            BindParameters(statement);
            if (isNonQuery == true)
            {
                statement.ExecuteNonQuery(useAutoCommit);
            }
            else
            {
                statement.ExecuteQuery(false);
            }

            UpdateParameterValues();

            int rowsAffected = statement.GetAttributeInt32(OciAttributeType.RowCount, ErrorHandle);

            return(rowsAffected);
        }
Beispiel #2
0
        public object ExecuteOracleScalar()
        {
            moreResults = -1;

            object output = DBNull.Value;

            AssertConnectionIsOpen();
            AssertTransactionMatch();
            AssertCommandTextIsSet();

            if (Transaction != null)
            {
                Transaction.AttachToServiceContext();
            }

            OciStatementHandle statement = GetStatementHandle();

            try {
                if (preparedStatement == null)
                {
                    PrepareStatement(statement);
                }

                bool isNonQuery = IsNonQuery(statement);

                BindParameters(statement);

                if (isNonQuery == true)
                {
                    ExecuteNonQueryInternal(statement, false);
                }
                else
                {
                    statement.ExecuteQuery(false);

                    if (statement.Fetch())
                    {
                        OciDefineHandle defineHandle = (OciDefineHandle)statement.Values [0];
                        if (!defineHandle.IsNull)
                        {
                            output = defineHandle.GetOracleValue(Connection.SessionFormatProvider, Connection);
                        }
                        switch (defineHandle.DataType)
                        {
                        case OciDataType.Blob:
                        case OciDataType.Clob:
                            ((OracleLob)output).connection = Connection;
                            break;
                        }
                    }
                    UpdateParameterValues();
                }

                return(output);
            } finally {
                SafeDisposeHandle(statement);
            }
        }
Beispiel #3
0
        OracleDataReader ExecuteReader(CommandBehavior behavior)
        {
            AssertConnectionIsOpen();
            AssertTransactionMatch();
            AssertCommandTextIsSet();

            moreResults = -1;

            bool hasRows = false;

            this.behavior = behavior;

            if (Transaction != null)
            {
                Transaction.AttachToServiceContext();
            }

            OciStatementHandle statement = GetStatementHandle();
            OracleDataReader   rd        = null;

            try
            {
                if (preparedStatement == null)
                {
                    PrepareStatement(statement);
                }
                else
                {
                    preparedStatement = null;   // OracleDataReader releases the statement handle
                }
                bool isNonQuery = IsNonQuery(statement);

                BindParameters(statement);

                if (isNonQuery)
                {
                    ExecuteNonQueryInternal(statement, false);
                }
                else
                {
                    if ((behavior & CommandBehavior.SchemaOnly) != 0)
                    {
                        statement.ExecuteQuery(true);
                    }
                    else
                    {
                        hasRows = statement.ExecuteQuery(false);
                    }

                    UpdateParameterValues();
                }

                if (Parameters.Count > 0)
                {
                    for (int p = 0; p < Parameters.Count; p++)
                    {
                        OracleParameter parm = Parameters[p];
                        if (parm.OracleType.Equals(OracleType.Cursor))
                        {
                            if (parm.Direction != ParameterDirection.Input)
                            {
                                rd = (OracleDataReader)parm.Value;
                                break;
                            }
                        }
                    }
                }

                if (rd == null)
                {
                    rd = new OracleDataReader(this, statement, hasRows, behavior);
                }
            }
            finally
            {
                if (statement != null && rd == null)
                {
                    statement.Dispose();
                }
            }

            return(rd);
        }