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

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

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r338