From 45f12594e91978b910eb7ad06a809b911c67abf4 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Mon, 2 Nov 2009 23:16:38 +0000 Subject: [PATCH] mysql_store_result() + mysql_free_result() are needed for all result queries, in order to unblock the connection. Fixes disconnecting + reconnect in query editor with multiple SELECT queries. --- source/mysql_connection.pas | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/source/mysql_connection.pas b/source/mysql_connection.pas index 66a6d13c..f44b7b56 100644 --- a/source/mysql_connection.pas +++ b/source/mysql_connection.pas @@ -306,18 +306,16 @@ begin Log(lcError, GetLastError); raise Exception.Create(GetLastError); end else begin - Result := nil; - // Affected rows are -1 for SELECT queries, 0 for UPDATE queries including - // admin commands e.g. FLUSH PRIVILEGES + // We must call mysql_store_result() + mysql_free_result() to unblock the connection + // See: http://dev.mysql.com/doc/refman/5.0/en/mysql-store-result.html FRowsAffected := mysql_affected_rows(FHandle); - if FRowsAffected = -1 then begin + Result := mysql_store_result(FHandle); + if Result <> nil then begin + FRowsFound := mysql_num_rows(Result); FRowsAffected := 0; - if DoStoreResult then begin - Result := mysql_store_result(FHandle); - if Result <> nil then - FRowsFound := mysql_num_rows(Result); - Log(lcDebug, IntToStr(RowsFound)+' rows found.'); - end; + Log(lcDebug, IntToStr(RowsFound)+' rows found.'); + if not DoStoreResult then + mysql_free_result(Result); end else begin // Query did not return a result FRowsFound := 0;