OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "app/sql/connection.h" | 5 #include "app/sql/connection.h" |
6 #include "app/sql/statement.h" | 6 #include "app/sql/statement.h" |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "third_party/sqlite/sqlite3.h" | 11 #include "third_party/sqlite/sqlite3.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)")); | 84 ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)")); |
85 EXPECT_TRUE(db().DoesTableExist("foo")); | 85 EXPECT_TRUE(db().DoesTableExist("foo")); |
86 | 86 |
87 // Should be case sensitive. | 87 // Should be case sensitive. |
88 EXPECT_FALSE(db().DoesTableExist("FOO")); | 88 EXPECT_FALSE(db().DoesTableExist("FOO")); |
89 | 89 |
90 // Test DoesColumnExist. | 90 // Test DoesColumnExist. |
91 EXPECT_FALSE(db().DoesColumnExist("foo", "bar")); | 91 EXPECT_FALSE(db().DoesColumnExist("foo", "bar")); |
92 EXPECT_TRUE(db().DoesColumnExist("foo", "a")); | 92 EXPECT_TRUE(db().DoesColumnExist("foo", "a")); |
93 | 93 |
94 // Testing for a column on a nonexistant table. | 94 // Testing for a column on a nonexistent table. |
95 EXPECT_FALSE(db().DoesColumnExist("bar", "b")); | 95 EXPECT_FALSE(db().DoesColumnExist("bar", "b")); |
96 } | 96 } |
97 | 97 |
98 TEST_F(SQLConnectionTest, GetLastInsertRowId) { | 98 TEST_F(SQLConnectionTest, GetLastInsertRowId) { |
99 ASSERT_TRUE(db().Execute("CREATE TABLE foo (id INTEGER PRIMARY KEY, value)")); | 99 ASSERT_TRUE(db().Execute("CREATE TABLE foo (id INTEGER PRIMARY KEY, value)")); |
100 | 100 |
101 ASSERT_TRUE(db().Execute("INSERT INTO foo (value) VALUES (12)")); | 101 ASSERT_TRUE(db().Execute("INSERT INTO foo (value) VALUES (12)")); |
102 | 102 |
103 // Last insert row ID should be valid. | 103 // Last insert row ID should be valid. |
104 int64 row = db().GetLastInsertRowId(); | 104 int64 row = db().GetLastInsertRowId(); |
105 EXPECT_LT(0, row); | 105 EXPECT_LT(0, row); |
106 | 106 |
107 // It should be the primary key of the row we just inserted. | 107 // It should be the primary key of the row we just inserted. |
108 sql::Statement s(db().GetUniqueStatement("SELECT value FROM foo WHERE id=?")); | 108 sql::Statement s(db().GetUniqueStatement("SELECT value FROM foo WHERE id=?")); |
109 s.BindInt64(0, row); | 109 s.BindInt64(0, row); |
110 ASSERT_TRUE(s.Step()); | 110 ASSERT_TRUE(s.Step()); |
111 EXPECT_EQ(12, s.ColumnInt(0)); | 111 EXPECT_EQ(12, s.ColumnInt(0)); |
112 } | 112 } |
113 | 113 |
OLD | NEW |