From d33be19be08bd084620f1e46b36adb955a6b2a10 Mon Sep 17 00:00:00 2001 From: rosenfield Date: Fri, 5 Oct 2007 18:52:38 +0000 Subject: [PATCH] Nuke ExpectResultSet. Opted not to disable the mysql driver exceptions in zeos, instead used Anse's TZConnection.GetAffectedRowsFromLastPost(). (Messing with the internals here, please test...) --- source/childwin.pas | 22 ++++++---------- source/helpers.pas | 50 ------------------------------------- source/mysqlquerythread.pas | 26 +++++++++---------- 3 files changed, 20 insertions(+), 78 deletions(-) diff --git a/source/childwin.pas b/source/childwin.pas index a9883ff2..45144932 100644 --- a/source/childwin.pas +++ b/source/childwin.pas @@ -2808,27 +2808,19 @@ begin // ok, let's rock SQLstart := GetTickCount(); try - if ( ExpectResultSet( SQL[i] ) ) then + ds := GetResults( SQL[i], false, false ); + gridQuery.DataSource.DataSet := ds; + if ( ds <> nil ) then begin - ds := GetResults( SQL[i], false, false ); - gridQuery.DataSource.DataSet := ds; - if ( ds <> nil ) then - begin - fieldcount := ds.Fieldcount; - recordcount := ds.Recordcount; - end - else - begin - fieldcount := 0; - recordcount := 0; - end; + fieldcount := ds.Fieldcount; + recordcount := ds.Recordcount; rowsaffected := rowsaffected + TZQuery(ds).RowsAffected; end else begin - rowsaffected := rowsaffected + ExecUpdateQuery( SQL[i], false, false ); fieldcount := 0; recordcount := 0; + rowsaffected := FMysqlConn.Connection.GetAffectedRowsFromLastPost; end; except on E:Exception do @@ -5050,7 +5042,7 @@ begin try // Start query execution MysqlQuery := RunThreadedQuery(sql); - Result := TZQuery(MysqlQuery.MysqlDataset).RowsAffected; + Result := FMysqlConn.Connection.GetAffectedRowsFromLastPost; // Inspect query result code and log / notify user on failure if MysqlQuery.Result in [MQR_CONNECT_FAIL,MQR_QUERY_FAIL] then begin diff --git a/source/helpers.pas b/source/helpers.pas index 3ee6f4dd..b546b439 100644 --- a/source/helpers.pas +++ b/source/helpers.pas @@ -74,7 +74,6 @@ type function maskSql(sql_version: integer; str: String) : String; procedure ActivateWindow(Window : HWnd); procedure ShellExec( cmd: String; path: String = '' ); - function ExpectResultSet(ASql: String): Boolean; function getFirstWord( text: String ): String; function ConvertWindowsCodepageToMysqlCharacterSet(codepage: Cardinal): string; function GetFieldValue( Field: TField ): String; @@ -1885,55 +1884,6 @@ end; -{*** - Checks if the SQL will bring up any resultset. - Important to know for deciding on whether to do a - ZQuery.Open or ZQuery.ExecSQL - - @param string (part of) SQL-query - @return boolean - @see TMDIChild:ExecSQLClick - @see TMysqlQueryThread:Execute -} -function ExpectResultSet(ASql: String): Boolean; -const - RESULTSET_KEYWORDS : array[0..11] of string[10] = - ( - 'ANALYZE', - 'CALL', - 'CHECK', - 'DESC', - 'DESCRIBE', - 'EXECUTE', - 'EXPLAIN', - 'HELP', - 'OPTIMIZE', - 'REPAIR', - 'SELECT', - 'SHOW' - ); - NOTRESULTSET_SENTENCE : string[12] = 'INTO OUTFILE'; -var - kw : String; - i : Integer; -begin - Result := False; - - // Find keyword and check existance in const-array of resultset-keywords - kw := UpperCase( getFirstWord( ASql ) ); - for i := Low(RESULTSET_KEYWORDS) to High(RESULTSET_KEYWORDS) do - begin - if kw = RESULTSET_KEYWORDS[i] then - begin - Result := True; - break; - end; - end; - if Pos(NOTRESULTSET_SENTENCE, UpperCase(ASql)) > 0 then Result := False; -end; - - - {*** Returns first word of a given text @param string Given text diff --git a/source/mysqlquerythread.pas b/source/mysqlquerythread.pas index bfe4d5e7..aebb96a5 100644 --- a/source/mysqlquerythread.pas +++ b/source/mysqlquerythread.pas @@ -4,6 +4,7 @@ interface uses Windows, Messages, Forms, Db, Classes, ZConnection, ZDataSet, StdCtrls, SysUtils, + ZMessages, HeidiComp; {$IFDEF EXAMPLE_APP} @@ -232,14 +233,12 @@ begin end; end else begin try - if ExpectResultSet(FSql) then begin - r := RunDataQuery (FSql,TDataSet(q),ex,FCallback); - if r then begin - if q.State=dsBrowse then begin - // WTF? - end; - end; - end else r := RunUpdateQuery (FSql,TDataSet(q),ex,FCallBack); + r := RunDataQuery (FSql,TDataSet(q),ex,FCallback); + if r then begin + //if q.State=dsBrowse then begin + // WTF? + //end; + end; TMysqlQuery(FOwner).SetMysqlDataset(q); if r then SetState (MQR_SUCCESS,'SUCCESS') @@ -336,11 +335,12 @@ begin q.Active := True; Result := True; except - on E: Exception do - begin - AExceptionData := GetExceptionData(E); - end; - // EZSQLException + on E: Exception do begin + if E.Message = SCanNotOpenResultSet then begin + Result := true; + ADataset := nil; + end else AExceptionData := GetExceptionData(E); + end; end; end;