示例#1
0
        // GetStatementHandle
        // ------------------
        // Try to return a cached statement handle.
        //
        // Creates a CmdWrapper object if necessary
        // If no handle is available a handle will be allocated.
        // Bindings will be unbound if a handle is cached and the bindings are invalid.
        //
        internal CMDWrapper GetStatementHandle()
        {
            // update the command wrapper object, allocate buffer
            // create reader object
            //
            if (_cmdWrapper == null)
            {
                _cmdWrapper = new CMDWrapper(_connection);

                Debug.Assert(null != _connection, "GetStatementHandle without connection?");
                _connection.AddWeakReference(this, OdbcReferenceCollection.CommandTag);
            }

            if (_cmdWrapper._dataReaderBuf == null)
            {
                _cmdWrapper._dataReaderBuf = new CNativeBuffer(4096);
            }

            // if there is already a statement handle we need to do some cleanup
            //
            if (null == _cmdWrapper.StatementHandle)
            {
                _isPrepared = false;
                _cmdWrapper.CreateStatementHandle();
            }
            else if ((null != _parameterCollection) && _parameterCollection.RebindCollection)
            {
                _cmdWrapper.FreeStatementHandle(ODBC32.STMT.RESET_PARAMS);
            }
            return(_cmdWrapper);
        }