author | Michael Krelin <hacker@klever.net> | 2013-11-25 18:57:36 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2013-11-25 18:57:36 (UTC) |
commit | 2c9aa9d30d3b833954b4fa584293e6e5a817f102 (patch) (unidiff) | |
tree | 0b3b969e0da227862edd1210203b560996c877b8 /backend | |
parent | bcfe3d4f277b5d87e5c3fd56479e07f194a37144 (diff) | |
download | clipperz-2c9aa9d30d3b833954b4fa584293e6e5a817f102.zip clipperz-2c9aa9d30d3b833954b4fa584293e6e5a817f102.tar.gz clipperz-2c9aa9d30d3b833954b4fa584293e6e5a817f102.tar.bz2 |
PG: don't try to commit after rolling back
-rw-r--r-- | backend/node/src/clipperz.js | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/backend/node/src/clipperz.js b/backend/node/src/clipperz.js index 6c13f16..6bf56bb 100644 --- a/backend/node/src/clipperz.js +++ b/backend/node/src/clipperz.js | |||
@@ -45,49 +45,49 @@ var CLIPPERZ = module.exports = function(CONFIG) { | |||
45 | if(e) return D(),cb(e); | 45 | if(e) return D(),cb(e); |
46 | cb(null,{ | 46 | cb(null,{ |
47 | Q: function(q,a,cb) { | 47 | Q: function(q,a,cb) { |
48 | LOGGER.trace({query:q,args:a},'SQL: %s',q); | 48 | LOGGER.trace({query:q,args:a},'SQL: %s',q); |
49 | if(this.over) return cb(new Error('game over')); | 49 | if(this.over) return cb(new Error('game over')); |
50 | if('function'===typeof a) cb=a,a=[]; | 50 | if('function'===typeof a) cb=a,a=[]; |
51 | var t0=new Date(); | 51 | var t0=new Date(); |
52 | C.query(q,a,function(e,r) { | 52 | C.query(q,a,function(e,r) { |
53 | var t1=new Date(), dt=t1-t0; | 53 | var t1=new Date(), dt=t1-t0; |
54 | LOGGER.trace({query:q,args:a,ms:dt,rows:r&&r.rowCount},"SQL query '%s' took %dms",q,dt); | 54 | LOGGER.trace({query:q,args:a,ms:dt,rows:r&&r.rowCount},"SQL query '%s' took %dms",q,dt); |
55 | cb(e,r); | 55 | cb(e,r); |
56 | }); | 56 | }); |
57 | }, | 57 | }, |
58 | commit: function(cb) { | 58 | commit: function(cb) { |
59 | LOGGER.trace('SQL: commit'); | 59 | LOGGER.trace('SQL: commit'); |
60 | if(this.over) return cb(new Error('game over')); | 60 | if(this.over) return cb(new Error('game over')); |
61 | return (this.over=true),C.query('COMMIT',function(e){D();cb&&cb(e)}); | 61 | return (this.over=true),C.query('COMMIT',function(e){D();cb&&cb(e)}); |
62 | }, | 62 | }, |
63 | rollback: function(cb) { | 63 | rollback: function(cb) { |
64 | LOGGER.trace('SQL: rollback'); | 64 | LOGGER.trace('SQL: rollback'); |
65 | if(this.over) return cb(new Error('game over')); | 65 | if(this.over) return cb(new Error('game over')); |
66 | return (this.over=true),C.query('ROLLBACK',function(e){D();cb&&cb(e)}); | 66 | return (this.over=true),C.query('ROLLBACK',function(e){D();cb&&cb(e)}); |
67 | }, | 67 | }, |
68 | end: function(e,cb) { | 68 | end: function(e,cb) { |
69 | if(e) LOGGER.trace(e,"rolling back transaction due to an error"),this.rollback(cb); | 69 | if(e) return LOGGER.trace(e,"rolling back transaction due to an error"),this.rollback(cb); |
70 | this.commit(cb); | 70 | this.commit(cb); |
71 | } | 71 | } |
72 | }); | 72 | }); |
73 | }); | 73 | }); |
74 | }); | 74 | }); |
75 | } | 75 | } |
76 | }; | 76 | }; |
77 | 77 | ||
78 | 78 | ||
79 | return { | 79 | return { |
80 | 80 | ||
81 | json: function clipperz_json(req,res,cb) { | 81 | json: function clipperz_json(req,res,cb) { |
82 | var method = req.body.method, pp = JSON.parse(req.body.parameters).parameters; | 82 | var method = req.body.method, pp = JSON.parse(req.body.parameters).parameters; |
83 | var message = pp.message; | 83 | var message = pp.message; |
84 | var ppp = pp.parameters; | 84 | var ppp = pp.parameters; |
85 | res.res = function(o) { return res.json({result:o}) }; | 85 | res.res = function(o) { return res.json({result:o}) }; |
86 | LOGGER.trace({method:method,parameters:pp},"JSON request"); | 86 | LOGGER.trace({method:method,parameters:pp},"JSON request"); |
87 | 87 | ||
88 | switch(method) { | 88 | switch(method) { |
89 | case 'registration': | 89 | case 'registration': |
90 | switch(message) { | 90 | switch(message) { |
91 | case 'completeRegistration': return PG.Q( | 91 | case 'completeRegistration': return PG.Q( |
92 | "INSERT INTO clipperz.theuser" | 92 | "INSERT INTO clipperz.theuser" |
93 | +" (u_name, u_srp_s,u_srp_v, u_authversion,u_header,u_statistics,u_version,u_lock)" | 93 | +" (u_name, u_srp_s,u_srp_v, u_authversion,u_header,u_statistics,u_version,u_lock)" |