Solved

Executing SQL Querys in Code

Posted on 2014-02-11
2
255 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 32

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Creating and Managing Databases with phpMyAdmin in cPanel.
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

757 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