0

I need to be able to "rollback" from a "transaction" to the DB in case a sequence of db queries don't all succeed. I could not find any documentation regarding this ability using the SQL library provided by CS50. I would resort to other libraries - but was wondering if this is supported be for I do so

1

It sounds like you're thinking about implementing some of the more complex database concepts that are used in financial programming. Kudos to you! But, these concepts are a little beyond the scope of this class, so they're not really covered or required for these exercises. That's why they're not really supported.

Having said that, here are some thoughts on how to implement what you want to do.

Manually handle the rollback: You could keep track of the information that is updated in each transaction. If something fails and you have to undo earlier changes, then you still have the data to create a query to undo what is needed.

The COMMIT statement. Most db engines support START,COMMIT and ROLLBACK statements. Basically, START and COMMIT work in combination. They group a collection of sql statements together. Either all must work successfully or any that have been executed will be rolled back. This is the preferred method. This is also why you generally won't find info on rollback outside of the db product. It's usually integrated into the db and supported for the specific product.

I'll leave it to you to research for your implementation. At this stage in the class, you're expected to be able to research and learn new languages and concepts on your own. ;-)

Hope this helps.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .