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

Problem with multi where condition #384

Closed
asgene opened this issue Sep 25, 2019 · 4 comments
Closed

Problem with multi where condition #384

asgene opened this issue Sep 25, 2019 · 4 comments
Labels

Comments

@asgene
Copy link

asgene commented Sep 25, 2019

I Found a problem in test.cpp according to #272
Visual Studio 2017

struct User {
		int id = 0;
		int age;
		std::string name;
	};
	auto storage = make_storage("test.db",
		make_table("users",
			make_column("id", &User::id, primary_key()),
			make_column("age", &User::age),
			make_column("name", &User::name)));
	storage.sync_schema();

	storage.replace(User{ 1, 15, "Jeremy" });
	storage.replace(User{ 2, 16, "Nataly" });
	storage.replace(User{ 3, 17, "Nataly" });
	storage.replace(User{ 4, 18, "Nataly" });
	storage.replace(User{ 5, 18, "Nataly" });

	auto users = storage.get_all<User>();
	cout << "users.size = 5 " << users.size() << endl;

	auto users6 = storage.get_all<User>(
		where(
			(false or c(&User::id) == 4)  and
			(false or c(&User::age) == 18)
			));

	cout << "users.size = 1 " << users6.size() << endl;
	for (auto &user : users6) {
		cout << storage.dump(user) << endl;
	}

The output is:

users.size = 5 5
users.size = 1 2
{ id : '4', age : '18', name : 'Nataly' }
{ id : '5', age : '18', name : 'Nataly' }

It seems that the SQL where clause is:

WHERE ( ? OR 'users'."id" = ? AND ? OR 'users'."age" = ?)

but the correct should be:

WHERE ( (? OR 'users'."id" = ?) and (? or 'users'."age" = ?) )

Any advice? Thank you.

@fnc12
Copy link
Owner

fnc12 commented Sep 25, 2019

Thanks. I shall inspect it soon

@fnc12 fnc12 added the bug label Sep 26, 2019
@fnc12
Copy link
Owner

fnc12 commented Sep 26, 2019

Fix is on it's way #385
Thank you

@fnc12
Copy link
Owner

fnc12 commented Sep 26, 2019

Fixed in #385 . Please check it out

@asgene
Copy link
Author

asgene commented Sep 27, 2019

Works great, thanks!

@asgene asgene closed this as completed Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants