コード例 #1
0
        protected override DbSqlParserColumnCollection GatherTableColumns(DbSqlParserTable table)
        {
            OciStatementHandle          stmtp       = new OciStatementHandle(this._connection.ServiceContextHandle);
            OciErrorHandle              errorHandle = this._connection.ErrorHandle;
            StringBuilder               builder     = new StringBuilder();
            string                      schemaName  = table.SchemaName;
            string                      tableName   = table.TableName;
            DbSqlParserColumnCollection columns     = new DbSqlParserColumnCollection();

            builder.Append("select * from ");
            if (!System.Data.Common.ADP.IsEmpty(schemaName))
            {
                builder.Append(schemaName);
                builder.Append(".");
            }
            builder.Append(tableName);
            string stmt = builder.ToString();

            if ((TracedNativeMethods.OCIStmtPrepare(stmtp, errorHandle, stmt, OCI.SYNTAX.OCI_NTV_SYNTAX, OCI.MODE.OCI_DEFAULT, this._connection) == 0) && (TracedNativeMethods.OCIStmtExecute(this._connection.ServiceContextHandle, stmtp, errorHandle, 0, OCI.MODE.OCI_DESCRIBE_ONLY) == 0))
            {
                int num3;
                stmtp.GetAttribute(OCI.ATTR.OCI_ATTR_PARAM_COUNT, out num3, errorHandle);
                for (int i = 0; i < num3; i++)
                {
                    string str;
                    OciParameterDescriptor handle = stmtp.GetDescriptor(i, errorHandle);
                    handle.GetAttribute(OCI.ATTR.OCI_ATTR_SQLCODE, out str, errorHandle, this._connection);
                    OciHandle.SafeDispose(ref handle);
                    str = this.QuotePrefixCharacter + str + this.QuoteSuffixCharacter;
                    columns.Add(null, schemaName, tableName, str, null);
                }
            }
            OciHandle.SafeDispose(ref stmtp);
            return(columns);
        }
コード例 #2
0
        public override void Prepare()
        {
            IntPtr ptr;

            OracleConnection.ExecutePermission.Demand();
            Bid.ScopeEnter(out ptr, "<ora.OracleCommand.Prepare|API> %d#\n", this.ObjectID);
            try
            {
                if (this.ConnectionIsClosed)
                {
                    throw System.Data.Common.ADP.ClosedConnectionError();
                }
                if (System.Data.CommandType.Text == this.CommandType)
                {
                    short num2;
                    OciStatementHandle statementHandle = this.GetStatementHandle();
                    int    closeCount    = this._connection.CloseCount;
                    string statementText = this.StatementText;
                    int    rc            = TracedNativeMethods.OCIStmtPrepare(statementHandle, this.ErrorHandle, statementText, OCI.SYNTAX.OCI_NTV_SYNTAX, OCI.MODE.OCI_DEFAULT, this.Connection);
                    if (rc != 0)
                    {
                        this.Connection.CheckError(this.ErrorHandle, rc);
                    }
                    statementHandle.GetAttribute(OCI.ATTR.OCI_ATTR_STMT_TYPE, out num2, this.ErrorHandle);
                    this._statementType = (OCI.STMT)num2;
                    if (OCI.STMT.OCI_STMT_SELECT == this._statementType)
                    {
                        rc = TracedNativeMethods.OCIStmtExecute(this._connection.ServiceContextHandle, statementHandle, this.ErrorHandle, 0, OCI.MODE.OCI_DESCRIBE_ONLY);
                        if (rc != 0)
                        {
                            this.Connection.CheckError(this.ErrorHandle, rc);
                        }
                    }
                    if (statementHandle != this._preparedStatementHandle)
                    {
                        OciHandle.SafeDispose(ref this._preparedStatementHandle);
                    }
                    this._preparedStatementHandle = statementHandle;
                    this._preparedAtCloseCount    = closeCount;
                }
                else if (this._preparedStatementHandle != null)
                {
                    OciHandle.SafeDispose(ref this._preparedStatementHandle);
                }
            }
            finally
            {
                Bid.ScopeLeave(ref ptr);
            }
        }
