The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Databases
> Firebird SQL Development
|
How to know the Records affected in a Transaction
Discuss How to know the Records affected in a Transaction in the Firebird SQL Development forum on Dev Shed. How to know the Records affected in a Transaction Firebird SQL Development forum discussing administration, Firebird SQL syntax, or other Firebird SQL-related topics. Firebird is the evolution of Borland's Interbase product.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 8th, 2011, 03:20 AM
|
 |
Contributing User
|
|
Join Date: Aug 2008
Posts: 75
  
Time spent in forums: 1 Day 10 h 31 m 7 sec
Reputation Power: 8
|
|
|
How to know the Records affected in a Transaction
Hi All,
Is there any way to determine the tables & rows affected in a transactions in the DATABASE TRANSACTION COMMIT TRIGGER?
Thanks in advance
Bij
|

January 9th, 2011, 12:21 AM
|
|
Contributing User
|
|
Join Date: Jan 2006
Location: Carlsbad, CA
|
|
|
What are you trying to discover?
Theoretically, one transaction could cover hundreds of different SQL statements.
|

January 9th, 2011, 01:09 AM
|
 |
Contributing User
|
|
Join Date: Aug 2008
Posts: 75
  
Time spent in forums: 1 Day 10 h 31 m 7 sec
Reputation Power: 8
|
|
|
Thanks Clivew
Thanks Clivew,
I have a table of accounts details with field Debit,Credit.
The sum of the debit ,Credit in this table must be equal.
So i want to check whether the debit , credit total is the same on committing the transaction.
thanks
|

January 9th, 2011, 12:37 PM
|
|
Contributing User
|
|
Join Date: Jan 2006
Location: Carlsbad, CA
|
|
|
Well, run a query to check that they match BEFORE you COMMIT.
If they do not match issue a ROLLBACK instead and issue some appropriate warning.
Naturally you will need to make sure that you do not have any sort of "Commit On Post" option set and handle your own COMMIT and ROLLBACK instructions.
|

January 9th, 2011, 10:25 PM
|
 |
Contributing User
|
|
Join Date: Aug 2008
Posts: 75
  
Time spent in forums: 1 Day 10 h 31 m 7 sec
Reputation Power: 8
|
|
Thanks clivew,
ok . but in my case, i have to be add more than one records to the table before commit.
Quote: | Originally Posted by clivew Well, run a query to check that they match BEFORE you COMMIT.
If they do not match issue a ROLLBACK instead and issue some appropriate warning. |
I think running a query to sum all the records( may have millions) for every insert will slow down my insert process, Instead if i get the affected records in the current transaction , it will will be performance gain .
regards
|

January 10th, 2011, 12:11 PM
|
|
Contributing User
|
|
Join Date: Jan 2006
Location: Carlsbad, CA
|
|
|
I think you need to show us your code / SQL to get a better understanding of what you are doing.
If your logic is watertight and you do all the debits and credits inside a single transaction
there should be no problem if no exceptions are raised.
If any exceptions are raised rollback the entire transaction and address the problem.
There should be no need to do any counting or summing.
|

January 10th, 2011, 02:03 PM
|
 |
Contributing User
|
|
Join Date: Aug 2008
Posts: 75
  
Time spent in forums: 1 Day 10 h 31 m 7 sec
Reputation Power: 8
|
|
Quote: | Originally Posted by clivew I think you need to show us your code / SQL to get a better understanding of what you are doing.
If your logic is watertight and you do all the debits and credits inside a single transaction
there should be no problem if no exceptions are raised.
If any exceptions are raised rollback the entire transaction and address the problem.
There should be no need to do any counting or summing. |
Well, i will explain the things in detail (Kindly forgive my bad english)
I have a account DB to store vouches
I am using two tables Acc_head and ACC_detail tables for that purpose. Following is the basic structure
Acc_head
ID int (primaryKey)
VocDate (date)
Narration varchar(100)
ACC_detail
ID int (primaryKey)
Header_ID int (foreign Key ->Acc_head)
LedgerID int ( foreign Key ->Acc_Ledger)
Debit Numeric,
Credit Numeric
Each voucher may have multiple credit or multiple debit , but the sum of the debit and credit in the vouchers will be the same.. so called tallied
All my other flow is designed based on the assumption that all the vouchers are tallied. So i need to ensure that the sum(Debit) , sum(credit) in the ACC_detail will always tallied.
The user may insert the data through the UI ( here we can check the data validity at client side) or sometimes using the SQL ...
When the user inputs data using SQL, i am not able to validated the data. since the user inputs the sql one another as follows
begin transactioninsert into Acc_head (fid....) Values(.....) returning ID into HID
insert into ACC_detail (Header_id,debit,credit) Values(HID,n,n1)
insert into ACC_detail (Header_id,debit,credit) Values(HID,n2,n3)
insert into ACC_detail (Header_id,debit,credit) Values(HID,n4,n5)
Commit
At this point how can i check the sum(debit),Sum(Credit) in the current transaction is tallied.
If i have the details about the rows affected in the current transaction (In TRANSACTION COMMIT TRIGGER) , then i can write a rule there. So that the validity of the data can be checked inside the database itself.
hope you got some idea
thanks ,
Last edited by biju_ps : January 10th, 2011 at 02:10 PM.
|

January 10th, 2011, 07:48 PM
|
|
Contributing User
|
|
Join Date: Jan 2006
Location: Carlsbad, CA
|
|
Isn't a TRANSACTION COMMIT TRIGGER a DATABASE trigger?
i.e. I do not believe you can apply it to a designated transaction; but I could be wrong.
What is wrong with (I am using pseudo code):
SQL Code:
Original
- SQL Code |
|
|
|
BEGIN transaction INSERT INTO Acc_head (fid....) VALUES(.....) returning ID INTO HID INSERT INTO ACC_detail (Header_id,debit,credit) VALUES(HID,n,n1) INSERT INTO ACC_detail (Header_id,debit,credit) VALUES(HID,n2,n3) INSERT INTO ACC_detail (Header_id,debit,credit) VALUES(HID,n4,n5) SELECT (SUM(debit) - SUM(credit)) FROM ACC_detail WHERE (Header_id = HID); IF the result IS zero Commit ELSE Rollback AND do your fixes
.
|

January 10th, 2011, 10:53 PM
|
 |
Contributing User
|
|
Join Date: Aug 2008
Posts: 75
  
Time spent in forums: 1 Day 10 h 31 m 7 sec
Reputation Power: 8
|
|
|
thanks clivew ,
.. I will use this ..
thanks a lot
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|