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...)
This commit is contained in:
rosenfield
2007-10-05 18:52:38 +00:00
parent 0f7015bf61
commit d33be19be0
3 changed files with 20 additions and 78 deletions

View File

@ -2808,27 +2808,19 @@ begin
// ok, let's rock
SQLstart := GetTickCount();
try
if ( ExpectResultSet( SQL[i] ) ) 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;
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

View File

@ -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

View File

@ -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
//if q.State=dsBrowse then begin
// WTF?
//end;
end;
end;
end else r := RunUpdateQuery (FSql,TDataSet(q),ex,FCallBack);
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);
on E: Exception do begin
if E.Message = SCanNotOpenResultSet then begin
Result := true;
ADataset := nil;
end else AExceptionData := GetExceptionData(E);
end;
// EZSQLException
end;
end;