| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 void reset_error() const { error_handler_->reset_error(); } | 63 void reset_error() const { error_handler_->reset_error(); } |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 ScopedTempDir temp_dir_; | 66 ScopedTempDir temp_dir_; |
| 67 sql::Connection db_; | 67 sql::Connection db_; |
| 68 scoped_refptr<StatementErrorHandler> error_handler_; | 68 scoped_refptr<StatementErrorHandler> error_handler_; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 TEST_F(SQLStatementTest, Assign) { | 71 TEST_F(SQLStatementTest, Assign) { |
| 72 sql::Statement s; | 72 sql::Statement s; |
| 73 EXPECT_FALSE(s); // bool conversion operator. | |
| 74 EXPECT_TRUE(!s); // ! operator. | |
| 75 EXPECT_FALSE(s.is_valid()); | 73 EXPECT_FALSE(s.is_valid()); |
| 76 | 74 |
| 77 s.Assign(db().GetUniqueStatement("CREATE TABLE foo (a, b)")); | 75 s.Assign(db().GetUniqueStatement("CREATE TABLE foo (a, b)")); |
| 78 EXPECT_TRUE(s); | |
| 79 EXPECT_FALSE(!s); | |
| 80 EXPECT_TRUE(s.is_valid()); | 76 EXPECT_TRUE(s.is_valid()); |
| 81 } | 77 } |
| 82 | 78 |
| 83 TEST_F(SQLStatementTest, Run) { | 79 TEST_F(SQLStatementTest, Run) { |
| 84 ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)")); | 80 ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)")); |
| 85 ASSERT_TRUE(db().Execute("INSERT INTO foo (a, b) VALUES (3, 12)")); | 81 ASSERT_TRUE(db().Execute("INSERT INTO foo (a, b) VALUES (3, 12)")); |
| 86 | 82 |
| 87 sql::Statement s(db().GetUniqueStatement("SELECT b FROM foo WHERE a=?")); | 83 sql::Statement s(db().GetUniqueStatement("SELECT b FROM foo WHERE a=?")); |
| 88 EXPECT_FALSE(s.Succeeded()); | 84 EXPECT_FALSE(s.Succeeded()); |
| 89 | 85 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 117 // Insert in the foo table the primary key. It is an error to insert | 113 // Insert in the foo table the primary key. It is an error to insert |
| 118 // something other than an number. This error causes the error callback | 114 // something other than an number. This error causes the error callback |
| 119 // handler to be called with SQLITE_MISMATCH as error code. | 115 // handler to be called with SQLITE_MISMATCH as error code. |
| 120 sql::Statement s(db().GetUniqueStatement("INSERT INTO foo (a) VALUES (?)")); | 116 sql::Statement s(db().GetUniqueStatement("INSERT INTO foo (a) VALUES (?)")); |
| 121 EXPECT_TRUE(s.is_valid()); | 117 EXPECT_TRUE(s.is_valid()); |
| 122 s.BindCString(0, "bad bad"); | 118 s.BindCString(0, "bad bad"); |
| 123 EXPECT_FALSE(s.Run()); | 119 EXPECT_FALSE(s.Run()); |
| 124 EXPECT_EQ(SQLITE_MISMATCH, sqlite_error()); | 120 EXPECT_EQ(SQLITE_MISMATCH, sqlite_error()); |
| 125 reset_error(); | 121 reset_error(); |
| 126 } | 122 } |
| OLD | NEW |