コード例 #3
0
        private int ExecuteNonQueryInternal(bool needRowid, out OciRowidDescriptor rowidDescriptor)
        {
            OciStatementHandle statementHandle = null;
            int num = -1;

            try
            {
                try
                {
                    ArrayList resultParameterOrdinals = new ArrayList();
                    statementHandle = this.GetStatementHandle();
                    this.Execute(statementHandle, CommandBehavior.Default, needRowid, out rowidDescriptor, out resultParameterOrdinals);
                    if (resultParameterOrdinals != null)
                    {
                        num = 0;
                        foreach (int num2 in resultParameterOrdinals)
                        {
                            OracleParameter parameter = this._parameterCollection[num2];
                            if (OracleType.Cursor != parameter.OracleType)
                            {
                                num += (int)parameter.Value;
                            }
                        }
                        return(num);
                    }
                    if (OCI.STMT.OCI_STMT_SELECT != this._statementType)
                    {
                        statementHandle.GetAttribute(OCI.ATTR.OCI_ATTR_ROW_COUNT, out num, this.ErrorHandle);
                    }
                    return(num);
                }
                finally
                {
                    if (statementHandle != null)
                    {
                        this.ReleaseStatementHandle(statementHandle);
                    }
                }
            }
            catch
            {
                throw;
            }
            return(num);
        }
