Raised This Month: $ Target: $400
 0% 

Are there transactions in sqlx?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Alon2k2
Junior Member
Join Date: Apr 2010
Old 11-21-2023 , 06:47   Are there transactions in sqlx?
Reply With Quote #1

Hi,

I wanted to ask if there are transactions in sqlx?

And where are there examples because I couldn't find it on Google.
Alon2k2 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-21-2023 , 09:14   Re: Are there transactions in sqlx?
Reply With Quote #2

Not sure what you mean by “transactions in sqlx ”

If you’re asking if you can execute SQL statements in sqlx , yes.
__________________
Bugsy is offline
Alon2k2
Junior Member
Join Date: Apr 2010
Old 11-21-2023 , 09:28   Re: Are there transactions in sqlx?
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
Not sure what you mean by “transactions in sqlx ”

If you’re asking if you can execute SQL statements in sqlx , yes.
In SourceMod there is SQL_CreateTransaction and SQL_ExecuteTransaction functions
Is there something similar in amxmodx?
Alon2k2 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-21-2023 , 10:57   Re: Are there transactions in sqlx?
Reply With Quote #4

If you want to execute something immediately, use SQL_Execute().
Example use-case would be a player connected and you need his data immediately.

To avoid interrupting gameplay due to poor/slow connection with the DB and you do not care if the transaction is not executed immediately, use SQL_ThreadQuery().
Example use-case is a player is disconnecting and you want to save his data - timing does not matter for this.
__________________

Last edited by Bugsy; 11-21-2023 at 11:13.
Bugsy is offline
Alon2k2
Junior Member
Join Date: Apr 2010
Old 11-21-2023 , 12:38   Re: Are there transactions in sqlx?
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
If you want to execute something immediately, use SQL_Execute().
Example use-case would be a player connected and you need his data immediately.

To avoid interrupting gameplay due to poor/slow connection with the DB and you do not care if the transaction is not executed immediately, use SQL_ThreadQuery().
Example use-case is a player is disconnecting and you want to save his data - timing does not matter for this.
What happens for example if I want to make 2 updates in the database, for example points taken from player A to player B this means I have to take points from one record and add it to another record,
This means I have to make sure both updates are happened.

Did you figure out the problem?
Alon2k2 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-21-2023 , 12:53   Re: Are there transactions in sqlx?
Reply With Quote #6

Quote:
Originally Posted by Alon2k2 View Post
What happens for example if I want to make 2 updates in the database, for example points taken from player A to player B this means I have to take points from one record and add it to another record,
This means I have to make sure both updates are happened.

Did you figure out the problem?
2 transactions

UPDATE tblPoints SET Points=(current points - 1) WHERE ID=PlayerA
UPDATE tblPoints SET Points=(current points + 1) WHERE ID=PlayerB
__________________
Bugsy is offline
Alon2k2
Junior Member
Join Date: Apr 2010
Old 11-21-2023 , 12:58   Re: Are there transactions in sqlx?
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post
2 transactions

UPDATE tblPoints SET Points=(current points - 1) WHERE ID=PlayerA
UPDATE tblPoints SET Points=(current points + 1) WHERE ID=PlayerB
Exactly what you wrote, there is a mechanism that makes sure that both happen?

If the first succeeds and the second fails it is not good

Last edited by Alon2k2; 11-21-2023 at 12:59.
Alon2k2 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-21-2023 , 13:29   Re: Are there transactions in sqlx?
Reply With Quote #8

I wouldn’t worry about a transaction failing, assuming you write your sql statements correctly.
__________________
Bugsy is offline
damage220
Member
Join Date: Jul 2022
Location: Ukraine
Old 11-21-2023 , 14:09   Re: Are there transactions in sqlx?
Reply With Quote #9

Bugsy,
There are situations where you need, for example, to get primary key of the newly created row and if something goes wrong you can rollback any changes made to the database. These are called transactions and it has nothing to do with errors in SQL syntax but rather the logic of the program.

Alon2k2,
There are no such functions in the API. I was too disappointed when discovered this.

Last edited by damage220; 11-21-2023 at 14:09.
damage220 is offline
Alon2k2
Junior Member
Join Date: Apr 2010
Old 11-21-2023 , 14:13   Re: Are there transactions in sqlx?
Reply With Quote #10

Quote:
Originally Posted by damage220 View Post
Bugsy,
There are situations where you need, for example, to get primary key of the newly created row and if something goes wrong you can rollback any changes made to the database. These are called transactions and it has nothing to do with errors in SQL syntax but rather the logic of the program.

Alon2k2,
There are no such functions in the API. I was too disappointed when discovered this.
Thank you, Too bad there isn't, is something very important when working with database
Alon2k2 is offline
Reply


Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:11.


Powered by vBulletin®
Copyright ©2000 - 2023, vBulletin Solutions, Inc.
Theme made by Freecode