Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 13th, 2004, 07:27 AM
pmanten pmanten is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 51 pmanten User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Unhappy Commit in a stored procedure

Hi,

I'm new to firebird so this may be a pretty stupid question. Anyhow, I've got a simple stored procedure doing nothing more than a simple insert. (I call the procedure from php.)

I want to be sure that the insert is really committed, so I thought to just put a commit statement in my stored procedure. This doesn't seem to be possible with firebird. Or am I using the wrong syntax for the commit??

This is my procedure:
create procedure test
as
begin
insert into test_table(id) values (1);
commit;
end

Why does the procedure not compile with the commit line? And how can I make sure that the insert is really inserted in the database (and not only posted)?

Reply With Quote
  #2  
Old August 14th, 2004, 07:16 AM
upscene upscene is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 223 upscene User rank is Corporal (100 - 500 Reputation Level)upscene User rank is Corporal (100 - 500 Reputation Level)upscene User rank is Corporal (100 - 500 Reputation Level)upscene User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 7 h 14 m 50 sec
Reputation Power: 8
Transactions cannot be started/committed/rolled back from inside stored procedure or trigger code.

The client (process) that calls the stored procedure should start and commit/rollback the transaction.



--
With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL Server.
Upscene Productions
http://www.upscene.com
__________________
Martijn Tonies
Database Workbench: developer IDE for Firebird, MySQL, InterBase, MSSQL Server and Oracle
Upscene Productions
http://www.upscene.com

Reply With Quote
  #3  
Old August 16th, 2004, 11:10 PM
pmanten pmanten is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 51 pmanten User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Thanks for the reply, Martijn!

I have one more related question. When my client (which is a php-application) calls the simple test-procedure (with something like ibase_query("execute procedure test")) and I don't do a commit after the procedure-call, I can still see that the database is updated!
So does this imply that there's an automatic commit after the procedure closes? Wouldn't this mean that I don't need the client to explicitly commit the transaction?

Regards, Peter

Reply With Quote
  #4  
Old August 17th, 2004, 02:38 AM
upscene upscene is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 223 upscene User rank is Corporal (100 - 500 Reputation Level)upscene User rank is Corporal (100 - 500 Reputation Level)upscene User rank is Corporal (100 - 500 Reputation Level)upscene User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 7 h 14 m 50 sec
Reputation Power: 8
Hi,

That implies that your connecting is doing some kind of auto-commit. This has nothing to do with the procedure itself, but more with the defaults for a PHP connection object, I think, and the driver that is used to connect to Firebird. My bet is that you can turn this behaviour OFF as well.


With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL Server.
Upscene Productions
http://www.upscene.com

Reply With Quote
  #5  
Old August 17th, 2004, 07:12 AM
pmanten pmanten is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 51 pmanten User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
That makes sense!!

I checked the documentation, but can't really find it. It could be that it's defined in the constant ibase_committed, which is set in a dll in my php-environment (php/extensions/php_interbase.dll).

I still can't figure out, how I can set this constant. I think it's better to put this 'auto commit' off and always use ibase_commit() instead.

Regards, Peter

Reply With Quote
  #6  
Old August 17th, 2004, 07:19 AM
upscene upscene is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 223 upscene User rank is Corporal (100 - 500 Reputation Level)upscene User rank is Corporal (100 - 500 Reputation Level)upscene User rank is Corporal (100 - 500 Reputation Level)upscene User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 7 h 14 m 50 sec
Reputation Power: 8
Hi Peter,

I have zero PHP knowledge, so I guess you need to ask someone else on that subject


With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL Server.
Upscene Productions
http://www.upscene.com

Reply With Quote
  #7  
Old September 5th, 2004, 07:00 PM
russh russh is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 18 russh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 48 sec
Reputation Power: 0
Hi,

Bit of a late reply sorry but I've just been faced with this issue too. From what I have gathered, PHP automatically creates a default transaction upon connecting to the db. This transaction is automatically commited when the script has finished executing.

If you want more control, you can create a new transaction (ibase_trans) and pass along the returned transaction id to any further queries etc. If you don't commit this transaction then your changes will be lost at the end of your script.

It's also not a bad idea to look at creating your own transactions anyway since you can pass along flags to tailor the transaction to your preferences. For example, the default transaction created for you is read/write. However, there is a small performance gain to be had from creating the transaction as read-only (if, of course, you only wish to perform SELECTs).

Russ

Reply With Quote
  #8  
Old September 6th, 2004, 12:00 AM
pmanten pmanten is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 51 pmanten User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Russ,

Thanks for the reply! I'm not that familiar yet with the way php handles transactions, but I'll definitely have a closer look at it (might be useful for me to set a read-only flag now and then).

Regards, Peter

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Commit in a stored procedure


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway