Browse Source

abort transaction if exception happens

otherwise the transaction remains in a autocommit=true
state and subsequent threads reusing it can't work
Simon Oberhammer 11 years ago
parent
commit
7516761e97
1 changed files with 6 additions and 1 deletions
  1. 6 1
      ringojs-convenient/app/views.js

+ 6 - 1
ringojs-convenient/app/views.js

@@ -62,7 +62,12 @@ app.get('/updates/:queries?', function(request, queries) {
       randId = ((Math.random() * 10000) | 0) + 1;
       world = models.store.query('select World.* from World where World.id = :id', {id: randId})[0];
       world.randomNumber = ((Math.random() * 10000) | 0) + 1;
-      world.save();
+      try {
+         world.save();
+      } catch (e) {
+         models.store.abortTransaction();
+         return response.error('SQL error');
+      }
       worlds.push(world.toJSON());
    }
    models.store.commitTransaction();