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

Unified Diff: sql/statement.cc

Issue 1145833002: [sql] Stats gathering for sql/ APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: asvitkine nits. Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sql/statement.h ('k') | storage/browser/database/database_tracker.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sql/statement.cc
diff --git a/sql/statement.cc b/sql/statement.cc
index 42b4598c51da87bcc6037446dc7e1d6970ab5153..038ebde0885670d136c454485d70a4cabe63450d 100644
--- a/sql/statement.cc
+++ b/sql/statement.cc
@@ -51,34 +51,63 @@ bool Statement::CheckValid() const {
return is_valid();
}
-bool Statement::Run() {
- DCHECK(!stepped_);
+int Statement::StepInternal(bool timer_flag) {
ref_->AssertIOAllowed();
if (!CheckValid())
- return false;
+ return SQLITE_ERROR;
+ const bool was_stepped = stepped_;
stepped_ = true;
- return CheckError(sqlite3_step(ref_->stmt())) == SQLITE_DONE;
+ int ret = SQLITE_ERROR;
+ if (!ref_->connection()) {
+ ret = sqlite3_step(ref_->stmt());
+ } else {
+ if (!timer_flag) {
+ ret = sqlite3_step(ref_->stmt());
+ } else {
+ const base::TimeTicks before = ref_->connection()->Now();
+ ret = sqlite3_step(ref_->stmt());
+ const base::TimeTicks after = ref_->connection()->Now();
+ const bool read_only = !!sqlite3_stmt_readonly(ref_->stmt());
+ ref_->connection()->RecordTimeAndChanges(after - before, read_only);
+ }
+
+ if (!was_stepped)
+ ref_->connection()->RecordOneEvent(Connection::EVENT_STATEMENT_RUN);
+
+ if (ret == SQLITE_ROW)
+ ref_->connection()->RecordOneEvent(Connection::EVENT_STATEMENT_ROWS);
+ }
+ return CheckError(ret);
}
-bool Statement::Step() {
- ref_->AssertIOAllowed();
- if (!CheckValid())
- return false;
+bool Statement::Run() {
+ DCHECK(!stepped_);
+ return StepInternal(true) == SQLITE_DONE;
+}
- stepped_ = true;
- return CheckError(sqlite3_step(ref_->stmt())) == SQLITE_ROW;
+bool Statement::RunWithoutTimers() {
+ DCHECK(!stepped_);
+ return StepInternal(false) == SQLITE_DONE;
+}
+
+bool Statement::Step() {
+ return StepInternal(true) == SQLITE_ROW;
}
void Statement::Reset(bool clear_bound_vars) {
ref_->AssertIOAllowed();
if (is_valid()) {
- // We don't call CheckError() here because sqlite3_reset() returns
- // the last error that Step() caused thereby generating a second
- // spurious error callback.
if (clear_bound_vars)
sqlite3_clear_bindings(ref_->stmt());
- sqlite3_reset(ref_->stmt());
+
+ // StepInternal() cannot track success because statements may be reset
+ // before reaching SQLITE_DONE. Don't call CheckError() because
+ // sqlite3_reset() returns the last step error, which StepInternal() already
+ // checked.
+ const int rc =sqlite3_reset(ref_->stmt());
+ if (rc == SQLITE_OK && ref_->connection())
+ ref_->connection()->RecordOneEvent(Connection::EVENT_STATEMENT_SUCCESS);
}
succeeded_ = false;
« no previous file with comments | « sql/statement.h ('k') | storage/browser/database/database_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698