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

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: Removed post-increment Created 3 months 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 results_.reset(new Database2BufferingRowHandler());
44 // if success and no success callback: 44 SetResult(connection()->Execute(statement_->sql(),
45 // tx->ExecuteNextStatement(); 45 statement_->num_arguments(), statement_->arguments(), results_.get()));
46 // *has_results = false; 46 if (success() && !statement_->HasCallback()) {
47 // return 47 // execute next statement
48 // otherwise, delegate to foreground thread (by default) 48 tx()->ExecuteNextStatement(NULL);
49 *has_results = false;
50 }
49 } 51 }
50 52
51 void Database2AsyncExecuteCommand::HandleResults() { 53 void Database2AsyncExecuteCommand::HandleResults() {
52 // create JS objects from collected rows 54 // create JS objects from collected rows
53 // stmt_->InvokeCallback(collected_rows); 55 // create Database2ResultSet
56 // results_.CopyTo(result_set);
57 // stmt_->InvokeCallback(result_set);
54 // if statement succeeded and callback failed, queue rollback op 58 // if statement succeeded and callback failed, queue rollback op
55 // else if statement failed and there is no callback, or callback did 59 // else if statement failed and there is no callback, or callback did
56 // not return false, queue rollback op 60 // not return false, queue rollback op
57 } 61 }
58 62
59 void Database2SyncExecuteCommand::Execute(bool *has_results) { 63 void Database2SyncExecuteCommand::Execute(bool *has_results) {
60 // TODO(dimitri.glazkov): Collect row results 64 // Since this is a sync operation, this method is invoked on the main thread,
65 // thus we can create a Database2ResultSet instance here.
66 if (!Database2ResultSet::Create(tx(), &result_set_)) {
67 // unable to create a result_set
68 context_->SetException(GET_INTERNAL_ERROR_MESSAGE());
69 return;
70 }
71
72 // Execute statement, using Database2ResultSet as Database2RowHandleInterface.
61 bool result = connection()->Execute(statement_->sql(), 73 bool result = connection()->Execute(statement_->sql(),
62 statement_->arguments(), NULL); 74 statement_->num_arguments(), statement_->arguments(), result_set_.get());
63 SetResult(result); 75 SetResult(result);
64 if (!result) { 76 if (!result) {
65 connection()->Rollback(); 77 connection()->Rollback();
66 tx()->MarkClosed(); 78 tx()->MarkClosed();
67 } 79 }
68 } 80 }
69 81
70 void Database2SyncExecuteCommand::HandleResults() { 82 void Database2SyncExecuteCommand::HandleResults() {
71 if (!success()) { 83 if (!success()) {
72 // throw SQL error as an exception 84 // throw SQL error as an exception
73 // TODO(dimitri.glazkov): Consider formatting the message to include error
74 // code
75 context_->SetException(connection()->error_message()); 85 context_->SetException(connection()->error_message());
76 return; 86 return;
77 } 87 }
78 88
79 scoped_refptr<Database2ResultSet> result_set; 89 context_->SetReturnValue(JSPARAM_DISPATCHER_MODULE, result_set_.get());
80 // TODO(dimitri.glazkov): Pass collected row results 90 ReleaseNewObjectToScript(result_set_.get());
81 if (!Database2ResultSet::Create(tx(), &result_set)) {
82 // unable to create a result_set
83 context_->SetException(GET_INTERNAL_ERROR_MESSAGE());
84 return;
85 }
86
87 context_->SetReturnValue(JSPARAM_DISPATCHER_MODULE, result_set.get());
88 ReleaseNewObjectToScript(result_set.get());
89 } 91 }
90 92
91 void Database2CommitCommand::Execute(bool *has_results) { 93 void Database2CommitCommand::Execute(bool *has_results) {
92 bool result = connection()->Commit(); 94 bool result = connection()->Commit();
93 SetResult(result); 95 SetResult(result);
94 if (!result) { 96 if (!result) {
95 connection()->Rollback(); 97 connection()->Rollback();
96 return; 98 return;
97 } 99 }
98 100
99 *has_results = tx()->HasSuccessCallback(); 101 *has_results = tx()->HasSuccessCallback();
100 } 102 }
101 103
102 void Database2CommitCommand::HandleResults() { 104 void Database2CommitCommand::HandleResults() {
103 if (success()) { 105 if (success()) {
104 tx()->InvokeSuccessCallback(); 106 tx()->InvokeSuccessCallback();
105 return; 107 return;
106 } 108 }
107 109
108 tx()->InvokeErrorCallback(); 110 tx()->InvokeErrorCallback();
109 } 111 }
110 112
111 void Database2RollbackCommand::Execute(bool *has_results) { 113 void Database2RollbackCommand::Execute(bool *has_results) {
112 // stub 114 // stub
113 } 115 }
114 116
115 void Database2RollbackCommand::HandleResults() { 117 void Database2RollbackCommand::HandleResults() {
116 // stub 118 // stub
117 } 119 }
118 120
OLDNEW

Powered by Google App Engine
This is Rietveld r305