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

Side by Side Diff: third_party/WebKit/Source/modules/webdatabase/sqlite/SQLiteTransaction.cpp

Issue 2813433002: Replace ASSERT, ASSERT_NOT_REACHED, and RELEASE_ASSERT in modules/webdatabase (Closed)
Patch Set: Replace ASSERT, ASSERT_NOT_REACHED, and RELEASE_ASSERT in modules/webdatabase Created 3 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/modules/webdatabase/sqlite/SQLiteStatement.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 21 matching lines...) Expand all
32 SQLiteTransaction::SQLiteTransaction(SQLiteDatabase& db, bool read_only) 32 SQLiteTransaction::SQLiteTransaction(SQLiteDatabase& db, bool read_only)
33 : db_(db), in_progress_(false), read_only_(read_only) {} 33 : db_(db), in_progress_(false), read_only_(read_only) {}
34 34
35 SQLiteTransaction::~SQLiteTransaction() { 35 SQLiteTransaction::~SQLiteTransaction() {
36 if (in_progress_) 36 if (in_progress_)
37 Rollback(); 37 Rollback();
38 } 38 }
39 39
40 void SQLiteTransaction::begin() { 40 void SQLiteTransaction::begin() {
41 if (!in_progress_) { 41 if (!in_progress_) {
42 ASSERT(!db_.transaction_in_progress_); 42 DCHECK(!db_.transaction_in_progress_);
43 // Call BEGIN IMMEDIATE for a write transaction to acquire 43 // Call BEGIN IMMEDIATE for a write transaction to acquire
44 // a RESERVED lock on the DB file. Otherwise, another write 44 // a RESERVED lock on the DB file. Otherwise, another write
45 // transaction (on another connection) could make changes 45 // transaction (on another connection) could make changes
46 // to the same DB file before this transaction gets to execute 46 // to the same DB file before this transaction gets to execute
47 // any statements. If that happens, this transaction will fail. 47 // any statements. If that happens, this transaction will fail.
48 // http://www.sqlite.org/lang_transaction.html 48 // http://www.sqlite.org/lang_transaction.html
49 // http://www.sqlite.org/lockingv3.html#locking 49 // http://www.sqlite.org/lockingv3.html#locking
50 if (read_only_) 50 if (read_only_)
51 in_progress_ = db_.ExecuteCommand("BEGIN"); 51 in_progress_ = db_.ExecuteCommand("BEGIN");
52 else 52 else
53 in_progress_ = db_.ExecuteCommand("BEGIN IMMEDIATE"); 53 in_progress_ = db_.ExecuteCommand("BEGIN IMMEDIATE");
54 db_.transaction_in_progress_ = in_progress_; 54 db_.transaction_in_progress_ = in_progress_;
55 } 55 }
56 } 56 }
57 57
58 void SQLiteTransaction::Commit() { 58 void SQLiteTransaction::Commit() {
59 if (in_progress_) { 59 if (in_progress_) {
60 ASSERT(db_.transaction_in_progress_); 60 DCHECK(db_.transaction_in_progress_);
61 in_progress_ = !db_.ExecuteCommand("COMMIT"); 61 in_progress_ = !db_.ExecuteCommand("COMMIT");
62 db_.transaction_in_progress_ = in_progress_; 62 db_.transaction_in_progress_ = in_progress_;
63 } 63 }
64 } 64 }
65 65
66 void SQLiteTransaction::Rollback() { 66 void SQLiteTransaction::Rollback() {
67 // We do not use the 'm_inProgress = m_db.executeCommand("ROLLBACK")' 67 // We do not use the 'm_inProgress = m_db.executeCommand("ROLLBACK")'
68 // construct here, because m_inProgress should always be set to false after a 68 // construct here, because m_inProgress should always be set to false after a
69 // ROLLBACK, and m_db.executeCommand("ROLLBACK") can sometimes harmlessly 69 // ROLLBACK, and m_db.executeCommand("ROLLBACK") can sometimes harmlessly
70 // fail, thus returning a non-zero/true result 70 // fail, thus returning a non-zero/true result
71 // (http://www.sqlite.org/lang_transaction.html). 71 // (http://www.sqlite.org/lang_transaction.html).
72 if (in_progress_) { 72 if (in_progress_) {
73 ASSERT(db_.transaction_in_progress_); 73 DCHECK(db_.transaction_in_progress_);
74 db_.ExecuteCommand("ROLLBACK"); 74 db_.ExecuteCommand("ROLLBACK");
75 in_progress_ = false; 75 in_progress_ = false;
76 db_.transaction_in_progress_ = false; 76 db_.transaction_in_progress_ = false;
77 } 77 }
78 } 78 }
79 79
80 void SQLiteTransaction::Stop() { 80 void SQLiteTransaction::Stop() {
81 if (in_progress_) { 81 if (in_progress_) {
82 in_progress_ = false; 82 in_progress_ = false;
83 db_.transaction_in_progress_ = false; 83 db_.transaction_in_progress_ = false;
84 } 84 }
85 } 85 }
86 86
87 bool SQLiteTransaction::WasRolledBackBySqlite() const { 87 bool SQLiteTransaction::WasRolledBackBySqlite() const {
88 // According to http://www.sqlite.org/c3ref/get_autocommit.html, 88 // According to http://www.sqlite.org/c3ref/get_autocommit.html,
89 // the auto-commit flag should be off in the middle of a transaction 89 // the auto-commit flag should be off in the middle of a transaction
90 return in_progress_ && db_.IsAutoCommitOn(); 90 return in_progress_ && db_.IsAutoCommitOn();
91 } 91 }
92 92
93 } // namespace blink 93 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webdatabase/sqlite/SQLiteStatement.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698