Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1393)

Side by Side Diff: sql/connection_unittest.cc

Issue 901033002: Import SQLite 3.8.7.4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chromium changes to support SQLite 3.8.7.4. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/files/file_util.h" 6 #include "base/files/file_util.h"
7 #include "base/files/scoped_file.h" 7 #include "base/files/scoped_file.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "sql/connection.h" 10 #include "sql/connection.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 TEST_F(SQLConnectionTest, ErrorCallback) { 230 TEST_F(SQLConnectionTest, ErrorCallback) {
231 const char* kCreateSql = "CREATE TABLE foo (id INTEGER UNIQUE)"; 231 const char* kCreateSql = "CREATE TABLE foo (id INTEGER UNIQUE)";
232 ASSERT_TRUE(db().Execute(kCreateSql)); 232 ASSERT_TRUE(db().Execute(kCreateSql));
233 ASSERT_TRUE(db().Execute("INSERT INTO foo (id) VALUES (12)")); 233 ASSERT_TRUE(db().Execute("INSERT INTO foo (id) VALUES (12)"));
234 234
235 int error = SQLITE_OK; 235 int error = SQLITE_OK;
236 { 236 {
237 sql::ScopedErrorCallback sec( 237 sql::ScopedErrorCallback sec(
238 &db(), base::Bind(&sql::CaptureErrorCallback, &error)); 238 &db(), base::Bind(&sql::CaptureErrorCallback, &error));
239 EXPECT_FALSE(db().Execute("INSERT INTO foo (id) VALUES (12)")); 239 EXPECT_FALSE(db().Execute("INSERT INTO foo (id) VALUES (12)"));
240 EXPECT_EQ(SQLITE_CONSTRAINT, error); 240
241 // Later versions of SQLite throw SQLITE_CONSTRAINT_UNIQUE. The specific
242 // sub-error isn't really important.
243 EXPECT_EQ(SQLITE_CONSTRAINT, (error&0xff));
241 } 244 }
242 245
243 // Callback is no longer in force due to reset. 246 // Callback is no longer in force due to reset.
244 { 247 {
245 error = SQLITE_OK; 248 error = SQLITE_OK;
246 sql::ScopedErrorIgnorer ignore_errors; 249 sql::ScopedErrorIgnorer ignore_errors;
247 ignore_errors.IgnoreError(SQLITE_CONSTRAINT); 250 ignore_errors.IgnoreError(SQLITE_CONSTRAINT);
248 ASSERT_FALSE(db().Execute("INSERT INTO foo (id) VALUES (12)")); 251 ASSERT_FALSE(db().Execute("INSERT INTO foo (id) VALUES (12)"));
249 ASSERT_TRUE(ignore_errors.CheckIgnoredErrors()); 252 ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
250 EXPECT_EQ(SQLITE_OK, error); 253 EXPECT_EQ(SQLITE_OK, error);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 444
442 { 445 {
443 base::ScopedFILE file(base::OpenFile(db_path(), "wb")); 446 base::ScopedFILE file(base::OpenFile(db_path(), "wb"));
444 ASSERT_TRUE(file.get() != NULL); 447 ASSERT_TRUE(file.get() != NULL);
445 448
446 const char* kJunk = "This is the hour of our discontent."; 449 const char* kJunk = "This is the hour of our discontent.";
447 fputs(kJunk, file.get()); 450 fputs(kJunk, file.get());
448 } 451 }
449 ASSERT_TRUE(base::PathExists(db_path())); 452 ASSERT_TRUE(base::PathExists(db_path()));
450 453
451 // SQLite will successfully open the handle, but will fail with 454 // SQLite will successfully open the handle, but fail when running PRAGMA
452 // SQLITE_IOERR_SHORT_READ on pragma statemenets which read the 455 // statements that access the database.
453 // header.
454 { 456 {
455 sql::ScopedErrorIgnorer ignore_errors; 457 sql::ScopedErrorIgnorer ignore_errors;
456 ignore_errors.IgnoreError(SQLITE_IOERR_SHORT_READ); 458
459 // Earlier versions of Chromium compiled against SQLite 3.6.7.3, which
460 // returned SQLITE_IOERR_SHORT_READ in this case. Some platforms may still
461 // compile against an earlier SQLite via USE_SYSTEM_SQLITE.
462 if (ignore_errors.SQLiteLibVersionNumber() < 3008007) {
463 ignore_errors.IgnoreError(SQLITE_IOERR_SHORT_READ);
464 } else {
465 ignore_errors.IgnoreError(SQLITE_NOTADB);
466 }
467
457 EXPECT_TRUE(db().Open(db_path())); 468 EXPECT_TRUE(db().Open(db_path()));
458 ASSERT_TRUE(ignore_errors.CheckIgnoredErrors()); 469 ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
459 } 470 }
460 EXPECT_TRUE(db().Raze()); 471 EXPECT_TRUE(db().Raze());
461 db().Close(); 472 db().Close();
462 473
463 // Now empty, the open should open an empty database. 474 // Now empty, the open should open an empty database.
464 EXPECT_TRUE(db().Open(db_path())); 475 EXPECT_TRUE(db().Open(db_path()));
465 EXPECT_EQ(0, SqliteMasterCount(&db())); 476 EXPECT_EQ(0, SqliteMasterCount(&db()));
466 } 477 }
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 EXPECT_LT(1u, messages.size()); 870 EXPECT_LT(1u, messages.size());
860 EXPECT_NE(kOk, messages[0]); 871 EXPECT_NE(kOk, messages[0]);
861 ASSERT_TRUE(ignore_errors.CheckIgnoredErrors()); 872 ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
862 } 873 }
863 874
864 // TODO(shess): CorruptTableOrIndex could be used to produce a 875 // TODO(shess): CorruptTableOrIndex could be used to produce a
865 // file that would pass the quick check and fail the full check. 876 // file that would pass the quick check and fail the full check.
866 } 877 }
867 878
868 } // namespace 879 } // namespace
OLDNEW
« no previous file with comments | « sql/BUILD.gn ('k') | sql/recovery.cc » ('j') | third_party/sqlite/src/src/os_unix.c » ('J')

Powered by Google App Engine
This is Rietveld 408576698