summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormichaelbai@chromium.org <michaelbai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-25 21:36:41 +0000
committermichaelbai@chromium.org <michaelbai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-25 21:36:41 +0000
commit389e0a485fe2c33cd25677ef5adf36b6f246c26c (patch)
tree2571a4bedd0047ee8b2f6fa6f8cab7e35f2ae17b
parent680ca65370fa194b8eea14b1c9c822e66fb2dd32 (diff)
downloadchromium_src-389e0a485fe2c33cd25677ef5adf36b6f246c26c.zip
chromium_src-389e0a485fe2c33cd25677ef5adf36b6f246c26c.tar.gz
chromium_src-389e0a485fe2c33cd25677ef5adf36b6f246c26c.tar.bz2
Added parameter 'clear_bound_vars', so we could reset the statement without clearing bound variables, so and current row is reset to the beginning.
It is used to support the Andorid' sqlite cursor feature which could move the cursor around the result set. BUG= TEST=Added a new test. TBR=agl,akalin,michaeln Review URL: http://codereview.chromium.org/10171014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133985 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autocomplete/network_action_predictor_database.cc2
-rw-r--r--chrome/browser/history/text_database.cc6
-rw-r--r--chrome/browser/history/visitsegment_database.cc2
-rw-r--r--chrome/browser/importer/firefox3_importer.cc2
-rw-r--r--chrome/browser/importer/safari_importer.mm2
-rw-r--r--chrome/browser/net/sqlite_persistent_cookie_store.cc8
-rw-r--r--chrome/browser/net/sqlite_server_bound_cert_store.cc8
-rw-r--r--chrome/browser/webdata/autofill_table.cc2
-rw-r--r--sql/connection_unittest.cc4
-rw-r--r--sql/statement.cc9
-rw-r--r--sql/statement.h6
-rw-r--r--sql/statement_unittest.cc28
-rw-r--r--sync/syncable/directory_backing_store.cc10
-rw-r--r--webkit/appcache/appcache_database.cc2
-rw-r--r--webkit/appcache/appcache_database_unittest.cc4
15 files changed, 59 insertions, 36 deletions
diff --git a/chrome/browser/autocomplete/network_action_predictor_database.cc b/chrome/browser/autocomplete/network_action_predictor_database.cc
index 77cce30..a1454f4 100644
--- a/chrome/browser/autocomplete/network_action_predictor_database.cc
+++ b/chrome/browser/autocomplete/network_action_predictor_database.cc
@@ -204,7 +204,7 @@ void NetworkActionPredictorDatabase::DeleteRows(
it != id_list.end(); ++it) {
statement.BindString(0, *it);
statement.Run();
- statement.Reset();
+ statement.Reset(true);
}
db_.CommitTransaction();
}
diff --git a/chrome/browser/history/text_database.cc b/chrome/browser/history/text_database.cc
index 3e3d925..f33cc6b 100644
--- a/chrome/browser/history/text_database.cc
+++ b/chrome/browser/history/text_database.cc
@@ -260,7 +260,7 @@ void TextDatabase::DeletePageData(base::Time time, const std::string& url) {
delete_page.BindInt64(0, *i);
if (!delete_page.Run())
return;
- delete_page.Reset();
+ delete_page.Reset(true);
}
// Delete from the info table.
@@ -272,7 +272,7 @@ void TextDatabase::DeletePageData(base::Time time, const std::string& url) {
delete_info.BindInt64(0, *i);
if (!delete_info.Run())
return;
- delete_info.Reset();
+ delete_info.Reset(true);
}
}
@@ -359,7 +359,7 @@ void TextDatabase::GetTextMatches(const std::string& query,
*first_time_searched = results->back().time;
}
- statement.Reset();
+ statement.Reset(true);
}
} // namespace history
diff --git a/chrome/browser/history/visitsegment_database.cc b/chrome/browser/history/visitsegment_database.cc
index 98e7827..d4a54da 100644
--- a/chrome/browser/history/visitsegment_database.cc
+++ b/chrome/browser/history/visitsegment_database.cc
@@ -298,7 +298,7 @@ void VisitSegmentDatabase::QuerySegmentUsage(
pud->SetURL(GURL(statement2.ColumnString(0)));
pud->SetTitle(statement2.ColumnString16(1));
}
- statement2.Reset();
+ statement2.Reset(true);
}
}
diff --git a/chrome/browser/importer/firefox3_importer.cc b/chrome/browser/importer/firefox3_importer.cc
index b6c0a3e..948df98 100644
--- a/chrome/browser/importer/firefox3_importer.cc
+++ b/chrome/browser/importer/firefox3_importer.cc
@@ -566,6 +566,6 @@ void Firefox3Importer::LoadFavicons(
usage.urls = i->second;
favicons->push_back(usage);
}
- s.Reset();
+ s.Reset(true);
}
}
diff --git a/chrome/browser/importer/safari_importer.mm b/chrome/browser/importer/safari_importer.mm
index ec17c99..921ebc4 100644
--- a/chrome/browser/importer/safari_importer.mm
+++ b/chrome/browser/importer/safari_importer.mm
@@ -162,7 +162,7 @@ void SafariImporter::LoadFaviconData(
for (FaviconMap::const_iterator i = favicon_map.begin();
i != favicon_map.end(); ++i) {
- s.Reset();
+ s.Reset(true);
s.BindInt64(0, i->first);
if (s.Step()) {
history::ImportedFaviconUsage usage;
diff --git a/chrome/browser/net/sqlite_persistent_cookie_store.cc b/chrome/browser/net/sqlite_persistent_cookie_store.cc
index 48a0533..04c2d4f 100644
--- a/chrome/browser/net/sqlite_persistent_cookie_store.cc
+++ b/chrome/browser/net/sqlite_persistent_cookie_store.cc
@@ -620,7 +620,7 @@ bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains(
cookies.push_back(cc.release());
++num_cookies_read_;
}
- smt.Reset();
+ smt.Reset(true);
}
{
base::AutoLock locked(lock_);
@@ -826,7 +826,7 @@ void SQLitePersistentCookieStore::Backend::Commit() {
scoped_ptr<PendingOperation> po(*it);
switch (po->op()) {
case PendingOperation::COOKIE_ADD:
- add_smt.Reset();
+ add_smt.Reset(true);
add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue());
add_smt.BindString(1, po->cc().Domain());
add_smt.BindString(2, po->cc().Name());
@@ -843,7 +843,7 @@ void SQLitePersistentCookieStore::Backend::Commit() {
break;
case PendingOperation::COOKIE_UPDATEACCESS:
- update_access_smt.Reset();
+ update_access_smt.Reset(true);
update_access_smt.BindInt64(0,
po->cc().LastAccessDate().ToInternalValue());
update_access_smt.BindInt64(1,
@@ -853,7 +853,7 @@ void SQLitePersistentCookieStore::Backend::Commit() {
break;
case PendingOperation::COOKIE_DELETE:
- del_smt.Reset();
+ del_smt.Reset(true);
del_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue());
if (!del_smt.Run())
NOTREACHED() << "Could not delete a cookie from the DB.";
diff --git a/chrome/browser/net/sqlite_server_bound_cert_store.cc b/chrome/browser/net/sqlite_server_bound_cert_store.cc
index 69dea95..e4a35e9 100644
--- a/chrome/browser/net/sqlite_server_bound_cert_store.cc
+++ b/chrome/browser/net/sqlite_server_bound_cert_store.cc
@@ -283,7 +283,7 @@ bool SQLiteServerBoundCertStore::Backend::EnsureDatabaseVersion() {
cert_from_db.data(), cert_from_db.size()));
if (cert) {
if (cur_version == 2) {
- update_expires_smt.Reset();
+ update_expires_smt.Reset(true);
update_expires_smt.BindInt64(0,
cert->valid_expiry().ToInternalValue());
update_expires_smt.BindString(1, origin);
@@ -294,7 +294,7 @@ bool SQLiteServerBoundCertStore::Backend::EnsureDatabaseVersion() {
}
}
- update_creation_smt.Reset();
+ update_creation_smt.Reset(true);
update_creation_smt.BindInt64(0, cert->valid_start().ToInternalValue());
update_creation_smt.BindString(1, origin);
if (!update_creation_smt.Run()) {
@@ -406,7 +406,7 @@ void SQLiteServerBoundCertStore::Backend::Commit() {
scoped_ptr<PendingOperation> po(*it);
switch (po->op()) {
case PendingOperation::CERT_ADD: {
- add_smt.Reset();
+ add_smt.Reset(true);
add_smt.BindString(0, po->cert().server_identifier());
const std::string& private_key = po->cert().private_key();
add_smt.BindBlob(1, private_key.data(), private_key.size());
@@ -420,7 +420,7 @@ void SQLiteServerBoundCertStore::Backend::Commit() {
break;
}
case PendingOperation::CERT_DELETE:
- del_smt.Reset();
+ del_smt.Reset(true);
del_smt.BindString(0, po->cert().server_identifier());
if (!del_smt.Run())
NOTREACHED() << "Could not delete a server bound cert from the DB.";
diff --git a/chrome/browser/webdata/autofill_table.cc b/chrome/browser/webdata/autofill_table.cc
index 4cc6f2f..aa4c225 100644
--- a/chrome/browser/webdata/autofill_table.cc
+++ b/chrome/browser/webdata/autofill_table.cc
@@ -502,7 +502,7 @@ bool AutofillTable::RemoveExpiredFormElements(
entries[i].timestamps().back().ToTimeT());
if (!cull_date_entry.Run())
return false;
- cull_date_entry.Reset();
+ cull_date_entry.Reset(true);
}
changes->clear();
diff --git a/sql/connection_unittest.cc b/sql/connection_unittest.cc
index 96cc25b..97dd152 100644
--- a/sql/connection_unittest.cc
+++ b/sql/connection_unittest.cc
@@ -195,7 +195,7 @@ TEST_F(SQLConnectionTest, RazePageSize) {
// After raze, page_size should still match the indicated value.
ASSERT_TRUE(db().Raze());
- s.Reset();
+ s.Reset(true);
ASSERT_TRUE(s.Step());
ASSERT_EQ(kPageSize, s.ColumnInt(0));
}
@@ -218,7 +218,7 @@ TEST_F(SQLConnectionTest, RazeMultiple) {
ASSERT_TRUE(db().Raze());
// The second connection sees the updated database.
- s.Reset();
+ s.Reset(true);
ASSERT_TRUE(s.Step());
ASSERT_EQ(0, s.ColumnInt(0));
}
diff --git a/sql/statement.cc b/sql/statement.cc
index 626c15b..3616dcc 100644
--- a/sql/statement.cc
+++ b/sql/statement.cc
@@ -28,11 +28,11 @@ Statement::~Statement() {
// Free the resources associated with this statement. We assume there's only
// one statement active for a given sqlite3_stmt at any time, so this won't
// mess with anything.
- Reset();
+ Reset(true);
}
void Statement::Assign(scoped_refptr<Connection::StatementRef> ref) {
- Reset();
+ Reset(true);
ref_ = ref;
}
@@ -61,12 +61,13 @@ bool Statement::Step() {
return CheckError(sqlite3_step(ref_->stmt())) == SQLITE_ROW;
}
-void Statement::Reset() {
+void Statement::Reset(bool clear_bound_vars) {
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.
- sqlite3_clear_bindings(ref_->stmt());
+ if (clear_bound_vars)
+ sqlite3_clear_bindings(ref_->stmt());
sqlite3_reset(ref_->stmt());
}
diff --git a/sql/statement.h b/sql/statement.h
index 92d1ef2..269684f 100644
--- a/sql/statement.h
+++ b/sql/statement.h
@@ -87,9 +87,9 @@ class SQL_EXPORT Statement {
// return s.Succeeded();
bool Step();
- // Resets the statement to its initial condition. This includes clearing all
- // the bound variables and any current result row.
- void Reset();
+ // Resets the statement to its initial condition. This includes any current
+ // result row, and also the bound variables if the |clear_bound_vars| is true.
+ void Reset(bool clear_bound_vars);
// Returns true if the last executed thing in this statement succeeded. If
// there was no last executed thing or the statement is invalid, this will
diff --git a/sql/statement_unittest.cc b/sql/statement_unittest.cc
index b6b6aa8..0028b9d 100644
--- a/sql/statement_unittest.cc
+++ b/sql/statement_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -88,14 +88,14 @@ TEST_F(SQLStatementTest, Run) {
// Run should fail since this produces output, and we should use Step(). This
// gets a bit wonky since sqlite says this is OK so succeeded is set.
- s.Reset();
+ s.Reset(true);
s.BindInt(0, 3);
EXPECT_FALSE(s.Run());
EXPECT_EQ(SQLITE_ROW, db().GetErrorCode());
EXPECT_TRUE(s.Succeeded());
// Resetting it should put it back to the previous state (not runnable).
- s.Reset();
+ s.Reset(true);
EXPECT_FALSE(s.Succeeded());
// Binding and stepping should produce one row.
@@ -120,3 +120,25 @@ TEST_F(SQLStatementTest, BasicErrorCallback) {
EXPECT_EQ(SQLITE_MISMATCH, sqlite_error());
reset_error();
}
+
+TEST_F(SQLStatementTest, Reset) {
+ ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)"));
+ ASSERT_TRUE(db().Execute("INSERT INTO foo (a, b) VALUES (3, 12)"));
+ ASSERT_TRUE(db().Execute("INSERT INTO foo (a, b) VALUES (4, 13)"));
+
+ sql::Statement s(db().GetUniqueStatement(
+ "SELECT b FROM foo WHERE a = ? "));
+ s.BindInt(0, 3);
+ ASSERT_TRUE(s.Step());
+ EXPECT_EQ(12, s.ColumnInt(0));
+ ASSERT_FALSE(s.Step());
+
+ s.Reset(false);
+ // Verify that we can get all rows again.
+ ASSERT_TRUE(s.Step());
+ EXPECT_EQ(12, s.ColumnInt(0));
+ EXPECT_FALSE(s.Step());
+
+ s.Reset(true);
+ ASSERT_FALSE(s.Step());
+}
diff --git a/sync/syncable/directory_backing_store.cc b/sync/syncable/directory_backing_store.cc
index 1685610..fda6d71 100644
--- a/sync/syncable/directory_backing_store.cc
+++ b/sync/syncable/directory_backing_store.cc
@@ -163,7 +163,7 @@ bool DirectoryBackingStore::DeleteEntries(const MetahandleSet& handles) {
statement.BindInt64(0, *i);
if (!statement.Run())
return false;
- statement.Reset();
+ statement.Reset(true);
}
return true;
}
@@ -227,7 +227,7 @@ bool DirectoryBackingStore::SaveChanges(
if (!s2.Run())
return false;
DCHECK_EQ(db_->GetLastChangeCount(), 1);
- s2.Reset();
+ s2.Reset(true);
}
}
@@ -499,7 +499,7 @@ bool DirectoryBackingStore::SaveEntryToDB(const EntryKernel& entry) {
save_entry_statement_.Assign(
db_->GetUniqueStatement(query.c_str()));
} else {
- save_entry_statement_.Reset();
+ save_entry_statement_.Reset(true);
}
BindFields(entry, &save_entry_statement_);
@@ -583,7 +583,7 @@ bool DirectoryBackingStore::MigrateToSpecifics(
update.BindInt64(1, metahandle);
if (!update.Run())
return false;
- update.Reset();
+ update.Reset(true);
}
return query.Succeeded();
}
@@ -868,7 +868,7 @@ bool DirectoryBackingStore::MigrateVersion74To75() {
update.BindBool(2, query.ColumnBool(2));
if (!update.Run())
return false;
- update.Reset();
+ update.Reset(true);
}
}
if (!query.Succeeded())
diff --git a/webkit/appcache/appcache_database.cc b/webkit/appcache/appcache_database.cc
index 1f5c6de..90c2d7c 100644
--- a/webkit/appcache/appcache_database.cc
+++ b/webkit/appcache/appcache_database.cc
@@ -852,7 +852,7 @@ bool AppCacheDatabase::RunCachedStatementWithIds(
statement.BindInt64(0, *iter);
if (!statement.Run())
return false;
- statement.Reset();
+ statement.Reset(true);
++iter;
}
diff --git a/webkit/appcache/appcache_database_unittest.cc b/webkit/appcache/appcache_database_unittest.cc
index 014a569..e147850 100644
--- a/webkit/appcache/appcache_database_unittest.cc
+++ b/webkit/appcache/appcache_database_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -790,7 +790,7 @@ TEST(AppCacheDatabaseTest, UpgradeSchema3to4) {
statement.BindString(2, namespace_url.spec().c_str());
statement.BindString(3, target_url.spec().c_str());
ASSERT_TRUE(statement.Run());
- statement.Reset();
+ statement.Reset(true);
}
EXPECT_TRUE(transaction.Commit());