コード例 #4
0
        internal string Execute(OciStatementHandle statementHandle, CommandBehavior behavior, bool needRowid, out OciRowidDescriptor rowidDescriptor, out ArrayList resultParameterOrdinals)
        {
            if (this.ConnectionIsClosed)
            {
                throw System.Data.Common.ADP.ClosedConnectionError();
            }
            if ((this._transaction == null) && (this.Connection.Transaction != null))
            {
                throw System.Data.Common.ADP.TransactionRequired();
            }
            if (((this._transaction != null) && (this._transaction.Connection != null)) && (this.Connection != this._transaction.Connection))
            {
                throw System.Data.Common.ADP.TransactionConnectionMismatch();
            }
            rowidDescriptor = null;
            this.Connection.RollbackDeadTransaction();
            int          rc = 0;
            NativeBuffer parameterBuffer = null;
            bool         success         = false;

            bool[]                   flagArray    = null;
            SafeHandle[]             handleArray  = null;
            OracleParameterBinding[] bindingArray = null;
            string                   stmt         = null;

            resultParameterOrdinals = null;
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                int   num8;
                short num13;
                if (this._preparedStatementHandle != statementHandle)
                {
                    stmt = this.StatementText;
                    rc   = TracedNativeMethods.OCIStmtPrepare(statementHandle, this.ErrorHandle, stmt, OCI.SYNTAX.OCI_NTV_SYNTAX, OCI.MODE.OCI_DEFAULT, this.Connection);
                    if (rc != 0)
                    {
                        this.Connection.CheckError(this.ErrorHandle, rc);
                    }
                }
                statementHandle.GetAttribute(OCI.ATTR.OCI_ATTR_STMT_TYPE, out num13, this.ErrorHandle);
                this._statementType = (OCI.STMT)num13;
                if (OCI.STMT.OCI_STMT_SELECT != this._statementType)
                {
                    num8 = 1;
                }
                else
                {
                    num8 = 0;
                    if (CommandBehavior.SingleRow != behavior)
                    {
                        statementHandle.SetAttribute(OCI.ATTR.OCI_ATTR_PREFETCH_ROWS, 0, this.ErrorHandle);
                        statementHandle.SetAttribute(OCI.ATTR.OCI_ATTR_PREFETCH_MEMORY, 0, this.ErrorHandle);
                    }
                }
                OCI.MODE mode = OCI.MODE.OCI_DEFAULT;
                if (num8 == 0)
                {
                    if (IsBehavior(behavior, CommandBehavior.SchemaOnly))
                    {
                        mode |= OCI.MODE.OCI_DESCRIBE_ONLY;
                    }
                }
                else if (this._connection.TransactionState == TransactionState.AutoCommit)
                {
                    mode |= OCI.MODE.OCI_COMMIT_ON_SUCCESS;
                }
                else if (TransactionState.GlobalStarted != this._connection.TransactionState)
                {
                    this._connection.TransactionState = TransactionState.LocalStarted;
                }
                if ((((mode & OCI.MODE.OCI_DESCRIBE_ONLY) == OCI.MODE.OCI_DEFAULT) && (this._parameterCollection != null)) && (this._parameterCollection.Count > 0))
                {
                    int offset = 0;
                    int count  = this._parameterCollection.Count;
                    flagArray    = new bool[count];
                    handleArray  = new SafeHandle[count];
                    bindingArray = new OracleParameterBinding[count];
                    for (int i = 0; i < count; i++)
                    {
                        bindingArray[i] = new OracleParameterBinding(this, this._parameterCollection[i]);
                        bindingArray[i].PrepareForBind(this._connection, ref offset);
                        if ((OracleType.Cursor == this._parameterCollection[i].OracleType) || (0 < this._parameterCollection[i].CommandSetResult))
                        {
                            if (resultParameterOrdinals == null)
                            {
                                resultParameterOrdinals = new ArrayList();
                            }
                            resultParameterOrdinals.Add(i);
                        }
                    }
                    parameterBuffer = new NativeBuffer_ParameterBuffer(offset);
                    parameterBuffer.DangerousAddRef(ref success);
                    for (int j = 0; j < count; j++)
                    {
                        bindingArray[j].Bind(statementHandle, parameterBuffer, this._connection, ref flagArray[j], ref handleArray[j]);
                    }
                }
                rc = TracedNativeMethods.OCIStmtExecute(this.ServiceContextHandle, statementHandle, this.ErrorHandle, num8, mode);
                if (rc != 0)
                {
                    this.Connection.CheckError(this.ErrorHandle, rc);
                }
                if (bindingArray != null)
                {
                    int length = bindingArray.Length;
                    for (int k = 0; k < length; k++)
                    {
                        bindingArray[k].PostExecute(parameterBuffer, this._connection);
                        bindingArray[k].Dispose();
                        bindingArray[k] = null;
                    }
                    bindingArray = null;
                }
                if (!needRowid || ((mode & OCI.MODE.OCI_DESCRIBE_ONLY) != OCI.MODE.OCI_DEFAULT))
                {
                    return(stmt);
                }
                switch (this._statementType)
                {
                case OCI.STMT.OCI_STMT_UPDATE:
                case OCI.STMT.OCI_STMT_DELETE:
                case OCI.STMT.OCI_STMT_INSERT:
                    rowidDescriptor = statementHandle.GetRowid(this.EnvironmentHandle, this.ErrorHandle);
                    return(stmt);
                }
                rowidDescriptor = null;
            }
            finally
            {
                if (success)
                {
                    parameterBuffer.DangerousRelease();
                }
                if (parameterBuffer != null)
                {
                    parameterBuffer.Dispose();
                    parameterBuffer = null;
                }
                if (bindingArray != null)
                {
                    int num10 = bindingArray.Length;
                    for (int m = 0; m < num10; m++)
                    {
                        if (bindingArray[m] != null)
                        {
                            bindingArray[m].Dispose();
                            bindingArray[m] = null;
                        }
                    }
                    bindingArray = null;
                }
                if ((flagArray != null) && (handleArray != null))
                {
                    int num9 = flagArray.Length;
                    for (int n = 0; n < num9; n++)
                    {
                        if (flagArray[n])
                        {
                            handleArray[n].DangerousRelease();
                        }
                    }
                }
            }
            return(stmt);
        }