Merge lp:~rpadovani/ubuntu-calculator-app/fix-database into lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk

Proposed by Riccardo Padovani
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 145
Merged at revision: 146
Proposed branch: lp:~rpadovani/ubuntu-calculator-app/fix-database
Merge into: lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk
Diff against target: 77 lines (+18/-22)
2 files modified
Simple/SimplePage.qml (+16/-13)
Storage.qml (+2/-9)
To merge this branch: bzr merge lp:~rpadovani/ubuntu-calculator-app/fix-database
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Gustavo Pichorim Boiko (community) Approve
Mihir Soni Approve
Review via email: mp+182896@code.launchpad.net

Commit message

Fix save of calcs in database

Description of the change

Fix save of calcs in database

To post a comment you must log in.
Revision history for this message
David Planella (dpm) wrote :

The fix works well for me, but could you add a short description about what the problem was and why it's surfaced now? Thanks!

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Riccardo Padovani (rpadovani) wrote :

In rev 140 was introduct a critical bug in DB storage[1]:
the Storage.saveCalculations was designed to save all calculations when the app was closed, so the function has an argoument (calculations) that is an array with all calculations.

After rev 140 the Storage.saveCalculations is called at every tearOff, so every time all array is saved.

If I put a console.log in Storage.saveCalculations that logs every time is called and the lenght of var calculations, and I do a calc, tear off, do a calc, tear off again and close the app, in rev 139 I have:
calculationCompleted
save
calc length 2

in rev 140 I have:
calculationCompleted
save
calc length1
newPush
calculationCompleted
save
calc length2

After my changes, the calc is saved every time, but the calculations array has only last calc, so we have not multiple calc saved.

[1]http://bazaar.launchpad.net/~ubuntu-calculator-dev/ubuntu-calculator-app/trunk/revision/140

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Mihir Soni (mihirsoni) wrote :

I tried this on machine as I don't have device.

It is not saving data.

Steps to reproduce :-

1. Open calc from Terminal (locate to the main project directory & type ubuntu-calculator-app)
2. 2+2 = 4 (tear off)
3. 4+2 = 6 (tear off)
4. Press CTL+Z in terminal close the application
5. Reopen the application

The data is not being stored into database.

review: Needs Fixing
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Mihir Soni (mihirsoni) wrote :

Great work Riccardo..Works perfect !!!

Thanks for your time :)

review: Approve
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Looks good and works as expected! Thanks for the fix.

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Simple/SimplePage.qml'
2--- Simple/SimplePage.qml 2013-08-28 13:36:33 +0000
3+++ Simple/SimplePage.qml 2013-08-29 13:37:19 +0000
4@@ -128,6 +128,8 @@
5 memory.setProperty(0, "timeStamp", currentDate.getTime());
6 memory.insert(0,{'dbId': -1, 'dateText': "", 'operators': [{_text:'', _operation:'', _number:''}], 'isLastItem': true, 'mainLabel': ''});
7 positionViewAtBeginning();
8+
9+ return true;
10 }
11 }
12
13@@ -227,28 +229,29 @@
14 }
15 onMovementEnded: {
16 if (__toBeRefresh) {
17- formulaView.addCurrentToMemory();
18- clear();
19- __toBeRefresh = false
20- //Save the calculation when the user tears it off
21- var calculations = []
22- for(var i=1; i<memory.count; i++){
23- var operators = memory.get(i).operators;
24+ if (formulaView.addCurrentToMemory()) {
25+ //Save the calculation when the user tears it off
26+ var calculations = []
27+ var operators = memory.get(1).operators;
28+
29 var newop = [];
30- if(operators.count !== undefined){
31+ if (operators.count !== undefined){
32 for(var j=0; j< operators.count; j++){
33 newop.push(operators.get(j));
34 }
35- }else{
36+ } else {
37 newop = operators
38 }
39- var newElement = {'dbId': memory.get(i).dbId,
40+ var newElement = {'dbId': memory.get(1).dbId,
41 'isLastItem': false,
42- 'mainLabel': memory.get(i).mainLabel,
43+ 'mainLabel': memory.get(1).mainLabel,
44 'operators': newop};
45- calculations.push({"calc": newElement, "date": memory.get(i).timeStamp})
46+ calculations.push({"calc": newElement, "date": memory.get(1).timeStamp})
47+
48+ storage.saveCalculations(calculations)
49 }
50- storage.saveCalculations(calculations)
51+ clear();
52+ __toBeRefresh = false
53 }
54 }
55 }
56
57=== modified file 'Storage.qml'
58--- Storage.qml 2013-08-07 17:50:25 +0000
59+++ Storage.qml 2013-08-29 13:37:19 +0000
60@@ -98,15 +98,8 @@
61 openDB();
62 var res;
63 db.transaction( function(tx){
64- for(var i=0; i<calculations.length; i++){
65- if(calculations[i].calc.dbId === -1) {
66- var r = tx.executeSql('INSERT INTO Calculations(calc, insertDate) VALUES(?, ?)', [JSON.stringify(calculations[i].calc), calculations[i].date]);
67- res = r.insertId;
68- } else {
69- tx.executeSql('UPDATE Calculations SET calc = ? WHERE id = ?', [JSON.stringify(calculations[i].calc), calculations[i].calc.dbId]);
70- res = calculations[i].calc.dbId;
71- }
72- }
73+ var r = tx.executeSql('INSERT INTO Calculations(calc, insertDate) VALUES(?, ?)', [JSON.stringify(calculations[0].calc), calculations[0].date]);
74+ res = r.insertId;
75 });
76 return res;
77 }

Subscribers

People subscribed via source and target branches