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

Unified Diff: gears/database2/statement.h

Issue 717: Database2Values, argument conversion implemented (Closed) SVN Base: http://google-gears.googlecode.com/svn/contrib/dimitri.glazkov/database2/
Patch Set: ready for another look. Created 5 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 side by-side-diff with in-line comments
Download patch
Index: gears/database2/statement.h
===================================================================
--- gears/database2/statement.h (revision 1639)
+++ gears/database2/statement.h (working copy)
@@ -33,42 +33,73 @@
// forward declarations
class Database2;
class Database2Transaction;
+class Database2Values;
-// represents Database2Statement
+// represents statement, for both synchronous and asynchronous operations
class Database2Statement {
public:
- Database2Statement() {}
-
bool HasCallback() const {
- assert(callback_.get());
- return !JsTokenIsNullOrUndefined(callback_->token());
+ return callback_.get() != NULL;
}
bool HasErrorCallback() const {
- assert(error_callback_.get());
- return !JsTokenIsNullOrUndefined(error_callback_->token());
+ return error_callback_.get() != NULL;
}
void InvokeCallback(Database2Transaction *tx);
void InvokeErrorCallback(Database2Transaction *tx, JsObject *error);
+ // create a statement instance
+ // must passs NULL for arguments or callbacks if they are not specified
static bool Create(const std::string16 &sql_statement,
- const JsArray &sql_arguments,
+ JsArray *sql_arguments,
JsRootedCallback *callback,
JsRootedCallback *error_callback,
Database2Statement **instance);
std::string16 sql() const { return sql_statement_; }
- JsParamToSend *arguments() const { return sql_arguments_; }
- int num_arguments() const { return num_arguments_; }
+ Database2Values *arguments() const { return arguments_.get(); }
private:
+ Database2Statement() {}
+ // if true, the statement has invalid arguments
+ bool bogus_;
std::string16 sql_statement_;
- int num_arguments_;
- JsParamToSend *sql_arguments_;
+ scoped_ptr<Database2Values> arguments_;
scoped_ptr<JsRootedCallback> callback_;
scoped_ptr<JsRootedCallback> error_callback_;
DISALLOW_EVIL_CONSTRUCTORS(Database2Statement);
};
+// Used for marshaling statement arguments to the database thread and
+// results to the main thread.
+// JsParamToSend is used to store the value-type pairs, and as a result the
+// values are heap-allocated, which is unfortunate in the case of int/double.
+// TODO(dimitri.glazkov): Reimplement using unions, possibly reusing or
+// integrating with MarshaledJsToken
+class Database2Values {
+ public:
+ ~Database2Values();
+
+ static bool CreateFromJsArray(const JsArray *sql_arguments,
+ Database2Values **instance);
+
+ int length() const { return length_; }
+ JsParamType GetType(int index) const;
+ int GetAsInt(int index) const;
+ double GetAsDouble(int index) const;
+ std::string16 &GetAsString(int index) const;
+ private:
+ Database2Values() {}
+
+ static bool SetJsParamToSend(const JsArray *js_array,
+ int index,
+ JsParamToSend *param);
+
+ scoped_array<JsParamToSend> arguments_;
+ int length_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(Database2Values);
+};
+
#endif // GEARS_DATABASE2_STATEMENT_H__

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