Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Delta Between Two Patch Sets: gears/database2/commands.cc

Issue 717: Database2Values, argument conversion implemented (Closed) SVN Base: http://google-gears.googlecode.com/svn/contrib/dimitri.glazkov/database2/
Left Patch Set: Created 4 months ago
Right Patch Set: Variant, multiple-row capability added Created 3 months, 2 weeks ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 // Copyright 2008, Google Inc. 1 // Copyright 2008, Google Inc.
2 // 2 //
3 // Redistribution and use in source and binary forms, with or without 3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met: 4 // modification, are permitted provided that the following conditions are met:
5 // 5 //
6 // 1. Redistributions of source code must retain the above copyright notice, 6 // 1. Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer. 7 // this list of conditions and the following disclaimer.
8 // 2. Redistributions in binary form must reproduce the above copyright notice, 8 // 2. Redistributions in binary form must reproduce the above copyright notice,
9 // this list of conditions and the following disclaimer in the documentation 9 // this list of conditions and the following disclaimer in the documentation
10 // and/or other materials provided with the distribution. 10 // and/or other materials provided with the distribution.
11 // 3. Neither the name of Google Inc. nor the names of its contributors may be 11 // 3. Neither the name of Google Inc. nor the names of its contributors may be
12 // used to endorse or promote products derived from this software without 12 // used to endorse or promote products derived from this software without
13 // specific prior written permission. 13 // specific prior written permission.
14 // 14 //
15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 25
26 #include "gears/database2/commands.h" 26 #include "gears/database2/commands.h"
27 #include "gears/database2/common.h" 27 #include "gears/database2/common.h"
28 #include "gears/database2/result_set2.h" 28 #include "gears/database2/result_set2.h"
29 29
30 void Database2BeginCommand::Execute(bool *has_results) { 30 void Database2BeginCommand::Execute(bool *has_results) {
31 SetResult(connection()->Begin()); 31 SetResult(connection()->Begin());
32 } 32 }
33 33
34 void Database2BeginCommand::HandleResults() { 34 void Database2BeginCommand::HandleResults() {
35 if (success()) { 35 if (success()) {
36 tx()->MarkOpen(); 36 tx()->MarkOpen();
37 } else { 37 } else {
38 tx()->InvokeErrorCallback(); 38 tx()->InvokeErrorCallback();
39 } 39 }
40 } 40 }
41 41
42 void Database2AsyncExecuteCommand::Execute(bool *has_results) { 42 void Database2AsyncExecuteCommand::Execute(bool *has_results) {
43 // conn_->Execute(stmt, this); 43 // conn_->Execute(stmt, this);
44 // if success and no success callback: 44 // if success and no success callback:
45 // tx->ExecuteNextStatement(); 45 // tx->ExecuteNextStatement();
46 // *has_results = false; 46 // *has_results = false;
47 // return 47 // return
48 // otherwise, delegate to foreground thread (by default) 48 // otherwise, delegate to foreground thread (by default)
49 } 49 }
50 50
51 void Database2AsyncExecuteCommand::HandleResults() { 51 void Database2AsyncExecuteCommand::HandleResults() {
52 // create JS objects from collected rows 52 // create JS objects from collected rows
53 // stmt_->InvokeCallback(collected_rows); 53 // stmt_->InvokeCallback(collected_rows);
54 // if statement succeeded and callback failed, queue rollback op 54 // if statement succeeded and callback failed, queue rollback op
55 // else if statement failed and there is no callback, or callback did 55 // else if statement failed and there is no callback, or callback did
56 // not return false, queue rollback op 56 // not return false, queue rollback op
57 } 57 }
58 58
59 void Database2SyncExecuteCommand::Execute(bool *has_results) { 59 void Database2SyncExecuteCommand::Execute(bool *has_results) {
60 // TODO(dimitri.glazkov): Collect row results 60 // TODO(dimitri.glazkov): Collect row results
61 bool result = connection()->Execute(statement_->sql(), 61 bool result = connection()->Execute(statement_->sql(),
62 statement_->arguments(), NULL); 62 statement_->arguments(), NULL);
63 SetResult(result); 63 SetResult(result);
64 if (!result) { 64 if (!result) {
65 connection()->Rollback(); 65 connection()->Rollback();
66 tx()->MarkClosed(); 66 tx()->MarkClosed();
67 } 67 }
68 } 68 }
69 69
70 void Database2SyncExecuteCommand::HandleResults() { 70 void Database2SyncExecuteCommand::HandleResults() {
71 if (!success()) { 71 if (!success()) {
72 // throw SQL error as an exception 72 // throw SQL error as an exception
73 // TODO(dimitri.glazkov): Consider formatting the message to include error 73 // TODO(dimitri.glazkov): Consider formatting the message to include error
74 // code 74 // code
75 context_->SetException(connection()->error_message()); 75 context_->SetException(connection()->error_message());
76 return; 76 return;
77 } 77 }
78 78
79 scoped_refptr<Database2ResultSet> result_set; 79 scoped_refptr<Database2ResultSet> result_set;
80 // TODO(dimitri.glazkov): Pass collected row results 80 // TODO(dimitri.glazkov): Pass collected row results
81 if (!Database2ResultSet::Create(tx(), &result_set)) { 81 if (!Database2ResultSet::Create(tx(), &result_set)) {
82 // unable to create a result_set 82 // unable to create a result_set
83 context_->SetException(GET_INTERNAL_ERROR_MESSAGE()); 83 context_->SetException(GET_INTERNAL_ERROR_MESSAGE());
84 return; 84 return;
85 } 85 }
86 86
87 context_->SetReturnValue(JSPARAM_DISPATCHER_MODULE, result_set.get()); 87 context_->SetReturnValue(JSPARAM_DISPATCHER_MODULE, result_set.get());
88 ReleaseNewObjectToScript(result_set.get()); 88 ReleaseNewObjectToScript(result_set.get());
89 } 89 }
90 90
91 void Database2CommitCommand::Execute(bool *has_results) { 91 void Database2CommitCommand::Execute(bool *has_results) {
92 bool result = connection()->Commit(); 92 bool result = connection()->Commit();
93 SetResult(result); 93 SetResult(result);
94 if (!result) { 94 if (!result) {
95 connection()->Rollback(); 95 connection()->Rollback();
96 return; 96 return;
97 } 97 }
98 98
99 *has_results = tx()->HasSuccessCallback(); 99 *has_results = tx()->HasSuccessCallback();
100 } 100 }
101 101
102 void Database2CommitCommand::HandleResults() { 102 void Database2CommitCommand::HandleResults() {
103 if (success()) { 103 if (success()) {
104 tx()->InvokeSuccessCallback(); 104 tx()->InvokeSuccessCallback();
105 return; 105 return;
106 } 106 }
107 107
108 tx()->InvokeErrorCallback(); 108 tx()->InvokeErrorCallback();
109 } 109 }
110 110
111 void Database2RollbackCommand::Execute(bool *has_results) { 111 void Database2RollbackCommand::Execute(bool *has_results) {
112 // stub 112 // stub
113 } 113 }
114 114
115 void Database2RollbackCommand::HandleResults() { 115 void Database2RollbackCommand::HandleResults() {
116 // stub 116 // stub
117 } 117 }
118
LEFTRIGHT

Powered by Google App Engine
This is Rietveld r305