@@ -35,13 +35,10 @@ internal class GdsStatement : StatementBase
3535 private GdsTransaction _transaction ;
3636 protected Descriptor _parameters ;
3737 protected Descriptor _fields ;
38- protected StatementState _state ;
39- protected DbStatementType _statementType ;
4038 protected bool _allRowsFetched ;
4139 private Queue < DbValue [ ] > _rows ;
4240 private Queue < DbValue [ ] > _outputParams ;
4341 private int _fetchSize ;
44- private bool _returnRecordsAffected ;
4542
4643 #endregion
4744
@@ -90,47 +87,12 @@ public override Descriptor Fields
9087 get { return _fields ; }
9188 }
9289
93- public override int RecordsAffected { get ; protected set ; }
94-
95- public override bool IsPrepared
96- {
97- get
98- {
99- if ( _state == StatementState . Deallocated || _state == StatementState . Error )
100- {
101- return false ;
102- }
103- else
104- {
105- return true ;
106- }
107- }
108- }
109-
110- public override DbStatementType StatementType
111- {
112- get { return _statementType ; }
113- protected set { _statementType = value ; }
114- }
115-
116- public override StatementState State
117- {
118- get { return _state ; }
119- protected set { _state = value ; }
120- }
121-
12290 public override int FetchSize
12391 {
12492 get { return _fetchSize ; }
12593 set { _fetchSize = value ; }
12694 }
12795
128- public override bool ReturnRecordsAffected
129- {
130- get { return _returnRecordsAffected ; }
131- set { _returnRecordsAffected = value ; }
132- }
133-
13496 #endregion
13597
13698 #region Constructors
@@ -152,7 +114,6 @@ public GdsStatement(IDatabase db, TransactionBase transaction)
152114 }
153115
154116 _handle = IscCodes . INVALID_OBJECT ;
155- RecordsAffected = - 1 ;
156117 _fetchSize = 200 ;
157118 _rows = new Queue < DbValue [ ] > ( ) ;
158119 _outputParams = new Queue < DbValue [ ] > ( ) ;
@@ -183,11 +144,8 @@ public override void Dispose()
183144 _parameters = null ;
184145 _transaction = null ;
185146 _allRowsFetched = false ;
186- _state = StatementState . Deallocated ;
187- _statementType = DbStatementType . None ;
188147 _handle = 0 ;
189148 _fetchSize = 0 ;
190- RecordsAffected = 0 ;
191149 base . Dispose ( ) ;
192150 }
193151 }
@@ -235,7 +193,7 @@ public override void Prepare(string commandText)
235193
236194 try
237195 {
238- if ( _state == StatementState . Deallocated )
196+ if ( State == StatementState . Deallocated )
239197 {
240198 SendAllocateToBuffer ( ) ;
241199 _database . XdrStream . Flush ( ) ;
@@ -248,22 +206,20 @@ public override void Prepare(string commandText)
248206
249207 SendInfoSqlToBuffer ( StatementTypeInfoItems , IscCodes . STATEMENT_TYPE_BUFFER_SIZE ) ;
250208 _database . XdrStream . Flush ( ) ;
251- _statementType = ProcessStatementTypeInfoBuffer ( ProcessInfoSqlResponse ( _database . ReadResponse < GenericResponse > ( ) ) ) ;
252-
209+ StatementType = ProcessStatementTypeInfoBuffer ( ProcessInfoSqlResponse ( _database . ReadResponse < GenericResponse > ( ) ) ) ;
253210
254- _state = StatementState . Prepared ;
211+ State = StatementState . Prepared ;
255212 }
256213 catch ( IOException ex )
257214 {
258- if ( _state == StatementState . Allocated )
259- _state = StatementState . Error ;
215+ State = State == StatementState . Allocated ? StatementState . Error : State ;
260216 throw IscException . ForErrorCode ( IscCodes . isc_network_error , ex ) ;
261217 }
262218 }
263219
264220 public override void Execute ( )
265221 {
266- if ( _state == StatementState . Deallocated )
222+ if ( State == StatementState . Deallocated )
267223 {
268224 throw new InvalidOperationException ( "Statement is not correctly created." ) ;
269225 }
@@ -272,13 +228,11 @@ public override void Execute()
272228
273229 try
274230 {
275- RecordsAffected = - 1 ;
276-
277231 SendExecuteToBuffer ( ) ;
278232
279233 _database . XdrStream . Flush ( ) ;
280234
281- if ( _statementType == DbStatementType . StoredProcedure )
235+ if ( StatementType == DbStatementType . StoredProcedure )
282236 {
283237 ProcessStoredProcedureExecuteResponse ( _database . ReadResponse < SqlResponse > ( ) ) ;
284238 }
@@ -292,32 +246,36 @@ public override void Execute()
292246 _database . XdrStream . Flush ( ) ;
293247 RecordsAffected = ProcessRecordsAffectedBuffer ( ProcessInfoSqlResponse ( _database . ReadResponse < GenericResponse > ( ) ) ) ;
294248 }
249+ else
250+ {
251+ RecordsAffected = - 1 ;
252+ }
295253
296- _state = StatementState . Executed ;
254+ State = StatementState . Executed ;
297255 }
298256 catch ( IOException ex )
299257 {
300- _state = StatementState . Error ;
258+ State = StatementState . Error ;
301259 throw IscException . ForErrorCode ( IscCodes . isc_network_error , ex ) ;
302260 }
303261 }
304262
305263 public override DbValue [ ] Fetch ( )
306264 {
307- if ( _state == StatementState . Deallocated )
265+ if ( State == StatementState . Deallocated )
308266 {
309267 throw new InvalidOperationException ( "Statement is not correctly created." ) ;
310268 }
311- if ( _statementType == DbStatementType . StoredProcedure && ! _allRowsFetched )
269+ if ( StatementType == DbStatementType . StoredProcedure && ! _allRowsFetched )
312270 {
313271 _allRowsFetched = true ;
314272 return GetOutputParameters ( ) ;
315273 }
316- else if ( _statementType == DbStatementType . Insert && _allRowsFetched )
274+ else if ( StatementType == DbStatementType . Insert && _allRowsFetched )
317275 {
318276 return null ;
319277 }
320- else if ( _statementType != DbStatementType . Select && _statementType != DbStatementType . SelectForUpdate )
278+ else if ( StatementType != DbStatementType . Select && StatementType != DbStatementType . SelectForUpdate )
321279 {
322280 return null ;
323281 }
@@ -478,8 +436,7 @@ protected override void Free(int option)
478436
479437 protected bool FreeNotNeeded ( int option )
480438 {
481- // Does not seem to be possible or necessary to close
482- // an execute procedure statement.
439+ // does not seem to be possible or necessary to close an execute procedure statement
483440 if ( StatementType == DbStatementType . StoredProcedure && option == IscCodes . DSQL_close )
484441 {
485442 return true ;
@@ -509,7 +466,7 @@ protected void DoFreePacket(int option)
509466 }
510467 catch ( IOException ex )
511468 {
512- _state = StatementState . Error ;
469+ State = StatementState . Error ;
513470 throw IscException . ForErrorCode ( IscCodes . isc_network_error , ex ) ;
514471 }
515472 }
@@ -531,8 +488,8 @@ protected void ProcessAllocateResponce(GenericResponse response)
531488 {
532489 _handle = response . ObjectHandle ;
533490 _allRowsFetched = false ;
534- _state = StatementState . Allocated ;
535- _statementType = DbStatementType . None ;
491+ State = StatementState . Allocated ;
492+ StatementType = DbStatementType . None ;
536493 }
537494 #endregion
538495
@@ -542,7 +499,7 @@ protected void SendExecuteToBuffer()
542499 // this may throw error, so it needs to be before any writing
543500 var descriptor = WriteParameters ( ) ;
544501
545- if ( _statementType == DbStatementType . StoredProcedure )
502+ if ( StatementType == DbStatementType . StoredProcedure )
546503 {
547504 _database . XdrStream . Write ( IscCodes . op_execute2 ) ;
548505 }
@@ -568,7 +525,7 @@ protected void SendExecuteToBuffer()
568525 _database . XdrStream . Write ( 0 ) ;
569526 }
570527
571- if ( _statementType == DbStatementType . StoredProcedure )
528+ if ( StatementType == DbStatementType . StoredProcedure )
572529 {
573530 _database . XdrStream . WriteBuffer ( _fields ? . ToBlrArray ( ) ) ;
574531 _database . XdrStream . Write ( 0 ) ; // Output message number
@@ -603,7 +560,7 @@ protected override void TransactionUpdated(object sender, EventArgs e)
603560 Transaction . Update -= TransactionUpdate ;
604561 }
605562
606- _state = StatementState . Closed ;
563+ State = StatementState . Closed ;
607564 TransactionUpdate = null ;
608565 _allRowsFetched = false ;
609566 }
0 commit comments