Solved

Firebird+Delphi 7 Problem with 0 results found

Posted on 2009-03-31
4
320 Views
Last Modified: 2013-12-09
Hey all,

Provided some code before which I use to update a record in my Firebird database; however, sometimes the main_boost.caption isn't found in the db (which is correct, not every entry is in the db) - and if a record isn't found then nothing should happen, if the record is found however then the Edit/Post procedure should begin.
Lag.close;
Lag.sql.text := 'select * from lag where klubb = '''+main_boost.caption+'''';
Lag.Open;
Lag.First;
Lag.Edit;
Lag['Off'] := inttostr(strtoint(Lag['Off']) - 3);
Lag['Def'] := inttostr(strtoint(Lag['Def']) - 3);
Lag.Post;
end;

Open in new window

0
Comment
Question by:MerlaP83
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24030698
have you ever heard of a update statement ?


Lag.SQL.Text := 
  'update lag                       '+
  'set Off = Off - 3, Def = Def - 3 '+
  'where klubb = :klubb             ';
Lag.Prepare;
Lag.ParamByName('klubb').AsString := main_boost.caption;
Lag.ExecuteSql;
// number of changed records:
ShowMessage(Format('Affected records: %d ', [Lag.AffectedRecords]));

Open in new window

0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 125 total points
ID: 24030721
or


Lag.close;
Lag.sql.text := 'select * from lag where klubb = ' + QuotedStr(main_boost.caption);
Lag.Open;
if not Lag.IsEmpty then 
begin
  Lag.Edit;
  Lag['Off'] := inttostr(strtoint(Lag['Off']) - 3);
  Lag['Def'] := inttostr(strtoint(Lag['Def']) - 3);
  Lag.Post;
end;

Open in new window

0
 

Author Comment

by:MerlaP83
ID: 24030788
Thank you.

Which solution would you prefer?

The first solution gave me Undeclared identifier on Prepare, Parambyname, ExecuteSQL and AffectedRecords (Using Firebird+Zeos). The second solution worked perfect.
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24030888
well most certainly try and do as many changes with a update statement
don't have zeos here atm, i'll have to check that tomorrow ...
i'm guessing:
ParamByName('X') should be Parameters.ParamByName('X)
ExecuteSql should be Execute
...

but this is for sample 1:
send script to server (some 100 bytes over network)
let server execute script
server returns number of records (some 10 bytes over network)

sample 2:
send script to server (some 100 bytes over network)
server returns the dataset (if any, probably 100 bytes per record)
dataset copies this set to memory
for each record
  you check the record in memory
  you edit the data locally
  you tell the server the record changed (probably 100 bytes per record)
  server returns number of records affected (some 10 bytes over network)

do you understand why you need to go for script 1 ?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question