View Issue Details

IDProjectCategoryView StatusLast Update
0037645FPCDatabasepublic2020-11-24 10:11
ReporterLuiz Americo Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformi386OSWindows 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0037645: SqlDb: Calling TSQLQuery.Prepare directly, opening, closing and re opening does not work with IBConnection
DescriptionWhen TSQLQuery.Prepare is called directly, query is open, closed and re opened, it does not work with IBConnection.

This use case is tested in TTestTSQLQuery.TestPrepareCount2 from DBTestFramework

Below is a patch that disposes cursor memory on UnPrepareStatement instead of FreeFldBuffers, making the cursor memory allocation balanced between PrepareStatement and UnPrepareStatement. This fixes the access violation, but now fails with another error:

TIBConnection : Fetch :
 -Dynamic SQL Error
 -SQL error code = -502
 -Attempt to reopen an open cursor
Exception class: EIBDatabaseError
at $006B6208 TIBCONNECTION__CHECKERROR, line 195 of D:/repositories/fpc-playground/packages/fcl-db/src/sqldb/interbase/ibconnection.pp

TagsNo tags attached.
Fixed in Revision47400
FPCOldBugId
FPCTarget3.2.2
Attached Files

Relationships

parent of 0038124 resolvedMichael Van Canneyt Regression after r47400: Firebird cannot CREATE or ALTER TABLE anymore 
related to 0031231 resolvedMichael Van Canneyt procedure TCustomSQLQuery.Prepare does not work 

Activities

Luiz Americo

2020-08-27 03:15

developer  

ibconnection-prepare-crash.diff (1,014 bytes)   
diff --git packages/fcl-db/src/sqldb/interbase/ibconnection.pp packages/fcl-db/src/sqldb/interbase/ibconnection.pp
index 51127ab83..7926f2b4c 100644
--- packages/fcl-db/src/sqldb/interbase/ibconnection.pp
+++ packages/fcl-db/src/sqldb/interbase/ibconnection.pp
@@ -899,6 +899,7 @@ procedure TIBConnection.UnPrepareStatement(cursor : TSQLCursor);
 
 begin
   with cursor as TIBcursor do
+  begin
     if assigned(StatementHandle) Then
       begin
         if isc_dsql_free_statement(@Status[0], @StatementHandle, DSQL_Drop) <> 0 then
@@ -906,6 +907,9 @@ begin
         StatementHandle := nil;
         FPrepared := False;
       end;
+    FreeSQLDABuffer(SQLDA);
+    FreeSQLDABuffer(in_SQLDA);
+  end;
 end;
 
 procedure TIBConnection.FreeSQLDABuffer(var aSQLDA : PXSQLDA);
@@ -949,8 +953,6 @@ procedure TIBConnection.FreeFldBuffers(cursor : TSQLCursor);
 begin
   with cursor as TIBCursor do
     begin
-    FreeSQLDABuffer(SQLDA);
-    FreeSQLDABuffer(in_SQLDA);
     SetLength(FieldBinding,0);
     end;
 end;

Michael Van Canneyt

2020-11-12 16:01

administrator   ~0126862

Fixed. Your patch was partially correct.

Turns out you need to create a cursor within firebird when using prepared queries.
We never noticed because we closed the statement when closing the dataset prior to the prepare fixes...

Thanks for reporting and for the patch.

Issue History

Date Modified Username Field Change
2020-08-27 03:15 Luiz Americo New Issue
2020-08-27 03:15 Luiz Americo File Added: ibconnection-prepare-crash.diff
2020-08-27 09:07 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-08-27 09:07 Michael Van Canneyt Status new => assigned
2020-11-12 16:01 Michael Van Canneyt Status assigned => resolved
2020-11-12 16:01 Michael Van Canneyt Resolution open => fixed
2020-11-12 16:01 Michael Van Canneyt Fixed in Version => 3.3.1
2020-11-12 16:01 Michael Van Canneyt Fixed in Revision => 47400
2020-11-12 16:01 Michael Van Canneyt FPCTarget => 3.2.2
2020-11-12 16:01 Michael Van Canneyt Note Added: 0126862
2020-11-14 00:34 Michael Van Canneyt Relationship added related to 0031231
2020-11-24 10:11 Ondrej Pokorny Relationship added parent of 0038124