Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int Column::getBytes() const noexcept // nothrow
// Standard std::ostream inserter
std::ostream& operator<<(std::ostream& aStream, const Column& aColumn)
{
aStream << aColumn.getText();
aStream.write(aColumn.getText(), aColumn.getBytes());
return aStream;
}

Expand Down
23 changes: 23 additions & 0 deletions tests/Column_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,26 @@ TEST(Column, getName) {
EXPECT_EQ("msg", oname1);
#endif
}

TEST(Column, stream) {
// Create a new database
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);
EXPECT_EQ(0, db.exec("CREATE TABLE test (msg TEXT)"));
SQLite::Statement insert(db, "INSERT INTO test VALUES (?)");

// content to test
const char str_[] = "stringwith\0embedded";
std::string str(str_, sizeof(str_)-1);

insert.bind(1, str);
// Execute the one-step query to insert the row
EXPECT_EQ(1, insert.exec());
EXPECT_EQ(1, db.getTotalChanges());

SQLite::Statement query(db, "SELECT * FROM test");
query.executeStep();
std::stringstream ss;
ss << query.getColumn(0);
std::string content = ss.str();
EXPECT_EQ(content, str);
}