sqlanywhere / node-sqlanywhere

SAP SQL Anywhere Database Client for Node
Apache License 2.0
38 stars 36 forks source link

Writing to Sql Anywhere 16 doesn't appear to be working #14

Closed ryanswapp closed 8 years ago

ryanswapp commented 8 years ago

I don't have much experience with Sql Anywhere and am trying to hook into a legacy system that runs on it. I am able to connect to the database and read from it but my update queries do not seem to be having any effect. For instance, if I run the following query:

UPDATE Party INNER JOIN Names ON Party.party_id = Names.names_id SET Names.first_name = 'Lindsay 5', Names.aka_first = 'Lindsay 4' WHERE (((Party.our_client)='Y') AND ((Party.case_id)=353178))

The values for first_name and aka_first remain unchanged. However, if I run that exact query inside Microsoft Access the query works and the values for first_name and aka_first are updated.

Database version is 16.0.0.1324

Any idea why this may be happening?

gperrow-SAP commented 8 years ago

I'm assuming you are checking the error code from the query. If there's no error, then the update should be succeeding. Are you doing a conn.commit() afterwards?

ryanswapp commented 8 years ago

You are the man! I didn't realize that I had to run conn.commit() afterwards. I just gave it a try and it worked. In what circumstances do you need to run conn.commit()? Every query besides a SELECT?

gperrow-SAP commented 8 years ago

A commit is a command to the database server to tell it that the transaction you are working on should be considered permanent. Once you've done the commit, you can disconnect and your changes will persist. The opposite is a rollback, which will "undo" any delete, insert, or update statements you've made (a) since the last commit or rollback or (b) since you connected. A commit / rollback isn't technically necessary after selects since you haven't changed anything but it's a good idea anyway since it releases locks held by the connection.

ryanswapp commented 8 years ago

That's good to know. I appreciate your help. Thanks for the quick response!