public ParserStateException(StatementState state, LexedToken curTok, AllowedTransition transitionRecord) : base($"Invalid token {curTok.TokenType.ToString()} in {state.ToString()}") { this.state = state; this.curTok = curTok; this.transitionRecord = transitionRecord; }
public static StatementState ProcessNumber(StatementState state) { switch (state) { case StatementState.None: return(StatementState.None); #region format case StatementState.FormatRowsEquals: return(StatementState.FormatRowsNumber); case StatementState.FormatColsEquals: return(StatementState.FormatColsNumber); case StatementState.FormatGenpagesEquals: return(StatementState.FormatGenpagesNumber); #endregion #region alter case StatementState.AlterApplicationLangId: return(StatementState.AlterApplicationLangIdNumber); #endregion } return(StatementState.None); }
protected override void Dispose(bool disposing) { if (!this.IsDisposed) { try { // release any unmanaged resources this.Release(); // release any managed resources if (disposing) { this.Clear(); this.db = null; this.fields = null; this.parameters = null; this.transaction = null; this.outputParams = null; this.allRowsFetched = false; this.recordsAffected = 0; this.state = StatementState.Deallocated; this.handle = 0; } } finally { base.Dispose(disposing); } } }
protected override void Dispose(bool disposing) { if (!_disposed) { try { if (disposing) { Release(); Clear(); _db = null; _fields = null; _parameters = null; _transaction = null; _outputParams = null; _statusVector = null; _allRowsFetched = false; _state = StatementState.Deallocated; _statementType = DbStatementType.None; _recordsAffected = 0; _handle.Dispose(); FetchSize = 0; } } finally { _disposed = true; base.Dispose(disposing); } } }
protected void ProcessAllocateResponce(GenericResponse response) { _handle = response.ObjectHandle; _allRowsFetched = false; _state = StatementState.Allocated; _statementType = DbStatementType.None; }
public override void Prepare(string commandText) { ClearAll(); try { if (_state == StatementState.Deallocated) { SendAllocateToBuffer(); _database.XdrStream.Flush(); ProcessAllocateResponce(_database.ReadGenericResponse()); } SendPrepareToBuffer(commandText); _database.XdrStream.Flush(); ProcessPrepareResponse(_database.ReadGenericResponse()); SendInfoSqlToBuffer(StatementTypeInfoItems, IscCodes.STATEMENT_TYPE_BUFFER_SIZE); _database.XdrStream.Flush(); _statementType = ProcessStatementTypeInfoBuffer(ProcessInfoSqlResponse(_database.ReadGenericResponse())); _state = StatementState.Prepared; } catch (IOException ex) { if (_state == StatementState.Allocated) { _state = StatementState.Error; } throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex); } }
protected override void Dispose(bool disposing) { if (!IsDisposed) { try { // release any unmanaged resources Release(); // release any managed resources if (disposing) { Clear(); _db = null; _fields = null; _parameters = null; _transaction = null; _outputParams = null; _allRowsFetched = false; _recordsAffected = 0; _state = StatementState.Deallocated; _handle = 0; } } finally { base.Dispose(disposing); } } }
public static StatementState ProcessSymbol(char ch, StatementState state) { switch (ch) { case '*': if (state == StatementState.Select) { return(StatementState.SelectStar); } break; case ',': switch (state) { case StatementState.SelectFromTable: return(StatementState.SelectFromTableComma); case StatementState.OrderByTableField: case StatementState.OrderByTableFieldAscDesc: return(StatementState.OrderByTableFieldComma); } break; case '.': if (state == StatementState.OrderByTable) { return(StatementState.OrderByTableDot); } break; case '=': if (state == StatementState.FormatRows) { return(StatementState.FormatRowsEquals); } if (state == StatementState.FormatCols) { return(StatementState.FormatColsEquals); } if (state == StatementState.FormatGenpages) { return(StatementState.FormatGenpagesEquals); } break; case '(': switch (state) { case StatementState.AlterApplicationPromptString: case StatementState.AlterApplicationCommentString: case StatementState.AlterApplicationLangIdNumber: case StatementState.AlterApplicationDescriptionString: return(StatementState.AlterApplicationBrackets); } break; } return(StatementState.None); }
static bool StatusIsValidForInitialization(StatementState targetStatus) { if (targetStatus == StatementState.Valid || targetStatus == StatementState.Invalid) { return(true); } return(false); }
public override void Execute() { if (_state == StatementState.Deallocated) { throw new InvalidOperationException("Statment is not correctly created."); } ClearStatusVector(); var inSqlda = IntPtr.Zero; var outSqlda = IntPtr.Zero; if (_parameters != null) { inSqlda = XsqldaMarshaler.MarshalManagedToNative(_db.Charset, _parameters); } if (_statementType == DbStatementType.StoredProcedure) { Fields.ResetValues(); outSqlda = XsqldaMarshaler.MarshalManagedToNative(_db.Charset, _fields); } var trHandle = _transaction.HandlePtr; _db.FbClient.isc_dsql_execute2( _statusVector, ref trHandle, ref _handle, IscCodes.SQLDA_VERSION1, inSqlda, outSqlda); if (outSqlda != IntPtr.Zero) { var descriptor = XsqldaMarshaler.MarshalNativeToManaged(_db.Charset, outSqlda, true); var values = new DbValue[descriptor.Count]; for (var i = 0; i < values.Length; i++) { values[i] = new DbValue(this, descriptor[i]); } _outputParams.Enqueue(values); } XsqldaMarshaler.CleanUpNativeData(ref inSqlda); XsqldaMarshaler.CleanUpNativeData(ref outSqlda); _db.ProcessStatusVector(_statusVector); UpdateRecordsAffected(); _state = StatementState.Executed; }
protected override void TransactionUpdated(object sender, EventArgs e) { if (Transaction != null && TransactionUpdate != null) { Transaction.Update -= TransactionUpdate; } _state = StatementState.Closed; TransactionUpdate = null; _allRowsFetched = false; }
static void EnsureValidStatusChange(StatementState?currentStatus, StatementState targetStatus) { if (targetStatus == StatementState.Undefined) { throw new InvalidOperationException($"Target status:{targetStatus} is invalid"); } //Undefined status can be changed (only) to active or inactive if (currentStatus == StatementState.Undefined) { if (StatusIsValidForInitialization(targetStatus)) { return; } } else if (currentStatus == null) { if (StatusIsValidForInitialization(targetStatus)) { return; } throw new InvalidOperationException( $"Uninitialized status can only be initialized with following statuses: \"{StatementState.Valid}\",\"{StatementState.Invalid}\""); } // var availableStatuses = Enum.GetValues(typeof(StatementState)).OfType <StatementState>(); //0 indexed enumerable var assignableStatuses = availableStatuses.Where(s => s != StatementState.Undefined); var numberOfAssgnableStatuses = assignableStatuses.Count(); var currentStatusId = (int)currentStatus; //Status id cant be 0 var nextStatusId = currentStatusId + 1; if (nextStatusId > numberOfAssgnableStatuses) { nextStatusId = 1; } //karoche wreze midis ra var nextStatus = (StatementState)nextStatusId; if (targetStatus != nextStatus) { throw new InvalidOperationException( $"Only status:{nextStatus} can be applied after current status:{currentStatus}"); } //Everything's Ok. Phew! }
public override void Prepare(string commandText) { ClearAll(); ClearStatusVector(); if (_state == StatementState.Deallocated) { Allocate(); } _fields = new Descriptor(1); var sqlda = XsqldaMarshaler.MarshalManagedToNative(_db.Charset, _fields); var trHandle = _transaction.HandlePtr; var buffer = _db.Charset.GetBytes(commandText); _db.FbClient.isc_dsql_prepare( _statusVector, ref trHandle, ref _handle, (short)buffer.Length, buffer, _db.Dialect, sqlda); var descriptor = XsqldaMarshaler.MarshalNativeToManaged(_db.Charset, sqlda); XsqldaMarshaler.CleanUpNativeData(ref sqlda); _db.ProcessStatusVector(_statusVector); _fields = descriptor; if (_fields.ActualCount > 0 && _fields.ActualCount != _fields.Count) { Describe(); } else { if (_fields.ActualCount == 0) { _fields = new Descriptor(0); } } _fields.ResetValues(); _statementType = GetStatementType(); _state = StatementState.Prepared; }
protected override void TransactionUpdated(object sender, EventArgs e) { lock (this) { if (this.Transaction != null && this.TransactionUpdate != null) { this.Transaction.Update -= this.TransactionUpdate; } this.state = StatementState.Closed; this.TransactionUpdate = null; this.allRowsFetched = false; } }
public override void Execute() { if (this.state == StatementState.Deallocated) { throw new InvalidOperationException("Statement is not correctly created."); } // Clear data this.Clear(); lock (this.database.SyncObject) { try { this.RecordsAffected = -1; this.SendExecuteToBuffer(); this.database.Flush(); if (this.statementType == DbStatementType.StoredProcedure) { this.ProcessStoredProcedureExecuteResponse(this.database.ReadSqlResponse()); } GenericResponse executeResponse = this.database.ReadGenericResponse(); this.ProcessExecuteResponse(executeResponse); // Updated number of records affected by the statement execution if (this.ReturnRecordsAffected && (this.StatementType == DbStatementType.Insert || this.StatementType == DbStatementType.Delete || this.StatementType == DbStatementType.Update || this.StatementType == DbStatementType.StoredProcedure)) { this.SendInfoSqlToBuffer(RowsAffectedInfoItems, IscCodes.ROWS_AFFECTED_BUFFER_SIZE); this.database.Flush(); this.RecordsAffected = this.ProcessRecordsAffectedBuffer(this.ProcessInfoSqlResponse(this.database.ReadGenericResponse())); } this.state = StatementState.Executed; } catch (IOException) { this.state = StatementState.Error; throw new IscException(IscCodes.isc_net_read_err); } } }
static void ChangeStatus(Statement user, StatementState targetStatus, bool force = false) { if (!force) { try { EnsureValidStatusChange(user.State, targetStatus); } catch (Exception e) { throw new InvalidOperationException($"Couldn't change status of user:{user.Name} current status:{user.State} to {targetStatus}. See inner exception for details", e); } } user.State = targetStatus; }
private void Allocate() { ClearStatusVector(); var dbHandle = _db.HandlePtr; _db.FbClient.isc_dsql_allocate_statement( _statusVector, ref dbHandle, ref _handle); _db.ProcessStatusVector(_statusVector); _allRowsFetched = false; _state = StatementState.Allocated; _statementType = DbStatementType.None; }
public override void Execute() { if (_state == StatementState.Deallocated) { throw new InvalidOperationException("Statement is not correctly created."); } Clear(); try { RecordsAffected = -1; SendExecuteToBuffer(); _database.XdrStream.Flush(); if (_statementType == DbStatementType.StoredProcedure) { ProcessStoredProcedureExecuteResponse(_database.ReadSqlResponse()); } GenericResponse executeResponse = _database.ReadGenericResponse(); ProcessExecuteResponse(executeResponse); if (ReturnRecordsAffected && (StatementType == DbStatementType.Insert || StatementType == DbStatementType.Delete || StatementType == DbStatementType.Update || StatementType == DbStatementType.StoredProcedure)) { SendInfoSqlToBuffer(RowsAffectedInfoItems, IscCodes.ROWS_AFFECTED_BUFFER_SIZE); _database.XdrStream.Flush(); RecordsAffected = ProcessRecordsAffectedBuffer(ProcessInfoSqlResponse(_database.ReadGenericResponse())); } _state = StatementState.Executed; } catch (IOException ex) { _state = StatementState.Error; throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex); } }
protected void DoFreePacket(int option) { try { SendFreeToBuffer(option); if (option == IscCodes.DSQL_drop) { _parameters = null; _fields = null; } Clear(); } catch (IOException ex) { _state = StatementState.Error; throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex); } }
public static StatementState ProcessStringLiteral(StatementState state) { switch (state) { case StatementState.None: return(StatementState.None); #region create case StatementState.CreateInterfacetypeTypeliblocator: return(StatementState.CreateInterfacetypeTypeliblocatorName); #endregion #region selects case StatementState.Select: // Optional name for select return(StatementState.Select); #endregion #region alter case StatementState.AlterApplicationAppIID: return(StatementState.AlterApplicationAppIIDName); case StatementState.AlterApplicationPrompt: return(StatementState.AlterApplicationPromptString); case StatementState.AlterApplicationComment: return(StatementState.AlterApplicationCommentString); case StatementState.AlterApplicationDescription: case StatementState.AlterApplicationDescriptionString: return(StatementState.AlterApplicationDescriptionString); case StatementState.AlterApplicationExtendsAppIID: return(StatementState.AlterApplicationExtendsAppIIDString); #endregion } return(StatementState.None); }
public override void Prepare(string commandText) { // Clear data this.Clear(); this.parameters = null; this.fields = null; lock (this.db) { if (this.state == StatementState.Deallocated) { // Allocate statement this.Allocate(); } try { this.db.Send.Write(IscCodes.op_prepare_statement); this.db.Send.Write(this.transaction.Handle); this.db.Send.Write(this.handle); this.db.Send.Write((int)this.db.Dialect); this.db.Send.Write(commandText); this.db.Send.WriteBuffer(DescribeInfoItems, DescribeInfoItems.Length); this.db.Send.Write(IscCodes.MAX_BUFFER_SIZE); this.db.Send.Flush(); GdsResponse r = this.db.ReadGenericResponse(); this.fields = this.ParseSqlInfo(r.Data, DescribeInfoItems); // Determine the statement type this.statementType = this.GetStatementType(); this.state = StatementState.Prepared; } catch (IOException) { this.state = StatementState.Error; throw new IscException(IscCodes.isc_net_read_err); } } }
private void Allocate() { lock (_db) { // Clear the status vector ClearStatusVector(); DatabaseHandle dbHandle = _db.HandlePtr; _db.FbClient.isc_dsql_allocate_statement( _statusVector, ref dbHandle, ref _handle); _db.ProcessStatusVector(_statusVector); _allRowsFetched = false; _state = StatementState.Allocated; _statementType = DbStatementType.None; } }
private void Allocate() { lock (this.db) { int[] statusVector = ExtConnection.GetNewStatusVector(); int dbHandle = this.db.Handle; int stmtHandle = this.handle; SafeNativeMethods.isc_dsql_allocate_statement( statusVector, ref dbHandle, ref stmtHandle); this.db.ParseStatusVector(statusVector); this.handle = stmtHandle; this.allRowsFetched = false; this.state = StatementState.Allocated; this.statementType = DbStatementType.None; } }
protected void DoFreePacket(int option) { try { SendFreeToBuffer(option); // Reset statement information if (option == IscCodes.DSQL_drop) { this.parameters = null; this.fields = null; } this.Clear(); } catch (IOException) { this.state = StatementState.Error; throw new IscException(IscCodes.isc_net_read_err); } }
public override void Prepare(string commandText) { // Clear data ClearAll(); lock (_database.SyncObject) { try { if (_state == StatementState.Deallocated) { // Allocate statement SendAllocateToBuffer(); _database.XdrStream.Flush(); ProcessAllocateResponce(_database.ReadGenericResponse()); } SendPrepareToBuffer(commandText); _database.XdrStream.Flush(); ProcessPrepareResponse(_database.ReadGenericResponse()); // Grab statement type SendInfoSqlToBuffer(StatementTypeInfoItems, IscCodes.STATEMENT_TYPE_BUFFER_SIZE); _database.XdrStream.Flush(); _statementType = ProcessStatementTypeInfoBuffer(ProcessInfoSqlResponse(_database.ReadGenericResponse())); _state = StatementState.Prepared; } catch (IOException ex) { // if the statement has been already allocated, it's now in error if (_state == StatementState.Allocated) { _state = StatementState.Error; } throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex); } } }
public override void Prepare(string commandText) { // Clear data this.ClearAll(); lock (this.database.SyncObject) { try { if (this.state == StatementState.Deallocated) { // Allocate statement this.SendAllocateToBuffer(); this.database.Flush(); this.ProcessAllocateResponce(this.database.ReadGenericResponse()); } this.SendPrepareToBuffer(commandText); this.database.Flush(); this.ProcessPrepareResponse(this.database.ReadGenericResponse()); // Grab statement type this.SendInfoSqlToBuffer(StatementTypeInfoItems, IscCodes.STATEMENT_TYPE_BUFFER_SIZE); this.database.Flush(); this.statementType = this.ProcessStatementTypeInfoBuffer(this.ProcessInfoSqlResponse(this.database.ReadGenericResponse())); this.state = StatementState.Prepared; } catch (IOException) { // if the statement has been already allocated, it's now in error if (this.state == StatementState.Allocated) { this.state = StatementState.Error; } throw new IscException(IscCodes.isc_net_read_err); } } }
protected override void Dispose(bool disposing) { lock (this) { if (!IsDisposed) { try { // release any unmanaged resources Release(); } catch { } finally { // release any managed resources if (disposing) { Clear(); _rows = null; _outputParams = null; _database = null; _fields = null; _parameters = null; _transaction = null; _allRowsFetched = false; _state = StatementState.Deallocated; _statementType = DbStatementType.None; _handle = 0; _fetchSize = 0; RecordsAffected = 0; } base.Dispose(disposing); } } } }
private void Allocate() { lock (this.db) { try { this.db.Send.Write(IscCodes.op_allocate_statement); this.db.Send.Write(this.db.Handle); this.db.Send.Flush(); this.handle = this.db.ReadGenericResponse().ObjectHandle; this.allRowsFetched = false; this.state = StatementState.Allocated; this.statementType = DbStatementType.None; } catch (IOException) { this.state = StatementState.Deallocated; throw new IscException(IscCodes.isc_net_read_err); } } }
public override void Dispose() { if (!_disposed) { _disposed = true; Release(); Clear(); _rows = null; _outputParams = null; _database = null; _fields = null; _parameters = null; _transaction = null; _allRowsFetched = false; _state = StatementState.Deallocated; _statementType = DbStatementType.None; _handle = 0; _fetchSize = 0; RecordsAffected = 0; base.Dispose(); } }
protected override void Free(int option) { // Does not seem to be possible or necessary to close // an execute procedure statement. if (this.StatementType == DbStatementType.StoredProcedure && option == IscCodes.DSQL_close) { return; } lock (this.db) { try { this.db.Send.Write(IscCodes.op_free_statement); this.db.Send.Write(this.handle); this.db.Send.Write(option); this.db.Send.Flush(); // Reset statement information if (option == IscCodes.DSQL_drop) { this.parameters = null; this.fields = null; } this.Clear(); this.allRowsFetched = false; this.db.ReadGenericResponse(); } catch (IOException) { this.state = StatementState.Error; throw new IscException(IscCodes.isc_net_read_err); } } }
private void ProcessElseElement(XmlProcessingInstruction pi, IXmlProcessorEngine engine, ref StatementState state) { AssertData(pi, pi.Name == ElsifPiName); if (state == StatementState.Collect) { state = StatementState.Finished; } else if (pi.Name == ElsePiName || engine.HasFlag(pi.Data)) { if (state == StatementState.Init) { state = StatementState.Collect; } } RemoveItSelf(pi); return; }
protected override void Dispose(bool disposing) { if (!IsDisposed) { try { // release any unmanaged resources Release(); // release any managed resources if (disposing) { Clear(); _db = null; _fields = null; _parameters = null; _transaction = null; _outputParams = null; _allRowsFetched = false; _recordsAffected = 0; _state = StatementState.Deallocated; _handle = 0; } } finally { base.Dispose(disposing); } } }
public override void Prepare(string commandText) { // Clear data ClearAll(); lock (_db) { // Clear the status vector ClearStatusVector(); // Allocate the statement if needed if (_state == StatementState.Deallocated) { Allocate(); } // Marshal structures to pointer // Setup fields structure _fields = new Descriptor(1); IntPtr sqlda = XsqldaMarshaler.MarshalManagedToNative(_db.Charset, _fields); int trHandle = _transaction.Handle; int stmtHandle = _handle; byte[] buffer = _db.Charset.GetBytes(commandText); _db.FbClient.isc_dsql_prepare( _statusVector, ref trHandle, ref stmtHandle, (short)buffer.Length, buffer, _db.Dialect, sqlda); // Marshal Pointer Descriptor descriptor = XsqldaMarshaler.MarshalNativeToManaged(_db.Charset, sqlda); // Free memory XsqldaMarshaler.CleanUpNativeData(ref sqlda); // Parse status vector _db.ParseStatusVector(_statusVector); // Describe fields _fields = descriptor; if (_fields.ActualCount > 0 && _fields.ActualCount != _fields.Count) { Describe(); } else { if (_fields.ActualCount == 0) { _fields = new Descriptor(0); } } // Reset actual field values _fields.ResetValues(); // Get Statement type _statementType = GetStatementType(); // Update state _state = StatementState.Prepared; } }
private void Allocate() { lock (this.db) { int[] statusVector = ExtConnection.GetNewStatusVector(); int dbHandle = this.db.Handle; int stmtHandle = this.handle; SafeNativeMethods.isc_dsql_allocate_statement( statusVector, ref dbHandle, ref stmtHandle); this.db.ParseStatusVector(statusVector); this.handle = stmtHandle; this.allRowsFetched = false; this.state = StatementState.Allocated; this.statementType = DbStatementType.None; } }
public override void Prepare(string commandText) { // Clear data ClearAll(); lock (_database.SyncObject) { try { if (_state == StatementState.Deallocated) { // Allocate statement SendAllocateToBuffer(); _database.XdrStream.Flush(); ProcessAllocateResponce(_database.ReadGenericResponse()); } SendPrepareToBuffer(commandText); _database.XdrStream.Flush(); ProcessPrepareResponse(_database.ReadGenericResponse()); // Grab statement type SendInfoSqlToBuffer(StatementTypeInfoItems, IscCodes.STATEMENT_TYPE_BUFFER_SIZE); _database.XdrStream.Flush(); _statementType = ProcessStatementTypeInfoBuffer(ProcessInfoSqlResponse(_database.ReadGenericResponse())); _state = StatementState.Prepared; } catch (IOException ex) { // if the statement has been already allocated, it's now in error if (_state == StatementState.Allocated) _state = StatementState.Error; throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex); } } }
public override void Prepare(string commandText) { // Clear data this.Clear(); this.parameters = null; this.fields = null; lock (this.db) { if (this.state == StatementState.Deallocated) { // Allocate statement this.Allocate(); } try { this.db.Send.Write(IscCodes.op_prepare_statement); this.db.Send.Write(this.transaction.Handle); this.db.Send.Write(this.handle); this.db.Send.Write((int)this.db.Dialect); this.db.Send.Write(commandText); this.db.Send.WriteBuffer(DescribeInfoItems, DescribeInfoItems.Length); this.db.Send.Write(IscCodes.MAX_BUFFER_SIZE); this.db.Send.Flush(); GdsResponse r = this.db.ReadGenericResponse(); this.fields = this.ParseSqlInfo(r.Data, DescribeInfoItems); // Determine the statement type this.statementType = this.GetStatementType(); this.state = StatementState.Prepared; } catch (IOException) { this.state = StatementState.Error; throw new IscException(IscCodes.isc_net_read_err); } } }
private void Allocate() { lock (_db) { // Clear the status vector ClearStatusVector(); int dbHandle = _db.Handle; int stmtHandle = _handle; _db.FbClient.isc_dsql_allocate_statement( _statusVector, ref dbHandle, ref stmtHandle); _db.ParseStatusVector(_statusVector); _handle = stmtHandle; _allRowsFetched = false; _state = StatementState.Allocated; _statementType = DbStatementType.None; } }
private void Allocate() { lock (this.db) { try { this.db.Send.Write(IscCodes.op_allocate_statement); this.db.Send.Write(this.db.Handle); this.db.Send.Flush(); this.handle = this.db.ReadGenericResponse().ObjectHandle; this.allRowsFetched = false; this.state = StatementState.Allocated; this.statementType = DbStatementType.None; } catch (IOException) { this.state = StatementState.Deallocated; throw new IscException(IscCodes.isc_net_read_err); } } }
public override void Execute() { if (this.state == StatementState.Deallocated) { throw new InvalidOperationException("Statment is not correctly created."); } // Clear data this.Clear(); lock (this.db) { try { byte[] descriptor = null; if (this.parameters != null) { XdrStream xdr = new XdrStream(this.db.Charset); xdr.Write(this.parameters); descriptor = xdr.ToArray(); xdr.Close(); } if (this.statementType == DbStatementType.StoredProcedure) { this.db.Send.Write(IscCodes.op_execute2); } else { this.db.Send.Write(IscCodes.op_execute); } this.db.Send.Write(this.handle); this.db.Send.Write(this.transaction.Handle); if (this.parameters != null) { this.db.Send.WriteBuffer(this.parameters.ToBlrArray()); this.db.Send.Write(0); // Message number this.db.Send.Write(1); // Number of messages this.db.Send.Write(descriptor, 0, descriptor.Length); } else { this.db.Send.WriteBuffer(null); this.db.Send.Write(0); this.db.Send.Write(0); } if (this.statementType == DbStatementType.StoredProcedure) { this.db.Send.WriteBuffer( (this.fields == null) ? null : this.fields.ToBlrArray()); this.db.Send.Write(0); // Output message number } this.db.Send.Flush(); if (this.db.NextOperation() == IscCodes.op_sql_response) { // This would be an Execute procedure this.outputParams.Enqueue(this.ReceiveSqlResponse()); } this.db.ReadGenericResponse(); // Updated number of records affected by the statement execution if (this.StatementType == DbStatementType.Insert || this.StatementType == DbStatementType.Delete || this.StatementType == DbStatementType.Update || this.StatementType == DbStatementType.StoredProcedure) { this.recordsAffected = this.GetRecordsAffected(); } else { this.recordsAffected = -1; } this.state = StatementState.Executed; } catch (IOException) { this.state = StatementState.Error; throw new IscException(IscCodes.isc_net_read_err); } } }
protected void ProcessAllocateResponce(GenericResponse response) { this.handle = response.ObjectHandle; this.allRowsFetched = false; this.state = StatementState.Allocated; this.statementType = DbStatementType.None; }
protected override void TransactionUpdated(object sender, EventArgs e) { lock (this) { if (this.Transaction != null && this.TransactionUpdate != null) { this.Transaction.Update -= this.TransactionUpdate; } this.state = StatementState.Closed; this.TransactionUpdate = null; this.allRowsFetched = false; } }
protected void DoFreePacket(int option) { try { SendFreeToBuffer(option); // Reset statement information if (option == IscCodes.DSQL_drop) { this.parameters = null; this.fields = null; } this.Clear(); } catch (IOException) { this.state = StatementState.Error; throw new IscException(IscCodes.isc_net_read_err); } }
public override void Execute() { if (this.state == StatementState.Deallocated) { throw new InvalidOperationException("Statement is not correctly created."); } // Clear data this.Clear(); lock (this.database.SyncObject) { try { this.RecordsAffected = -1; this.SendExecuteToBuffer(); this.database.Flush(); if (this.statementType == DbStatementType.StoredProcedure) { this.ProcessStoredProcedureExecuteResponse(this.database.ReadSqlResponse()); } GenericResponse executeResponse = this.database.ReadGenericResponse(); this.ProcessExecuteResponse(executeResponse); // Updated number of records affected by the statement execution if (this.ReturnRecordsAffected && (this.StatementType == DbStatementType.Insert || this.StatementType == DbStatementType.Delete || this.StatementType == DbStatementType.Update || this.StatementType == DbStatementType.StoredProcedure)) { this.SendInfoSqlToBuffer(RowsAffectedInfoItems, IscCodes.ROWS_AFFECTED_BUFFER_SIZE); this.database.Flush(); this.RecordsAffected = this.ProcessRecordsAffectedBuffer(this.ProcessInfoSqlResponse(this.database.ReadGenericResponse())); } this.state = StatementState.Executed; } catch (IOException) { this.state = StatementState.Error; throw new IscException(IscCodes.isc_net_read_err); } } }
public override void Prepare(string commandText) { // Clear data this.ClearAll(); lock (this.database.SyncObject) { try { if (this.state == StatementState.Deallocated) { // Allocate statement this.SendAllocateToBuffer(); this.database.Flush(); this.ProcessAllocateResponce(this.database.ReadGenericResponse()); } this.SendPrepareToBuffer(commandText); this.database.Flush(); this.ProcessPrepareResponse(this.database.ReadGenericResponse()); // Grab statement type this.SendInfoSqlToBuffer(StatementTypeInfoItems, IscCodes.STATEMENT_TYPE_BUFFER_SIZE); this.database.Flush(); this.statementType = this.ProcessStatementTypeInfoBuffer(this.ProcessInfoSqlResponse(this.database.ReadGenericResponse())); this.state = StatementState.Prepared; } catch (IOException) { // if the statement has been already allocated, it's now in error if (this.state == StatementState.Allocated) this.state = StatementState.Error; throw new IscException(IscCodes.isc_net_read_err); } } }
protected override void Dispose(bool disposing) { lock (this) { if (!IsDisposed) { try { // release any unmanaged resources Release(); } catch { } finally { // release any managed resources if (disposing) { Clear(); _rows = null; _outputParams = null; _database = null; _fields = null; _parameters = null; _transaction = null; _allRowsFetched = false; _state = StatementState.Deallocated; _statementType = DbStatementType.None; _handle = 0; _fetchSize = 0; RecordsAffected = 0; } base.Dispose(disposing); } } } }
protected void DoFreePacket(int option) { try { SendFreeToBuffer(option); // Reset statement information if (option == IscCodes.DSQL_drop) { _parameters = null; _fields = null; } Clear(); } catch (IOException ex) { _state = StatementState.Error; throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex); } }
protected override void Dispose(bool disposing) { if (!IsDisposed) { try { Release(); } catch { } finally { if (disposing) { Clear(); _db = null; _fields = null; _parameters = null; _transaction = null; _outputParams = null; _statusVector = null; _allRowsFetched = false; _state = StatementState.Deallocated; _statementType = DbStatementType.None; _recordsAffected = 0; _handle = 0; FetchSize = 0; } base.Dispose(disposing); } } }
protected override void Dispose(bool disposing) { if (!this.IsDisposed) { try { // release any unmanaged resources this.Release(); // release any managed resources if (disposing) { this.Clear(); this.db = null; this.fields = null; this.parameters = null; this.transaction = null; this.outputParams = null; this.allRowsFetched = false; this.recordsAffected = 0; this.state = StatementState.Deallocated; this.handle = 0; } } finally { base.Dispose(disposing); } } }
private void Allocate() { lock (this.db) { // Clear the status vector this.ClearStatusVector(); int dbHandle = this.db.Handle; int stmtHandle = this.handle; db.FbClient.isc_dsql_allocate_statement( this.statusVector, ref dbHandle, ref stmtHandle); this.db.ParseStatusVector(this.statusVector); this.handle = stmtHandle; this.allRowsFetched = false; this.state = StatementState.Allocated; this.statementType = DbStatementType.None; } }
public override void Execute() { if (_state == StatementState.Deallocated) { throw new InvalidOperationException("Statment is not correctly created."); } lock (_db) { // Clear the status vector ClearStatusVector(); // Marshal structures to pointer IntPtr inSqlda = IntPtr.Zero; IntPtr outSqlda = IntPtr.Zero; if (_parameters != null) { inSqlda = XsqldaMarshaler.MarshalManagedToNative(_db.Charset, _parameters); } if (_statementType == DbStatementType.StoredProcedure) { Fields.ResetValues(); outSqlda = XsqldaMarshaler.MarshalManagedToNative(_db.Charset, _fields); } int trHandle = _transaction.Handle; int stmtHandle = _handle; _db.FbClient.isc_dsql_execute2( _statusVector, ref trHandle, ref stmtHandle, IscCodes.SQLDA_VERSION1, inSqlda, outSqlda); if (outSqlda != IntPtr.Zero) { Descriptor descriptor = XsqldaMarshaler.MarshalNativeToManaged(_db.Charset, outSqlda, true); // This would be an Execute procedure DbValue[] values = new DbValue[descriptor.Count]; for (int i = 0; i < values.Length; i++) { values[i] = new DbValue(this, descriptor[i]); } _outputParams.Enqueue(values); } // Free memory XsqldaMarshaler.CleanUpNativeData(ref inSqlda); XsqldaMarshaler.CleanUpNativeData(ref outSqlda); _db.ParseStatusVector(_statusVector); UpdateRecordsAffected(); _state = StatementState.Executed; } }
protected override void Free(int option) { // Does not seem to be possible or necessary to close // an execute procedure statement. if (this.StatementType == DbStatementType.StoredProcedure && option == IscCodes.DSQL_close) { return; } lock (this.db) { try { this.db.Send.Write(IscCodes.op_free_statement); this.db.Send.Write(this.handle); this.db.Send.Write(option); this.db.Send.Flush(); // Reset statement information if (option == IscCodes.DSQL_drop) { this.parameters = null; this.fields = null; } this.Clear(); this.allRowsFetched = false; this.db.ReadGenericResponse(); } catch (IOException) { this.state = StatementState.Error; throw new IscException(IscCodes.isc_net_read_err); } } }
public override void Execute() { if (this.state == StatementState.Deallocated) { throw new InvalidOperationException("Statment is not correctly created."); } lock (this.db) { // Marshal structures to pointer XsqldaMarshaler marshaler = XsqldaMarshaler.Instance; IntPtr inSqlda = IntPtr.Zero; IntPtr outSqlda = IntPtr.Zero; if (this.parameters != null) { inSqlda = marshaler.MarshalManagedToNative(this.db.Charset, this.parameters); } if (this.statementType == DbStatementType.StoredProcedure) { this.Fields.ResetValues(); outSqlda = marshaler.MarshalManagedToNative(this.db.Charset, this.fields); } int[] statusVector = ExtConnection.GetNewStatusVector(); int trHandle = this.transaction.Handle; int stmtHandle = this.handle; SafeNativeMethods.isc_dsql_execute2( statusVector, ref trHandle, ref stmtHandle, IscCodes.SQLDA_VERSION1, inSqlda, outSqlda); if (outSqlda != IntPtr.Zero) { Descriptor descriptor = marshaler.MarshalNativeToManaged(this.db.Charset, outSqlda); // This would be an Execute procedure DbValue[] values = new DbValue[descriptor.Count]; for (int i = 0; i < values.Length; i++) { values[i] = new DbValue(this, descriptor[i]); } this.outputParams.Enqueue(values); } // Free memory marshaler.CleanUpNativeData(ref inSqlda); marshaler.CleanUpNativeData(ref outSqlda); this.db.ParseStatusVector(statusVector); this.UpdateRecordsAffected(); this.state = StatementState.Executed; } }
public override void Prepare(string commandText) { // Clear data this.ClearAll(); lock (this.db) { if (this.state == StatementState.Deallocated) { // Allocate statement this.Allocate(); } // Marshal structures to pointer XsqldaMarshaler marshaler = XsqldaMarshaler.Instance; // Setup fields structure this.fields = new Descriptor(1); IntPtr sqlda = marshaler.MarshalManagedToNative(this.db.Charset, this.fields); int[] statusVector = ExtConnection.GetNewStatusVector(); int trHandle = this.transaction.Handle; int stmtHandle = this.handle; byte[] buffer = this.db.Charset.GetBytes(commandText); SafeNativeMethods.isc_dsql_prepare( statusVector, ref trHandle, ref stmtHandle, (short)buffer.Length, buffer, this.db.Dialect, sqlda); // Marshal Pointer Descriptor descriptor = marshaler.MarshalNativeToManaged(this.db.Charset, sqlda); // Free memory marshaler.CleanUpNativeData(ref sqlda); // Parse status vector this.db.ParseStatusVector(statusVector); // Describe fields this.fields = descriptor; if (this.fields.ActualCount > 0 && this.fields.ActualCount != this.fields.Count) { this.Describe(); } else { if (this.fields.ActualCount == 0) { this.fields = new Descriptor(0); } } // Reset actual field values this.fields.ResetValues(); // Get Statement type this.statementType = this.GetStatementType(); // Update state this.state = StatementState.Prepared; } }
protected override void TransactionUpdated(object sender, EventArgs e) { lock (this) { if (Transaction != null && _TransactionUpdate != null) { Transaction.Update -= _TransactionUpdate; } _state = StatementState.Closed; _TransactionUpdate = null; _allRowsFetched = false; } }