Hello, i have a strange problem when i try to write down to a Sybase IQ db, using django 1.7 Using the .save() method does not write to the underlying database as expected from the official django documentation.
Looking at the source code in this repo (https://github.com/sqlanywhere/sqlany-django) i have seen 'AUTOCOMMIT' listed as one of the key that can solve this problem, but I have no way to tell which value should i set.
Digging around i have seen that you can set any string value to get into the function
self.set_autocommit(self.settings_dict['AUTOCOMMIT']) -> _set_autocommit( self, autocommit )
and consequently set
curs.execute( "SET TEMPORARY OPTION chained='%s'" % ('Off' if autocommit else 'On') )
to Off, which is what i want.
This is something that another user https://github.com/faxioman/sqlany-django solved by forcing the chained option to Off, but it's not working.
What am i doing wrong here?
Be extremely careful when using chained mode as an auto commit alternative. Many people believe that auto commit and chained mode are the same thing; but they are radically different. Auto commit is an explicit commit request initiated by either the driver or the server after a REQUEST is complete whereas chained mode issues an explicit commit after EVERY STATEMENT.
In general, an application should not use auto commit nor chained mode. Instead, the application should issue explicit commits at appropriate times. Relying on auto commit or chained mode introduces unnecessary performance degradation and can lead to some very unexpected behaviour. I realize that with IQ it might make most sense to have auto commit turned on to ensure you are always getting the most current snapshot; but it is still much better to code your application such that it issues the commits directly when appropriate.
However, if you must resort to auto commit, then be advised that chained mode is not auto commit. The Django driver does not support auto commit so you may think that using chained mode will be sufficient or equivelent. However consider the following (very contrived) example:
Suppose the application now does something like
So final thoughts, yes the Django driver does not support auto commit and you may think that setting chained to off is the equivalent or next best thing; but I would strongly advise against it. It would be better (both from a performance as well as a proper/expected behaviour standpoint) if you coded your application to issue explicit commits at appropriate times.
answered 24 Feb '15, 10:19
Solved by putting cursor.execute("SET TEMPORARY OPTION chained='Off'")
answered 24 Feb '15, 09:17