# HG changeset patch # User Sebastien Jodogne # Date 1392738910 -3600 # Node ID 96a2d2da0feecb292d7856b4d9c6af51507edc13 # Parent 0da078f3affc2f8e652e21d2cc089753a9732b69 more sqlite tests diff -r 0da078f3affc -r 96a2d2da0fee Core/SQLite/Statement.cpp --- a/Core/SQLite/Statement.cpp Tue Feb 18 16:18:42 2014 +0100 +++ b/Core/SQLite/Statement.cpp Tue Feb 18 16:55:10 2014 +0100 @@ -295,7 +295,7 @@ return true; }*/ - bool Statement::ColumnBlobAsVector(int col, std::vector* val) const + /*bool Statement::ColumnBlobAsVector(int col, std::vector* val) const { val->clear(); @@ -306,14 +306,14 @@ memcpy(&(*val)[0], data, len); } return true; - } + }*/ - bool Statement::ColumnBlobAsVector( + /*bool Statement::ColumnBlobAsVector( int col, std::vector* val) const { return ColumnBlobAsVector(col, reinterpret_cast< std::vector* >(val)); - } + }*/ } } diff -r 0da078f3affc -r 96a2d2da0fee Core/SQLite/Statement.h --- a/Core/SQLite/Statement.h Tue Feb 18 16:18:42 2014 +0100 +++ b/Core/SQLite/Statement.h Tue Feb 18 16:55:10 2014 +0100 @@ -89,10 +89,6 @@ return reference_.GetWrappedObject(); } - // 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 = true); - public: Statement(Connection& database, const std::string& sql); @@ -166,9 +162,12 @@ const void* ColumnBlob(int col) const; bool ColumnBlobAsString(int col, std::string* blob); //bool ColumnBlobAsString16(int col, string16* val) const; - bool ColumnBlobAsVector(int col, std::vector* val) const; - bool ColumnBlobAsVector(int col, std::vector* val) const; + //bool ColumnBlobAsVector(int col, std::vector* val) const; + //bool ColumnBlobAsVector(int col, std::vector* val) const; + // 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 = true); }; } } diff -r 0da078f3affc -r 96a2d2da0fee UnitTestsSources/SQLite.cpp --- a/UnitTestsSources/SQLite.cpp Tue Feb 18 16:18:42 2014 +0100 +++ b/UnitTestsSources/SQLite.cpp Tue Feb 18 16:55:10 2014 +0100 @@ -236,3 +236,66 @@ throw e; } } + + +TEST(SQLite, Types) +{ + SQLite::Connection c; + c.OpenInMemory(); + c.Execute("CREATE TABLE a(id INTEGER PRIMARY KEY, value)"); + + { + SQLite::Statement s(c, std::string("SELECT * FROM a")); + ASSERT_EQ(2, s.ColumnCount()); + ASSERT_FALSE(s.Step()); + } + + { + SQLite::Statement s(c, SQLITE_FROM_HERE, std::string("SELECT * FROM a")); + ASSERT_FALSE(s.Step()); + ASSERT_EQ("SELECT * FROM a", s.GetOriginalSQLStatement()); + } + + { + SQLite::Statement s(c, SQLITE_FROM_HERE, "INSERT INTO a VALUES(NULL, ?);"); + s.BindNull(0); ASSERT_TRUE(s.Run()); s.Reset(); + s.BindBool(0, true); ASSERT_TRUE(s.Run()); s.Reset(); + s.BindInt(0, 42); ASSERT_TRUE(s.Run()); s.Reset(); + s.BindInt64(0, 42ll); ASSERT_TRUE(s.Run()); s.Reset(); + s.BindDouble(0, 42.5); ASSERT_TRUE(s.Run()); s.Reset(); + s.BindCString(0, "Hello"); ASSERT_TRUE(s.Run()); s.Reset(); + s.BindBlob(0, "Hello", 5); ASSERT_TRUE(s.Run()); s.Reset(); + } + + { + SQLite::Statement s(c, SQLITE_FROM_HERE, std::string("SELECT * FROM a")); + ASSERT_TRUE(s.Step()); + ASSERT_EQ(SQLite::COLUMN_TYPE_NULL, s.GetColumnType(1)); + ASSERT_TRUE(s.ColumnIsNull(1)); + ASSERT_TRUE(s.Step()); + ASSERT_EQ(SQLite::COLUMN_TYPE_INTEGER, s.GetColumnType(1)); + ASSERT_TRUE(s.ColumnBool(1)); + ASSERT_TRUE(s.Step()); + ASSERT_EQ(SQLite::COLUMN_TYPE_INTEGER, s.GetColumnType(1)); + ASSERT_EQ(42, s.ColumnInt(1)); + ASSERT_TRUE(s.Step()); + ASSERT_EQ(SQLite::COLUMN_TYPE_INTEGER, s.GetColumnType(1)); + ASSERT_EQ(42ll, s.ColumnInt64(1)); + ASSERT_TRUE(s.Step()); + ASSERT_EQ(SQLite::COLUMN_TYPE_FLOAT, s.GetColumnType(1)); + ASSERT_FLOAT_EQ(42.5, s.ColumnDouble(1)); + ASSERT_TRUE(s.Step()); + ASSERT_EQ(SQLite::COLUMN_TYPE_TEXT, s.GetColumnType(1)); + ASSERT_EQ("Hello", s.ColumnString(1)); + ASSERT_TRUE(s.Step()); + ASSERT_EQ(SQLite::COLUMN_TYPE_BLOB, s.GetColumnType(1)); + ASSERT_EQ(5, s.ColumnByteLength(1)); + ASSERT_TRUE(!memcmp("Hello", s.ColumnBlob(1), 5)); + + std::string t; + ASSERT_TRUE(s.ColumnBlobAsString(1, &t)); + ASSERT_EQ("Hello", t); + + ASSERT_FALSE(s.Step()); + } +}