| OLD | NEW |
|---|---|
| 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 15 matching lines...) Show 10 above Show 10 below | |
| 26 #ifndef GEARS_DATABASE2_STATEMENT_H__ | 26 #ifndef GEARS_DATABASE2_STATEMENT_H__ |
| 27 #define GEARS_DATABASE2_STATEMENT_H__ | 27 #define GEARS_DATABASE2_STATEMENT_H__ |
| 28 | 28 |
| 29 #include "gears/base/common/common.h" | 29 #include "gears/base/common/common.h" |
| 30 #include "gears/base/common/js_types.h" | 30 #include "gears/base/common/js_types.h" |
| 31 #include "gears/third_party/scoped_ptr/scoped_ptr.h" | 31 #include "gears/third_party/scoped_ptr/scoped_ptr.h" |
| 32 | 32 |
| 33 // forward declarations | 33 // forward declarations |
| 34 class Database2; | 34 class Database2; |
| 35 class Database2Transaction; | 35 class Database2Transaction; |
| 36 class Database2Values; | |
| 36 | 37 |
| 37 // represents Database2Statement | 38 // represents statement, for both synchronous and asynchronous operations |
| 38 class Database2Statement { | 39 class Database2Statement { |
| 39 public: | 40 public: |
| 40 Database2Statement() {} | |
| 41 | |
| 42 bool HasCallback() const { | 41 bool HasCallback() const { |
| 43 assert(callback_.get()); | 42 assert(callback_.get()); |
| 44 return !JsTokenIsNullOrUndefined(callback_->token()); | 43 return !JsTokenIsNullOrUndefined(callback_->token()); |
| 45 } | 44 } |
| 46 | 45 |
| 47 bool HasErrorCallback() const { | 46 bool HasErrorCallback() const { |
| 48 assert(error_callback_.get()); | 47 assert(error_callback_.get()); |
| 49 return !JsTokenIsNullOrUndefined(error_callback_->token()); | 48 return !JsTokenIsNullOrUndefined(error_callback_->token()); |
| 50 } | 49 } |
| 51 | 50 |
| 52 void InvokeCallback(Database2Transaction *tx); | 51 void InvokeCallback(Database2Transaction *tx); |
| 53 void InvokeErrorCallback(Database2Transaction *tx, JsObject *error); | 52 void InvokeErrorCallback(Database2Transaction *tx, JsObject *error); |
| 54 | 53 |
| 55 static bool Create(const std::string16 &sql_statement, | 54 static bool Create(const std::string16 &sql_statement, |
| 56 const JsArray &sql_arguments, | 55 const JsArray &sql_arguments, |
| 57 JsRootedCallback *callback, | 56 JsRootedCallback *callback, |
| 58 JsRootedCallback *error_callback, | 57 JsRootedCallback *error_callback, |
| 59 Database2Statement **instance); | 58 Database2Statement **instance); |
| 60 | 59 |
| 61 std::string16 sql() const { return sql_statement_; } | 60 std::string16 sql() const { return sql_statement_; } |
| 62 JsParamToSend *arguments() const { return sql_arguments_; } | 61 Database2Values *arguments() const { return arguments_.get(); } |
| 63 int num_arguments() const { return num_arguments_; } | |
| 64 private: | 62 private: |
| 63 Database2Statement() {} | |
| 64 // if true, the statement has invalid arguments | |
| 65 bool bogus_; | |
| 65 std::string16 sql_statement_; | 66 std::string16 sql_statement_; |
| 66 int num_arguments_; | 67 scoped_ptr<Database2Values> arguments_; |
| 67 JsParamToSend *sql_arguments_; | |
| 68 scoped_ptr<JsRootedCallback> callback_; | 68 scoped_ptr<JsRootedCallback> callback_; |
| 69 scoped_ptr<JsRootedCallback> error_callback_; | 69 scoped_ptr<JsRootedCallback> error_callback_; |
| 70 | 70 |
| 71 DISALLOW_EVIL_CONSTRUCTORS(Database2Statement); | 71 DISALLOW_EVIL_CONSTRUCTORS(Database2Statement); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 // used for marshaling statement arguments to the database thread and | |
| 75 // results to the main thread | |
| 76 class Database2Values { | |
| 77 public: | |
| 78 ~Database2Values(); | |
| 79 | |
| 80 static bool CreateFromJsArray(const JsArray &sql_arguments, | |
| 81 Database2Values **instance); | |
| 82 | |
| 83 int length() const { return length_; } | |
| 84 JsParamType GetType(int index) const; | |
| 85 int GetAsInt(int index) const; | |
| 86 double GetAsDouble(int index) const; | |
| 87 std::string16 &GetAsString(int index) const; | |
| 88 private: | |
| 89 Database2Values() {} | |
| 90 | |
| 91 static bool SetJsParamToSend(JsArray js_array, | |
| 92 int index, | |
| 93 JsParamToSend *param); | |
| 94 | |
| 95 scoped_array<JsParamToSend> arguments_; | |
| 96 int length_; | |
|
Aaron
2008/05/11 18:11:21
Should length be passed separately? The way it is
Dimitri
2008/05/13 22:52:03
On 2008/05/11 18:11:21, Aaron wrote:
> Should leng
| |
| 97 | |
| 98 DISALLOW_EVIL_CONSTRUCTORS(Database2Values); | |
| 99 }; | |
| 100 | |
| 74 #endif // GEARS_DATABASE2_STATEMENT_H__ | 101 #endif // GEARS_DATABASE2_STATEMENT_H__ |
| OLD | NEW |