Solved

Executing SQL Querys in Code

Posted on 2014-02-11
2
258 Views
Last Modified: 2014-02-13
;
Is there  a simpler approach to updating a SQL Table than all this?  All this cross linkage of Transactions, Querys and Databases?  Do all Querys need transactions?

  IBDatabase1.DatabaseName := 'c:\backupdbs\JPBD.IB';
  IBDatabase1.Params.Clear
  IBDatabase1.Params.Add('user_name=sysdba');
  IBDatabase1.Params.Add('password=masterkey');

  IBDatabase1.DefaultTransaction := IBTransaction1;
  IBTransaction1.DefaultDatabase := IBDatabase1;

  IBQuery1.Transaction := IBTransaction1;

  IBDatabase1.Open;
  IBQuery1.Database := IBDatabase1;
  IBQuery1.SQL.Clear;
  IBQuery1.SQL.Add('Insert into Employee(PersonID, LastName) Values(1, ''Price'')');
  IBQuery1.Transaction.StartTransaction;
  IBQuery1.ExecSQL;
  IBQuery1.Transaction.Commit;
  IBDatabase1.Close;
0
Comment
Question by:CiaoBaby
2 Comments
 
LVL 68

Expert Comment

by:Qlemo
ID: 39851890
That again depends on the database system you are using. But most times you do not need transactions, which results in autocommiting all changes without chance to rollback changes.

Transactions are used to bundle several commands into a single "atomic" operation. They don't make much sense with a single command.
0
 
LVL 33

Accepted Solution

by:
ste5an earned 500 total points
ID: 39852631
The IB prefix sounds like FireBird. And yes, here you need explicit transactions. Well, abstraction is your friend. Encapsulate theses actions in an appropriate class model.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Read about achieving the basic levels of HRIS security in the workplace.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now