diff options
author | michaelbai@chromium.org <michaelbai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 21:36:41 +0000 |
---|---|---|
committer | michaelbai@chromium.org <michaelbai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 21:36:41 +0000 |
commit | 389e0a485fe2c33cd25677ef5adf36b6f246c26c (patch) | |
tree | 2571a4bedd0047ee8b2f6fa6f8cab7e35f2ae17b /sql/statement_unittest.cc | |
parent | 680ca65370fa194b8eea14b1c9c822e66fb2dd32 (diff) | |
download | chromium_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
Diffstat (limited to 'sql/statement_unittest.cc')
-rw-r--r-- | sql/statement_unittest.cc | 28 |
1 files changed, 25 insertions, 3 deletions
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()); +} |