function daOpenDataSet_(ADB: TIBDatabase;
const ATableName:
String;
const AFieldNames:
Array of String;
const ACondition:
String): TIBDataSet;
var
ibTr: TIBTransaction;
s:
String;
p: Pointer;
begin
p :=
nil;
Result :=
nil;
try
if ATableName = '
'
then
raise EDaDBError.Create(SDBENoTableName);
if Length(AFieldNames) = 0
then
raise EDaDBError.Create(SDBENoFieldName);
// if ACondition = '' then
// raise EDaDBError.Create(SDBENoCondition);
Result := TIBDataSet.Create(
nil);
ibTr := TIBTransaction.Create(Result);
ibTr.DefaultAction := TARollback;
ibTr.Params.Add(konDBReadOnlyTran);
ibTr.DefaultDatabase := ADB;
Result.Transaction := ibTr;
ibTr.StartTransaction;
if ACondition <> '
'
then
Result.SelectSQL.Text := Format('
SELECT %s FROM %s WHERE %s',
[daArrayToString(AFieldNames), ATableName, ACondition])
else
Result.SelectSQL.Text := Format('
SELECT %s FROM %s',
[daArrayToString(AFieldNames), ATableName]);
Result.Open;
//Muss Caller handeln ibdsFields.Transaction.Rollback;
except
on e:
Exception do begin
p := AcquireExceptionObject;
s := '
';
try
if (ADB <>
nil)
then
s := ADB.DatabaseName;
except end;
e.
Message := '
daDb.daOpenDataSet' +
SDBEErrRead+#13#10#09 +
SDBDataBase+'
: '+s+#13#10#09+
SDBTable+'
: '+ATableName+#13#10#09+
SDBField+'
: '+daArrayToString(AFieldNames)+#13#10#09+
SDBCondition+'
: '+ACondition+#13#10#09+
SPMErrMsg+'
: '+e.
Message+#13#10#09+
SPMErrCls+'
: '+e.ClassName+#13#10#09;
end;
//on e:Exception do begin
end;
if p <>
nil then begin
raise EDaDBError(p);
end;
end;