diff options
author | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-25 20:09:32 +0000 |
---|---|---|
committer | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-25 20:09:32 +0000 |
commit | 097723df58b4749b4b9cbe606f933de34ad35b30 (patch) | |
tree | 2a681070281047242a434af0b7f6fc9737ed737b /sql | |
parent | 361abceedddbea70c1bb90e4c7ce57175a2fd9e4 (diff) | |
download | chromium_src-097723df58b4749b4b9cbe606f933de34ad35b30.zip chromium_src-097723df58b4749b4b9cbe606f933de34ad35b30.tar.gz chromium_src-097723df58b4749b4b9cbe606f933de34ad35b30.tar.bz2 |
[sql] Complain about statement mutations after stepping has started.
DCHECK if any Bind*() calls occur after Step() has been called. The
bind cannot be implemented at that point, so most likely the calling
code has an error, such as a forgotted Reset().
Also DCHECK if Run() is called after Run() or Step() without an
intervening Reset(). Such a calling sequence is unlikely to be
intentional, because the results of calling Run() twice aren't
defined.
BUG=309759
Review URL: https://codereview.chromium.org/40733003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231098 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql')
-rw-r--r-- | sql/statement.cc | 13 | ||||
-rw-r--r-- | sql/statement.h | 5 |
2 files changed, 18 insertions, 0 deletions
diff --git a/sql/statement.cc b/sql/statement.cc index 67b7334..4f5e17f 100644 --- a/sql/statement.cc +++ b/sql/statement.cc @@ -16,11 +16,13 @@ namespace sql { // only have to check the ref's validity bit. Statement::Statement() : ref_(new Connection::StatementRef(NULL, NULL, false)), + stepped_(false), succeeded_(false) { } Statement::Statement(scoped_refptr<Connection::StatementRef> ref) : ref_(ref), + stepped_(false), succeeded_(false) { } @@ -50,10 +52,12 @@ bool Statement::CheckValid() const { } bool Statement::Run() { + DCHECK(!stepped_); ref_->AssertIOAllowed(); if (!CheckValid()) return false; + stepped_ = true; return CheckError(sqlite3_step(ref_->stmt())) == SQLITE_DONE; } @@ -62,6 +66,7 @@ bool Statement::Step() { if (!CheckValid()) return false; + stepped_ = true; return CheckError(sqlite3_step(ref_->stmt())) == SQLITE_ROW; } @@ -77,6 +82,7 @@ void Statement::Reset(bool clear_bound_vars) { } succeeded_ = false; + stepped_ = false; } bool Statement::Succeeded() const { @@ -87,6 +93,7 @@ bool Statement::Succeeded() const { } bool Statement::BindNull(int col) { + DCHECK(!stepped_); if (!is_valid()) return false; @@ -98,6 +105,7 @@ bool Statement::BindBool(int col, bool val) { } bool Statement::BindInt(int col, int val) { + DCHECK(!stepped_); if (!is_valid()) return false; @@ -105,6 +113,7 @@ bool Statement::BindInt(int col, int val) { } bool Statement::BindInt64(int col, int64 val) { + DCHECK(!stepped_); if (!is_valid()) return false; @@ -112,6 +121,7 @@ bool Statement::BindInt64(int col, int64 val) { } bool Statement::BindDouble(int col, double val) { + DCHECK(!stepped_); if (!is_valid()) return false; @@ -119,6 +129,7 @@ bool Statement::BindDouble(int col, double val) { } bool Statement::BindCString(int col, const char* val) { + DCHECK(!stepped_); if (!is_valid()) return false; @@ -127,6 +138,7 @@ bool Statement::BindCString(int col, const char* val) { } bool Statement::BindString(int col, const std::string& val) { + DCHECK(!stepped_); if (!is_valid()) return false; @@ -142,6 +154,7 @@ bool Statement::BindString16(int col, const string16& value) { } bool Statement::BindBlob(int col, const void* val, int val_len) { + DCHECK(!stepped_); if (!is_valid()) return false; diff --git a/sql/statement.h b/sql/statement.h index 5fedc53..acf89e7 100644 --- a/sql/statement.h +++ b/sql/statement.h @@ -178,6 +178,11 @@ class SQL_EXPORT Statement { // guaranteed non-NULL. scoped_refptr<Connection::StatementRef> ref_; + // Set after Step() or Run() are called, reset by Reset(). Used to + // prevent accidental calls to API functions which would not work + // correctly after stepping has started. + bool stepped_; + // See Succeeded() for what this holds. bool succeeded_; |