GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

πŸ’– GOLF(2gg) β€” rollback-transaction πŸ’–

okay bestie, this is a page from the GOLF manual (section 2gg, from the Development chapter) and it's literally all about rollback-transaction. no cap, it's shorter than you'd think but every line EATS.


🌸 NAME 🌸

rollback-transaction β€” (database) 🫢


✨ PURPOSE ✨

Rollbacks a SQL transaction. yes that's the whole thing. iconic brevity.


πŸŽ€ SYNTAX πŸŽ€

rollback-transaction [ @<database> ] \
    [ on-error-continue | on-error-exit ] \
    [ error <error> ] [ error-text <error text> ] \
    [ options <options> ]

look at those little optional brackets, they're giving "pick me, choose me" energy πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

rollback-transaction will roll back a transaction started with begin-transaction. periodt.

<options> (inside the "options" clause) is any additional options to send to database you wish to supply for this functionality. it's the "extra toppings" slot, you know?

okay so here's the tea β˜• β€” 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 law. If you do neither, your transaction will be rolled back once the request has completed and your program will stop with an error message. yeah, it will literally just end you. This is because opening a transaction and leaving without committing or a rollback is a bug in your program. not a vibe. not the move. fix it bestie.

You must use begin-transaction, commit-transaction and rollback-transaction instead of calling this functionality through run-query. do not try to sneak around it, it will not work out for you πŸ™ˆ


🌈 DATABASE 🌈

<database> is specified in "@" clause and is the name of the database-config-file. If omitted, your program must use exactly one database (see --db option in gg). so like, either you tell it which one, or there's only one and it just knows. main character energy either way πŸ‘‘


πŸ’œ ERROR HANDLING πŸ’œ

The error code is available in <error> variable in "error" clause β€” this code is always "0" if successful. The <error> code may or may not be a number but is always returned as a string value. yes, always a string. always. In case of error, error text is available in "error-text" clause in <error text> string.

"on-error-continue" clause specifies that request processing will continue in case of an error, whereas "on-error-exit" clause specifies that it will exit. This setting overrides database-level db-error for this specific statement only. If you use "on-error-continue", be sure to check the error code. like fr fr, check it. don't just keep rolling and pretend nothing happened 😭

Note that if database connection was lost, and could not be reestablished, the request will error out (see error-handling). no connection, no party. πŸ’€

πŸ”₯ EXAMPLES πŸ”₯

begin-transaction @mydb
run-query @mydb="insert into employee (name, dateOfHire) values ('Terry', now())"
run-query @mydb="insert into payroll (name, salary) values ('Terry', 100000)"
rollback-transaction @mydb

ngl Terry had a whole career and a whole salary and then we just said "jk" and rolled it back. that's the power of rollback-transaction. slay πŸ’…βœ¨


⭐ SEE ALSO ⭐

  • Database
  • begin-transaction
  • commit-transaction
  • current-row
  • database-config-file
  • db-error
  • mariadb-database
  • postgresql-database
  • rollback-transaction
  • run-query
  • sqlite-database
  • See all documentation

and that's the whole page bestie, you ate it up 🫢

this was $VERSION of the GOLF(2gg) manual, dated $DATE β€” go forth and roll back responsibly, mwah πŸ’–πŸŽ€πŸ¦‹πŸŒΈπŸ’…

πŸ“¦ where this page comes from