Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating empty constructor for rowset #1086

Closed
wants to merge 4 commits into from
Closed

Conversation

cstiborg
Copy link
Contributor

This PR allows the creation of an empty rowset as per #1057

Copy link
Member

@vadz vadz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a test creating an empty rowset and using it in some trivial way, e.g.

CHECK( empty.begin() == empty.end() );

? It really bothers me that the previous problem wasn't detected.

TIA!

@cstiborg
Copy link
Contributor Author

cstiborg commented Oct 11, 2023

I will add a test.

Regarding the "Previous problem" - I didn't catch a problem. I have tested both the previous code and this version using the test code below which might not be short and sweet, but at least to me it proves that it works. In both cases it compiled and executed as expected - I have it in a docker container, if you want to see it for yourself.

#include <soci/soci.h>
#include <string>
#include <iostream>

class Test {
public:
	Test(soci::session& session): session(session) {
	}

 	void buildIt() {
		session << "delete from soci_test";
		for (int i = 0; i < 5; i++) {
			session << "insert into soci_test (a) values (" << i << ")";
		}
		rowset = (session.prepare << "select * from soci_test");
		readRow = rowset.begin();
	}

	bool handleRow() {
		if (readRow != rowset.end()) {
			std::cout << "Got row" << std::endl;
			++readRow;
		}
		return readRow != rowset.end();
	}

private:
	soci::session& session;
	soci::rowset<soci::row> rowset;
	soci::rowset<soci::row>::const_iterator readRow;
};

int
main(int argc, char *argv[]) {
	soci::session postgresql("postgresql", "user=soci host=127.0.0.1 dbname=postgres password=abcd1234");
	soci::session mysql("mysql", "user=soci host=127.0.0.1 dbname=soci password=abcd1234");

	Test pgTest(postgresql);
	Test myTest(mysql);
	if (pgTest.handleRow()) std::cout << "PG Row holds data" << std::endl;
	if (myTest.handleRow()) std::cout << "MY Row holds data" << std::endl;
	pgTest.buildIt();
	myTest.buildIt();
	while (pgTest.handleRow()) {}
	while (myTest.handleRow()) {}

	return 0;
}

@cstiborg
Copy link
Contributor Author

Is it possible to re-run the tests? - Something went wrong when fetching from a Ubuntu repo...

@vadz
Copy link
Member

vadz commented Oct 11, 2023

Thanks, should I merge this or will you add clear() to this PR too?

@cstiborg
Copy link
Contributor Author

I've just tested and added it - now waiting for the automated tests to succeed.

@cstiborg
Copy link
Contributor Author

I forgot about the test, sorry - I've added it now.

@vadz
Copy link
Member

vadz commented Oct 19, 2023

Thanks again for you work! I'll merge it in a moment.

@vadz vadz closed this in 9bcc5f8 Oct 19, 2023
@cstiborg cstiborg deleted the soci-1057 branch July 19, 2024 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants