| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/sql/connection.h" | 7 #include "app/sql/connection.h" |
| 8 #include "app/sql/statement.h" | 8 #include "app/sql/statement.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/sqlite/preprocessed/sqlite3.h" | 13 #include "third_party/sqlite/sqlite3.h" |
| 14 | 14 |
| 15 class StatementErrorHandler : public sql::ErrorDelegate { | 15 class StatementErrorHandler : public sql::ErrorDelegate { |
| 16 public: | 16 public: |
| 17 StatementErrorHandler() : error_(SQLITE_OK) {} | 17 StatementErrorHandler() : error_(SQLITE_OK) {} |
| 18 | 18 |
| 19 virtual int OnError(int error, sql::Connection* connection, | 19 virtual int OnError(int error, sql::Connection* connection, |
| 20 sql::Statement* stmt) { | 20 sql::Statement* stmt) { |
| 21 error_ = error; | 21 error_ = error; |
| 22 const char* sql_txt = stmt ? stmt->GetSQLStatement() : NULL; | 22 const char* sql_txt = stmt ? stmt->GetSQLStatement() : NULL; |
| 23 sql_text_ = sql_txt ? sql_txt : "no statement available"; | 23 sql_text_ = sql_txt ? sql_txt : "no statement available"; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // Insert in the foo table the primary key. It is an error to insert | 122 // Insert in the foo table the primary key. It is an error to insert |
| 123 // something other than an number. This error causes the error callback | 123 // something other than an number. This error causes the error callback |
| 124 // handler to be called with SQLITE_MISMATCH as error code. | 124 // handler to be called with SQLITE_MISMATCH as error code. |
| 125 sql::Statement s(db().GetUniqueStatement("INSERT INTO foo (a) VALUES (?)")); | 125 sql::Statement s(db().GetUniqueStatement("INSERT INTO foo (a) VALUES (?)")); |
| 126 EXPECT_TRUE(s.is_valid()); | 126 EXPECT_TRUE(s.is_valid()); |
| 127 s.BindCString(0, "bad bad"); | 127 s.BindCString(0, "bad bad"); |
| 128 EXPECT_FALSE(s.Run()); | 128 EXPECT_FALSE(s.Run()); |
| 129 EXPECT_EQ(SQLITE_MISMATCH, sqlite_error()); | 129 EXPECT_EQ(SQLITE_MISMATCH, sqlite_error()); |
| 130 reset_error(); | 130 reset_error(); |
| 131 } | 131 } |
| OLD | NEW |