Subject | SQL2GDB fix |
---|---|
Author | benadembaba |
Post date | 2002-09-14T12:41:42Z |
Hi,
When there is a single record in a table, issuing
SELECT MAX() results in an EOleException with this
message: 'No value given for one or more required
parameters'
As a workaround, here is my fix. Actually, since
there is a likelyhood that Nil can be returned
from TConvertInfo.OpenRecordset(), all routines
using that should be corrected to accomodate for
this --but I have only fixed TConvertInfo.MaxFieldValue()
as it is the one immediately affected by the exception.
Cheers,
Adem
Function TConvertInfo.MaxFieldValue(Const TableName, FieldName:
String): Integer;
Var
CommandText: String;
Fld: Field;
Rst: _Recordset;
Begin
{ Fix suggested by Woody [woody.tmw@...]. }
CommandText := 'SELECT MAX(' + GetProviderFieldName(FieldName) + ')
FROM ' + TableName;
Rst := OpenRecordset(CommandText);
If Assigned(Rst) Then Begin {added by adembaba@...}
If Rst.EOF Then Result := 0
Else Begin
{ It has been reported that the correct value will not always
be returned when the recordset is empty. Odd. }
Fld := Rst.Fields.Item[0];
If VarIsNull(Fld.Value) Then Result := 0
Else Result := Fld.Value;
End;
End Else Result := 0; {added by adembaba@...}
End;
Function TConvertInfo.OpenRecordset(Const CommandText: String):
_Recordset;
Var
ConnDisp: IDispatch;
Conn: _Connection;
Affected: OleVariant;
Begin
ConnDisp := FCatalog.Get_ActiveConnection;
Conn := ConnDisp As _Connection;
Try
Result := Conn.Execute(CommandText, Affected, 0);
Except
On E: Exception Do Begin
ShowMessage(CommandText + #13#10 + #13#10 + E.Message);
Result := Nil;
End;
End;
End;
When there is a single record in a table, issuing
SELECT MAX() results in an EOleException with this
message: 'No value given for one or more required
parameters'
As a workaround, here is my fix. Actually, since
there is a likelyhood that Nil can be returned
from TConvertInfo.OpenRecordset(), all routines
using that should be corrected to accomodate for
this --but I have only fixed TConvertInfo.MaxFieldValue()
as it is the one immediately affected by the exception.
Cheers,
Adem
Function TConvertInfo.MaxFieldValue(Const TableName, FieldName:
String): Integer;
Var
CommandText: String;
Fld: Field;
Rst: _Recordset;
Begin
{ Fix suggested by Woody [woody.tmw@...]. }
CommandText := 'SELECT MAX(' + GetProviderFieldName(FieldName) + ')
FROM ' + TableName;
Rst := OpenRecordset(CommandText);
If Assigned(Rst) Then Begin {added by adembaba@...}
If Rst.EOF Then Result := 0
Else Begin
{ It has been reported that the correct value will not always
be returned when the recordset is empty. Odd. }
Fld := Rst.Fields.Item[0];
If VarIsNull(Fld.Value) Then Result := 0
Else Result := Fld.Value;
End;
End Else Result := 0; {added by adembaba@...}
End;
Function TConvertInfo.OpenRecordset(Const CommandText: String):
_Recordset;
Var
ConnDisp: IDispatch;
Conn: _Connection;
Affected: OleVariant;
Begin
ConnDisp := FCatalog.Get_ActiveConnection;
Conn := ConnDisp As _Connection;
Try
Result := Conn.Execute(CommandText, Affected, 0);
Except
On E: Exception Do Begin
ShowMessage(CommandText + #13#10 + #13#10 + E.Message);
Result := Nil;
End;
End;
End;