Locate command returns false when next record exists

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Leonard Gojer

Locate command returns false when next record exists

Post by Leonard Gojer » Mon 29 Nov 2004 18:03

Here is a program that I am developing as a template. It does
everything right, except that after finding the first record while
attempting to list all records, it fails to find the second record in
the database, which is actually there. Can you tell why it is doing
this?
{$APPTYPE CONSOLE}
{-------------------------------------------------------}
{ Database Test1: declared in Orace PLSQL as }
{ create table test1( }
{ key : varchar(30), }
{ data : varchar(30)); }
{-------------------------------------------------------}
program p1;
uses
System,OdacVcl,DBAccess, Ora, OraAlerter, Db,
Messages, SysUtils, Classes, Controls, MemDS, OraSmart;


var
flag : boolean;
k : integer;
OraSession1 : TOraSession;
key1 : string;
key2 : string;
data1 : string;
test1 : TOraTable;
tmem1 : TMemDataSet;
flag2 : boolean;

begin
flag := false;
OraSession1 := TOraSession.Create(nil);
OraSession1.Server := 'dbgojer';
OraSession1.Password := 'shlock';
OraSession1.Username := 'SYSTEM';
OraSession1.Connect;
test1 := TOraTable.Create(nil);
test1.TableName := 'TEST1';
test1.Open;
tmem1 := TMemDataSet.Create(nil);
tmem1.Open;
while not flag do
begin
writeln;
writeln('Menu');
writeln('1 - insert record');
writeln('2 - delete record');
writeln('3 - search record');
writeln('4 - list all records');
writeln('5 - quit program');
write('> ');
readln(k);
case k of
1 : begin
write('Enter key: ');
readln(key1);
write('Enter data: ');
readln(data1);
test1.Insert;
test1.FieldByName('KEY').AsString := key1;
test1.FieldByName('DATA').AsString := data1;
test1.Post;
end;
2 : begin
write('Enter key: ');
readln(key1);
try
test1.Locate('KEY',key1,[loPartialKey]);
test1.Delete;
test1.Post;
except
end;
end;
3 : begin
write('Enter key: ');
readln(key1);
test1.Locate('KEY',key1,[loPartialKey]);
data1 := test1.FieldByName('DATA').AsString;
writeln('Data1: ',data1);
end;
4 : begin
key1 := '';
test1.LocateEx('KEY',key1,[]);
key2 := test1.FieldByName('KEY').AsString;
data1 := test1.FieldByName('DATA').AsString;
writeln('Key1: ',key2:20,' Data1: ',Data1);
flag2 := true;
while flag2 do
begin
flag2 := test1.Locate('KEY',key1,[]);
key2 := test1.FieldByName('KEY').AsString;
data1 := test1.FieldByName('DATA').AsString;
if flag2 then writeln('Key1: ',key2:20,' Data1: ',Data1);
end;
end;
5 : begin
flag := true;
end;
end;
end;
test1.Close;
OraSession1.Disconnect;
end.

Leonard Gojer

I figured it out, so don't answer it

Post by Leonard Gojer » Mon 29 Nov 2004 23:05

I figured it out, so don't answer it

Post Reply