OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
9 #include "sql/connection.h" | 9 #include "sql/connection.h" |
10 #include "sql/statement.h" | 10 #include "sql/statement.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "third_party/sqlite/sqlite3.h" | 12 #include "third_party/sqlite/sqlite3.h" |
13 | 13 |
14 class StatementErrorHandler : public sql::ErrorDelegate { | 14 class StatementErrorHandler : public sql::ErrorDelegate { |
15 public: | 15 public: |
16 StatementErrorHandler() : error_(SQLITE_OK) {} | 16 StatementErrorHandler() : error_(SQLITE_OK) {} |
17 | 17 |
18 virtual int OnError(int error, sql::Connection* connection, | 18 virtual int OnError(int error, sql::Connection* connection, |
19 sql::Statement* stmt) { | 19 sql::Statement* stmt) OVERRIDE { |
20 error_ = error; | 20 error_ = error; |
21 const char* sql_txt = stmt ? stmt->GetSQLStatement() : NULL; | 21 const char* sql_txt = stmt ? stmt->GetSQLStatement() : NULL; |
22 sql_text_ = sql_txt ? sql_txt : "no statement available"; | 22 sql_text_ = sql_txt ? sql_txt : "no statement available"; |
23 return error; | 23 return error; |
24 } | 24 } |
25 | 25 |
26 int error() const { return error_; } | 26 int error() const { return error_; } |
27 | 27 |
28 void reset_error() { | 28 void reset_error() { |
29 sql_text_.clear(); | 29 sql_text_.clear(); |
30 error_ = SQLITE_OK; | 30 error_ = SQLITE_OK; |
31 } | 31 } |
32 | 32 |
33 const char* sql_statement() const { return sql_text_.c_str(); } | 33 const char* sql_statement() const { return sql_text_.c_str(); } |
34 | 34 |
| 35 protected: |
| 36 virtual ~StatementErrorHandler() {} |
| 37 |
35 private: | 38 private: |
36 int error_; | 39 int error_; |
37 std::string sql_text_; | 40 std::string sql_text_; |
38 }; | 41 }; |
39 | 42 |
40 class SQLStatementTest : public testing::Test { | 43 class SQLStatementTest : public testing::Test { |
41 public: | 44 public: |
42 SQLStatementTest() : error_handler_(new StatementErrorHandler) {} | 45 SQLStatementTest() : error_handler_(new StatementErrorHandler) {} |
43 | 46 |
44 void SetUp() { | 47 void SetUp() { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 138 |
136 s.Reset(false); | 139 s.Reset(false); |
137 // Verify that we can get all rows again. | 140 // Verify that we can get all rows again. |
138 ASSERT_TRUE(s.Step()); | 141 ASSERT_TRUE(s.Step()); |
139 EXPECT_EQ(12, s.ColumnInt(0)); | 142 EXPECT_EQ(12, s.ColumnInt(0)); |
140 EXPECT_FALSE(s.Step()); | 143 EXPECT_FALSE(s.Step()); |
141 | 144 |
142 s.Reset(true); | 145 s.Reset(true); |
143 ASSERT_FALSE(s.Step()); | 146 ASSERT_FALSE(s.Step()); |
144 } | 147 } |
OLD | NEW |