mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-06 18:56:40 -04:00
Add test for Column std::shared_ptr; remove noexcept from throwing Column constructor
This commit is contained in:
parent
10d779a349
commit
27a32521b7
@ -54,7 +54,7 @@ public:
|
|||||||
* @param[in] aStmtPtr Shared pointer to the prepared SQLite Statement Object.
|
* @param[in] aStmtPtr Shared pointer to the prepared SQLite Statement Object.
|
||||||
* @param[in] aIndex Index of the column in the row of result, starting at 0
|
* @param[in] aIndex Index of the column in the row of result, starting at 0
|
||||||
*/
|
*/
|
||||||
explicit Column(const Statement::TStatementPtr& aStmtPtr, int aIndex) noexcept;
|
explicit Column(const Statement::TStatementPtr& aStmtPtr, int aIndex);
|
||||||
|
|
||||||
// default destructor: the finalization will be done by the destructor of the last shared pointer
|
// default destructor: the finalization will be done by the destructor of the last shared pointer
|
||||||
// default copy constructor and assignment operator are perfectly suited :
|
// default copy constructor and assignment operator are perfectly suited :
|
||||||
|
@ -26,7 +26,7 @@ const int Null = SQLITE_NULL;
|
|||||||
|
|
||||||
|
|
||||||
// Encapsulation of a Column in a row of the result pointed by the prepared Statement.
|
// Encapsulation of a Column in a row of the result pointed by the prepared Statement.
|
||||||
Column::Column(const Statement::TStatementPtr& aStmtPtr, int aIndex) noexcept :
|
Column::Column(const Statement::TStatementPtr& aStmtPtr, int aIndex) :
|
||||||
mStmtPtr(aStmtPtr),
|
mStmtPtr(aStmtPtr),
|
||||||
mIndex(aIndex)
|
mIndex(aIndex)
|
||||||
{
|
{
|
||||||
|
@ -241,3 +241,39 @@ TEST(Column, stream)
|
|||||||
std::string content = ss.str();
|
std::string content = ss.str();
|
||||||
EXPECT_EQ(content, str);
|
EXPECT_EQ(content, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Column, shared_ptr)
|
||||||
|
{
|
||||||
|
// Create a new database
|
||||||
|
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);
|
||||||
|
EXPECT_EQ(0, db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, msg TEXT)"));
|
||||||
|
EXPECT_EQ(1, db.exec(R"(INSERT INTO test VALUES (42, "fortytwo"))"));
|
||||||
|
const char* query_str = "SELECT id, msg FROM test";
|
||||||
|
|
||||||
|
std::unique_ptr<SQLite::Statement> query{ new SQLite::Statement(db, query_str) };
|
||||||
|
query->executeStep();
|
||||||
|
|
||||||
|
auto column0 = query->getColumn(0);
|
||||||
|
auto column1 = query->getColumn(1);
|
||||||
|
query.reset();
|
||||||
|
|
||||||
|
EXPECT_EQ(42, column0.getInt());
|
||||||
|
EXPECT_STREQ("fortytwo", column1.getText());
|
||||||
|
|
||||||
|
query.reset(new SQLite::Statement(db, query_str));
|
||||||
|
query->executeStep();
|
||||||
|
column0 = query->getColumn(0);
|
||||||
|
EXPECT_EQ(true, column0.isInteger());
|
||||||
|
query->executeStep(); // query is done
|
||||||
|
|
||||||
|
// Undefined behavior
|
||||||
|
// auto x = column0.getInt();
|
||||||
|
|
||||||
|
query.reset();
|
||||||
|
|
||||||
|
// Undefined behavior
|
||||||
|
// auto x = column0.getInt();
|
||||||
|
// bool isInt = column0.isInteger();
|
||||||
|
|
||||||
|
EXPECT_STREQ("id", column0.getName());
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user