Guys I don't understand what is the alternative for sql.Begin() and sql.Commit() in MySQLOO, can someone explain to me what can I do to replace them? Is it really needed or does MySQL works with them?
Thanks for reading (Rated dumb on the way I bet)
EDIT: And what about sql.QueryValue()?
sql.Begin() and sql.Commit() are simply wrappers to SQL calls BEGIN and COMMIT respectively. You will have to write your own wrappers. The same goes for sql.QueryValue(), which simply grabs the first row and the first value from the result set. This means that sql.Begin() is equivalent to sql.Query("BEGIN"), same goes for commit.
BEGIN and COMMIT are available in MySQL as well, but you will need to search on the web how to properly use them. You might also want to look into transactions, as they are supported in MySQLOOv9. For batch inserts you can also use prepared queries in MySQLOO, look for PreparedQuery:putNewParameters() in the MySQLOO docs.
[url=https://en.wikipedia.org/wiki/Database_transaction]Transactions Wiki article[/url]
[url=http://www.tutorialspoint.com/mysql/mysql-transactions.htm]A sample tutorial on transactions[/url]
[QUOTE=typedef state;50764031]sql.Begin() and sql.Commit() are simply wrappers to SQL calls BEGIN and COMMIT respectively. You will have to write your own wrappers. The same goes for sql.QueryValue(), which simply grabs the first row and the first value from the result set. This means that sql.Begin() is equivalent to sql.Query("BEGIN"), same goes for commit.
BEGIN and COMMIT are available in MySQL as well, but you will need to search on the web how to properly use them. You might also want to look into transactions, as they are supported in MySQLOOv9. For batch inserts you can also use prepared queries in MySQLOO, look for PreparedQuery:putNewParameters() in the MySQLOO docs.
[url=https://en.wikipedia.org/wiki/Database_transaction]Transactions Wiki article[/url]
[url=http://www.tutorialspoint.com/mysql/mysql-transactions.htm]A sample tutorial on transactions[/url][/QUOTE]
PreparedQuery:putNewParameters() doesn't work with "SELECT" statements and that's exacly what I wanted to do :(
A good example for a code would be this:
[code]
sql.Begin()
ply:SetNWInt("money",tonumber(sql.QueryValue("SELECT money FROM money_data WHERE steam = "..sql.SQLStr(ply:SteamID())..";")))
sql.Commit()
[/code]
Any ideas?
[QUOTE=Pwned231;50764162]PreparedQuery:putNewParameters() doesn't work with "SELECT" statements and that's exacly what I wanted to do :(
A good example for a code would be this:
[code]
sql.Begin()
ply:SetNWInt("money",tonumber(sql.QueryValue("SELECT money FROM money_data WHERE steam = "..sql.SQLStr(ply:SteamID())..";")))
sql.Commit()
[/code]
Any ideas?[/QUOTE]
What are you trying to achieve here? BEGIN and COMMIT start and commit a transaction respectively. There isn't really much point in wrapping SELECT statements in transactions (there might be in some special cases, but more often than not it's not needed). In SQLite, all write/update/delete operations start a transactions by default unless specifically told otherwise, e.g. by BEGIN and COMMIT. So there is no point in wrapping single queries with BEGIN and COMMIT. The same goes for MySQL; unless you want multiple queries to execute at once, atomically, there is absolutely no point in using BEGIN and COMMIT, since the RDBMS automatically wraps queries that are receceived outside of transactions into transactions as well.
Either way, the MySQL equivalent seems to be something like this:
[code]
START TRANSACTION;
(query 1)
(query 2)
(query 3)
COMMIT;
[/code]
[url=http://dev.mysql.com/doc/refman/5.7/en/commit.html]MySQL BEGIN COMMIT ROLLBACK syntax[/url]
Sorry, you need to Log In to post a reply to this thread.