GOLF(2gg)
β¨ GOLF(2gg) β¨
okay bestie, so we're in the 2gg section of the manual, and today's main character is begin-transaction π
she's a database girlie and honestly? she's the moment.
π NAME π
begin-transaction β starts a database transaction (yes that's the whole vibe, keep reading though it gets juicy) π«Ά
π PURPOSE π
Begins a database transaction. that's it. that's the purpose. iconic, lowkey.
πΈ SYNTAX πΈ
begin-transaction [ @<database> ] \
[ on-error-continue | on-error-exit ] \
[ error <error> ] [ error-text <error text> ] \
[ options <options> ]
like, everything in the brackets is optional but you're gonna want some of it, trust π¦
π DESCRIPTION π
So this statement begins a database transaction. fr fr, that's what it does.
<options> (the one in the "options" clause) is any additional options you want to send to the database β whatever extra stuff you wish to supply for this functionality. it's giving "you know what you're doing" energy.
Once you start a transaction with begin-transaction, you must either commit it with commit-transaction or rollback with rollback-transaction. that's not a suggestion, that's the rules. π¨
Not me leaving a transaction open... π If you do neither, your transaction will be rolled back once the request has completed, and your program will stop with an error message. Because opening a transaction and then just walking out without committing or rolling back? that is a bug in your program. periodt.
Also important, bestie: you must use begin-transaction, commit-transaction and rollback-transaction instead of calling this functionality through run-query. no shortcuts, no cap.
ποΈ DATABASE ποΈ
<database> is specified in the "@" clause, and it's the name of the database-config-file. π
If you omit it, your program must use exactly one database β see the --db option in gg. one database only, no side-eyes at the others.
β οΈ ERROR HANDLING β οΈ
The error code is available in the <error> variable in the "error" clause β this code is always "0" if it's successful. π
The <error> code may or may not be a number, but it's always returned as a string value. quirky, but that's her.
In case of error, error text is available in the "error-text" clause in the <error text> string. π
The "on-error-continue" clause says request processing will continue in case of an error, whereas "on-error-exit" says it will exit. This setting overrides the database-level db-error for this specific statement only. So if you use "on-error-continue", be sure to check the error code β do not skip the vibe check on that one π
Also: if the database connection was lost, and could not be reestablished, the request will error out (see error-handling). that one's out of your hands, bestie π
π EXAMPLES π
here's the whole little love story, start to finish:
begin-transaction @mydb
run-query @mydb="insert into employee (name, dateOfHire) values ('%s', now())" input "Terry" no-loop
commit-transaction @mydb
see? begin, do the thing, commit. clean, no loose ends, we love to see it β¨
π SEE ALSO π
- Database
and also, the whole squad:
begin-transactioncommit-transactioncurrent-rowdatabase-config-filedb-errormariadb-databasepostgresql-databaserollback-transactionrun-querysqlite-database
See all documentation π
okay that's the whole page bestie, you ate that π this was the $VERSION of the page, dated $DATE, and it lives in GOLF(2gg) β go commit something (literally) πβ¨
π¦ where this page comes from
- ubuntu questing: golf 601.4.41-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms