| 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. |
| 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 #ifndef GEARS_DATABASE2_CONNECTION_H__ | 26 #ifndef GEARS_DATABASE2_CONNECTION_H__ |
| 27 #define GEARS_DATABASE2_CONNECTION_H__ | 27 #define GEARS_DATABASE2_CONNECTION_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/base/common/scoped_refptr.h" | 31 #include "gears/base/common/scoped_refptr.h" |
| 32 #include "gears/base/common/security_model.h" | 32 #include "gears/base/common/security_model.h" |
| 33 #include "gears/base/common/string16.h" | 33 #include "gears/base/common/string16.h" |
| 34 #include "gears/third_party/sqlite_google/preprocessed/sqlite3.h" | 34 #include "gears/third_party/sqlite_google/preprocessed/sqlite3.h" |
| 35 |
| 36 class Database2Values; |
| 35 | 37 |
| 36 class Database2RowHandlerInterface { | 38 class Database2RowHandlerInterface { |
| 37 public: | 39 public: |
| 38 Database2RowHandlerInterface() {}; | 40 Database2RowHandlerInterface() {}; |
| 39 ~Database2RowHandlerInterface() {}; | 41 ~Database2RowHandlerInterface() {}; |
| 40 | 42 |
| 41 virtual void Begin() = 0; | 43 virtual void Begin() = 0; |
| 42 // TODO(dimitri.glazkov): Add row data parameter(s) | 44 // TODO(dimitri.glazkov): Add row data parameter(s) |
| 43 virtual void HandleRow() = 0; | 45 virtual void HandleRow() = 0; |
| 44 virtual void End() = 0; | 46 virtual void End() = 0; |
| 45 | 47 |
| 46 DISALLOW_EVIL_CONSTRUCTORS(Database2RowHandlerInterface); | 48 DISALLOW_EVIL_CONSTRUCTORS(Database2RowHandlerInterface); |
| 47 }; | 49 }; |
| 48 | 50 |
| 49 // Encapsulates database operations, opens and closes database connection | 51 // Encapsulates database operations, opens and closes database connection |
| 50 class Database2Connection : public RefCounted { | 52 class Database2Connection : public RefCounted { |
| 51 public: | 53 public: |
| 52 // lazily initialized | 54 // lazily initialized |
| 53 Database2Connection(const std::string16 &name, | 55 Database2Connection(const std::string16 &name, |
| 54 const SecurityOrigin &origin) : | 56 const SecurityOrigin &origin) : |
| 55 name_(name), origin_(origin) {} | 57 name_(name), origin_(origin) {} |
| 56 ~Database2Connection() { | 58 ~Database2Connection() { |
| 57 // close connection | 59 // close connection |
| 58 } | 60 } |
| 59 | 61 |
| 60 bool OpenAndVerifyVersion(const std::string16 &database_version); | 62 bool OpenAndVerifyVersion(const std::string16 &database_version); |
| 61 bool Execute(const std::string16 &statement, | 63 bool Execute(const std::string16 &statement, |
| 62 const int num_arguments, | 64 Database2Values *arguments, |
| 63 const JsParamToSend *arguments, | |
| 64 Database2RowHandlerInterface *row_handler); | 65 Database2RowHandlerInterface *row_handler); |
| 65 bool Begin(); | 66 bool Begin(); |
| 66 void Rollback(); | 67 void Rollback(); |
| 67 bool Commit(); | 68 bool Commit(); |
| 68 | 69 |
| 69 int error_code() const { return error_code_; } | 70 int error_code() const { return error_code_; } |
| 70 std::string16 error_message() const { return error_message_; } | 71 std::string16 error_message() const { return error_message_; } |
| 71 | 72 |
| 72 private: | 73 private: |
| 73 bool bogus_version_; | 74 bool bogus_version_; |
| 74 int expected_version_; | 75 int expected_version_; |
| 75 | 76 |
| 76 std::string16 error_message_; | 77 std::string16 error_message_; |
| 77 int error_code_; | 78 int error_code_; |
| 78 | 79 |
| 79 sqlite3 *handle_; | 80 sqlite3 *handle_; |
| 80 std::string16 name_; | 81 std::string16 name_; |
| 81 SecurityOrigin origin_; | 82 SecurityOrigin origin_; |
| 82 | 83 |
| 83 DISALLOW_EVIL_CONSTRUCTORS(Database2Connection); | 84 DISALLOW_EVIL_CONSTRUCTORS(Database2Connection); |
| 84 }; | 85 }; |
| 85 | 86 |
| 86 #endif // GEARS_DATABASE2_CONNECTION_H__ | 87 #endif // GEARS_DATABASE2_CONNECTION_H__ |
| OLD | NEW |