uses
..Ora,OdacVcl;
Function ....
var
oracleSession : TOraSession;
SQLQuery : TOraQuery;
SQLStatement : TStringList;
dbResult : TStringList;
begin
oracleSession := TOraSession.Create(
nil);
try
oracleSession.ConnectPrompt := false;
oracleSession.Options.Net := true;
oracleSession.Server := configData.getDatabaseSettings.dbServerAddress+'
:'+
intToStr(configData.getDatabaseSettings.dbListenerPort)+'
:'+
configData.getDatabaseSettings.dbSID;
oracleSession.Username := configData.getDatabaseSettings.dbUserName;
oracleSession.Password := configData.getDatabaseSettings.dbPassword;
try
oracleSession.Connect;
logData.addItem('
Connection to db established');
SQLQuery := TOraQuery.Create(
nil);
SQLStatement := TStringList.Create;
dbResult := TStringList.Create;
try
SQLQuery.Close;
SQLQuery.Session := oracleSession;
SQLStatement.Text := '
...';
SQLQuery.SQL := SQLStatement;
try
SQLQuery.Open;
except
on E:
Exception do
begin
logData.addItem('
SQL Error: '+E.
Message);
end;
end;
if SQLQuery.Active
then
if SQLQuery.RecordCount > 0
then
while not SQLQuery.Eof
do
begin
dbResult.Add(SQLQuery.Fields[0].asString+'
;'+SQLQuery.Fields[1].asString);
SQLQuery.Next;
end;
finally
if assigned(dbResult)
then
eNodeBList.Assign(dbResult)
else
eNodeBList :=
nil;
SQLQuery.Close;
freeAndNil(SQLQuery);
freeAndNil(SQLStatement);
freeAndNil(dbResult);
end;
except
on E:
Exception do
logData.addItem('
Error connecting to the database: '+e.
Message);
end;
finally
oracleSession.Disconnect;
logData.addItem('
Connection to db closed');
freeAndNil(oracleSession);
result := eNodeBList;
end;
end;