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

Side by Side Diff: gears/database2/commands.cc

Issue 717: Database2Values, argument conversion implemented (Closed) SVN Base: http://google-gears.googlecode.com/svn/contrib/dimitri.glazkov/database2/
Patch Set: 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:
View unified diff | Download patch
OLDNEW
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_->num_arguments(),
63 statement_->arguments(), NULL); 62 statement_->arguments(), NULL);
64 SetResult(result); 63 SetResult(result);
65 if (!result) { 64 if (!result) {
66 connection()->Rollback(); 65 connection()->Rollback();
67 tx()->MarkClosed(); 66 tx()->MarkClosed();
68 } 67 }
69 } 68 }
70 69
71 void Database2SyncExecuteCommand::HandleResults() { 70 void Database2SyncExecuteCommand::HandleResults() {
72 if (!success()) { 71 if (!success()) {
73 // throw SQL error as an exception 72 // throw SQL error as an exception
74 // TODO(dimitri.glazkov): Consider formatting the message to include error 73 // TODO(dimitri.glazkov): Consider formatting the message to include error
75 // code 74 // code
76 context_->SetException(connection()->error_message()); 75 context_->SetException(connection()->error_message());
77 return; 76 return;
78 } 77 }
79 78
80 scoped_refptr<Database2ResultSet> result_set; 79 scoped_refptr<Database2ResultSet> result_set;
81 // TODO(dimitri.glazkov): Pass collected row results 80 // TODO(dimitri.glazkov): Pass collected row results
82 if (!Database2ResultSet::Create(tx(), &result_set)) { 81 if (!Database2ResultSet::Create(tx(), &result_set)) {
83 // unable to create a result_set 82 // unable to create a result_set
84 context_->SetException(GET_INTERNAL_ERROR_MESSAGE()); 83 context_->SetException(GET_INTERNAL_ERROR_MESSAGE());
85 return; 84 return;
86 } 85 }
87 86
88 context_->SetReturnValue(JSPARAM_DISPATCHER_MODULE, result_set.get()); 87 context_->SetReturnValue(JSPARAM_DISPATCHER_MODULE, result_set.get());
89 ReleaseNewObjectToScript(result_set.get()); 88 ReleaseNewObjectToScript(result_set.get());
90 } 89 }
91 90
92 void Database2CommitCommand::Execute(bool *has_results) { 91 void Database2CommitCommand::Execute(bool *has_results) {
93 bool result = connection()->Commit(); 92 bool result = connection()->Commit();
94 SetResult(result); 93 SetResult(result);
95 if (!result) { 94 if (!result) {
96 connection()->Rollback(); 95 connection()->Rollback();
97 return; 96 return;
98 } 97 }
99 98
100 *has_results = tx()->HasSuccessCallback(); 99 *has_results = tx()->HasSuccessCallback();
101 } 100 }
102 101
103 void Database2CommitCommand::HandleResults() { 102 void Database2CommitCommand::HandleResults() {
104 if (success()) { 103 if (success()) {
105 tx()->InvokeSuccessCallback(); 104 tx()->InvokeSuccessCallback();
106 return; 105 return;
107 } 106 }
108 107
109 tx()->InvokeErrorCallback(); 108 tx()->InvokeErrorCallback();
110 } 109 }
111 110
112 void Database2RollbackCommand::Execute(bool *has_results) { 111 void Database2RollbackCommand::Execute(bool *has_results) {
113 // stub 112 // stub
114 } 113 }
115 114
116 void Database2RollbackCommand::HandleResults() { 115 void Database2RollbackCommand::HandleResults() {
117 // stub 116 // stub
118 } 117 }
119
120
OLDNEW

Powered by Google App Engine
This is Rietveld r292