Subject | Re: [IBO] Finding the right record |
---|---|
Author | hans@hoogstraat.ca |
Post date | 2001-08-22T06:03:48Z |
For my convertion test,
I dreamt up something simular for a numbered itemized grid.
Auto renumbers any inserts or append.
Table.BufferSynchroFlags := [bsAfterEdit];
ICRENO = UniqueNum
ENUM = EntryNo
CODE = Description
=================
procedure GridEnumKeys(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
temp : string;
Enum : Integer;
BookMark : TBookMark;
TABLE :TIBOQuery;
begin
TABLE := TIBOQuery(TwwDBGrid(Sender).DataSource.DataSet);
with DM do
begin
if Key = VK_INSERT then
begin
Key := 0;
if TABLE.IsEmpty then
begin
try
TABLE.Append;
TABLE['ENUM'] := 1;
TABLE['CODE'] := '';
TABLE.Post;
except
end;
end
else
begin
if Table.State <> dsBrowse then
Exit;
Enum := TABLE['ENUM'];
BookMark := Table.GetBookMark;
try
TABLE.Insert;
TABLE['ENUM'] := -Enum;
TABLE['CODE'] := '';
TABLE.Post;
except
end;
TABLE.Refresh;
Table.GoToBookMark(BookMark);
Table.FreeBookMark(BookMark);
while (not TABLE.Bof) and (TABLE['CODE'] <> '') do
Table.Prior;
end;
end
else
if Key = VK_DOWN then
begin
if TABLE.IsEmpty then
begin
try
TABLE.Append;
TABLE['ENUM'] := 1;
TABLE['CODE'] := '';
TABLE.Post;
except
end;
end
else
if TABLE.Eof then
begin
Key := 0;
if TABLE['CODE'] <> '' then
begin
try
TABLE.Append;
TABLE['ENUM'] := -9999999999;
TABLE['CODE'] := '';
TABLE.Post;
except
end;
TABLE.Refresh;
TABLE.Last;
end;
end;
end;
end;
end;
==================
For table CMPEV:
CREATE TRIGGER CMPEV_AFTER_INSERT
AFTER INSERT
POSITION 0
AS
DECLARE VARIABLE ICRECNO INTEGER;
DECLARE VARIABLE ENUM INTEGER;
DECLARE VARIABLE NEWENUM INTEGER;
DECLARE VARIABLE INSERTNO INTEGER;
DECLARE VARIABLE RENUM INTEGER;
DECLARE VARIABLE INSERTAT INTEGER;
BEGIN
RENUM = 0;
NEWENUM = NEW.ENUM;
INSERTNO = -NEWENUM;
FOR SELECT
ICRECNO,
ENUM
FROM CMPEV
WHERE ICRECNO = NEW.ICRECNO
AND ENUM >= 0
ORDER BY ENUM
INTO
:ICRECNO,
:ENUM
DO
BEGIN
RENUM = RENUM + 1;
IF (INSERTNO = ENUM) THEN
INSERTNO = RENUM;
UPDATE CMPEV
SET ENUM = :RENUM
WHERE ICRECNO = :ICRECNO
AND ENUM = :ENUM;
END
SELECT MAX(ENUM)+1 FROM CMPEV
WHERE ICRECNO = NEW.ICRECNO
INTO
:RENUM;
IF (NEWENUM = -9999999999) THEN
BEGIN
UPDATE CMPEV
SET ENUM = :RENUM
WHERE ICRECNO = NEW.ICRECNO
AND ENUM = :NEWENUM;
END
ELSE
BEGIN
FOR SELECT
ICRECNO,
ENUM
FROM CMPEV
WHERE ICRECNO = NEW.ICRECNO
AND ENUM >= 0
ORDER BY ENUM DESC
INTO
:ICRECNO,
:ENUM
DO
BEGIN
UPDATE CMPEV
SET ENUM = :RENUM
WHERE ICRECNO = :ICRECNO
AND ENUM = :ENUM;
RENUM = RENUM - 1;
IF (ENUM = INSERTNO) THEN
BEGIN
INSERTAT = RENUM;
RENUM = RENUM - 1;
END
END
UPDATE CMPEV
SET ENUM = :INSERTAT
WHERE ICRECNO = :ICRECNO
AND ENUM = :NEWENUM;
END
END
Hope of some use, works great for table ledger work.
=================
Jason Wharton wrote:
I dreamt up something simular for a numbered itemized grid.
Auto renumbers any inserts or append.
Table.BufferSynchroFlags := [bsAfterEdit];
ICRENO = UniqueNum
ENUM = EntryNo
CODE = Description
=================
procedure GridEnumKeys(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
temp : string;
Enum : Integer;
BookMark : TBookMark;
TABLE :TIBOQuery;
begin
TABLE := TIBOQuery(TwwDBGrid(Sender).DataSource.DataSet);
with DM do
begin
if Key = VK_INSERT then
begin
Key := 0;
if TABLE.IsEmpty then
begin
try
TABLE.Append;
TABLE['ENUM'] := 1;
TABLE['CODE'] := '';
TABLE.Post;
except
end;
end
else
begin
if Table.State <> dsBrowse then
Exit;
Enum := TABLE['ENUM'];
BookMark := Table.GetBookMark;
try
TABLE.Insert;
TABLE['ENUM'] := -Enum;
TABLE['CODE'] := '';
TABLE.Post;
except
end;
TABLE.Refresh;
Table.GoToBookMark(BookMark);
Table.FreeBookMark(BookMark);
while (not TABLE.Bof) and (TABLE['CODE'] <> '') do
Table.Prior;
end;
end
else
if Key = VK_DOWN then
begin
if TABLE.IsEmpty then
begin
try
TABLE.Append;
TABLE['ENUM'] := 1;
TABLE['CODE'] := '';
TABLE.Post;
except
end;
end
else
if TABLE.Eof then
begin
Key := 0;
if TABLE['CODE'] <> '' then
begin
try
TABLE.Append;
TABLE['ENUM'] := -9999999999;
TABLE['CODE'] := '';
TABLE.Post;
except
end;
TABLE.Refresh;
TABLE.Last;
end;
end;
end;
end;
end;
==================
For table CMPEV:
CREATE TRIGGER CMPEV_AFTER_INSERT
AFTER INSERT
POSITION 0
AS
DECLARE VARIABLE ICRECNO INTEGER;
DECLARE VARIABLE ENUM INTEGER;
DECLARE VARIABLE NEWENUM INTEGER;
DECLARE VARIABLE INSERTNO INTEGER;
DECLARE VARIABLE RENUM INTEGER;
DECLARE VARIABLE INSERTAT INTEGER;
BEGIN
RENUM = 0;
NEWENUM = NEW.ENUM;
INSERTNO = -NEWENUM;
FOR SELECT
ICRECNO,
ENUM
FROM CMPEV
WHERE ICRECNO = NEW.ICRECNO
AND ENUM >= 0
ORDER BY ENUM
INTO
:ICRECNO,
:ENUM
DO
BEGIN
RENUM = RENUM + 1;
IF (INSERTNO = ENUM) THEN
INSERTNO = RENUM;
UPDATE CMPEV
SET ENUM = :RENUM
WHERE ICRECNO = :ICRECNO
AND ENUM = :ENUM;
END
SELECT MAX(ENUM)+1 FROM CMPEV
WHERE ICRECNO = NEW.ICRECNO
INTO
:RENUM;
IF (NEWENUM = -9999999999) THEN
BEGIN
UPDATE CMPEV
SET ENUM = :RENUM
WHERE ICRECNO = NEW.ICRECNO
AND ENUM = :NEWENUM;
END
ELSE
BEGIN
FOR SELECT
ICRECNO,
ENUM
FROM CMPEV
WHERE ICRECNO = NEW.ICRECNO
AND ENUM >= 0
ORDER BY ENUM DESC
INTO
:ICRECNO,
:ENUM
DO
BEGIN
UPDATE CMPEV
SET ENUM = :RENUM
WHERE ICRECNO = :ICRECNO
AND ENUM = :ENUM;
RENUM = RENUM - 1;
IF (ENUM = INSERTNO) THEN
BEGIN
INSERTAT = RENUM;
RENUM = RENUM - 1;
END
END
UPDATE CMPEV
SET ENUM = :INSERTAT
WHERE ICRECNO = :ICRECNO
AND ENUM = :NEWENUM;
END
END
Hope of some use, works great for table ledger work.
=================
Jason Wharton wrote:
>
> Write a stored procedure that attempts the insert and then have it catch the
> exception of a duplicate key violation and do the update. This way you don't
> select any records to the client whatever, you only send the information to
> the server once and it does the insert or update as appropriate.
>
> I've mentioned this method many times over. I recommend you search the
> archives for it.
>
> In a support system I would like to design I'd put a link right in here for
> you...
>
> Regards,
> Jason Wharton
> CPS - Mesa AZ
> http://www.ibobjects.com
>
> ----- Original Message -----
> From: "Walter Araújo Franco" <warty@...>
> To: "IBObjects" <ibobjects@yahoogroups.com>
> Sent: Tuesday, August 21, 2001 7:11 PM
> Subject: [IBO] Finding the right record
>
> Hi,
>
> A doubt about "how to develop",
> With Paradox (argh), i used to do:
> Table.setkey;
> tablePK.value:=avalue;
> if table.gotokey then table.edit
> else table.insert;
>
> With queries, i know that i have to use the "where" clause, but, if i have
> to read a thousand of new and updated record, it won't make my database go
> down? or slowly?
> Or there's another way to locate the record in a faster time?
> txs in advance....
>
> []'s
>
> Walter A. Franco
> SysMaker Sistemas
> Poços de Caldas - MG
> UIN 11.606.129
>
> [Non-text portions of this message have been removed]
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/