summaryrefslogtreecommitdiffstats
path: root/sql/statement.cc
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-25 20:09:32 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-25 20:09:32 +0000
commit097723df58b4749b4b9cbe606f933de34ad35b30 (patch)
tree2a681070281047242a434af0b7f6fc9737ed737b /sql/statement.cc
parent361abceedddbea70c1bb90e4c7ce57175a2fd9e4 (diff)
downloadchromium_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/statement.cc')
-rw-r--r--sql/statement.cc13
1 files changed, 13 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;