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
4 changes: 2 additions & 2 deletions dev/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -2832,13 +2832,13 @@ namespace sqlite_orm {
using columns_type = typename decltype(impl->table)::columns_type;
using head_t = typename std::tuple_element<0, columns_type>::type;
using indexed_type = typename internal::table_type<head_t>::type;
ss << "INDEX IF NOT EXISTS " << impl->table.name << " ON '" << this->impl.template find_table_name<indexed_type>() << "' ( ";
ss << "INDEX IF NOT EXISTS '" << impl->table.name << "' ON '" << this->impl.template find_table_name<indexed_type>() << "' ( ";
std::vector<std::string> columnNames;
tuple_helper::iterator<std::tuple_size<columns_type>::value - 1, Cols...>()(impl->table.columns, [&columnNames, this](auto &v){
columnNames.push_back(this->impl.column_name(v));
});
for(size_t i = 0; i < columnNames.size(); ++i) {
ss << columnNames[i];
ss << "'" << columnNames[i] << "'";
if(i < columnNames.size() - 1) {
ss << ",";
}
Expand Down
2 changes: 1 addition & 1 deletion examples/exists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ int main(int argc, char **argv) {
// (SELECT *
// FROM customer
// WHERE grade=3 AND agents.agent_code=customer.agent_code)
// ORDER BY commission;
// ORDER BY commission;
auto rows = storage.select(columns(&Agent::code, &Agent::name, &Agent::workingArea, &Agent::comission),
where(exists(select(asterisk<Customer>(),
where(is_equal(&Customer::grade, 3) and is_equal(&Agent::code, &Customer::agentCode))))),
Expand Down
4 changes: 2 additions & 2 deletions include/sqlite_orm/sqlite_orm.h
Original file line number Diff line number Diff line change
Expand Up @@ -8838,13 +8838,13 @@ namespace sqlite_orm {
using columns_type = typename decltype(impl->table)::columns_type;
using head_t = typename std::tuple_element<0, columns_type>::type;
using indexed_type = typename internal::table_type<head_t>::type;
ss << "INDEX IF NOT EXISTS " << impl->table.name << " ON '" << this->impl.template find_table_name<indexed_type>() << "' ( ";
ss << "INDEX IF NOT EXISTS '" << impl->table.name << "' ON '" << this->impl.template find_table_name<indexed_type>() << "' ( ";
std::vector<std::string> columnNames;
tuple_helper::iterator<std::tuple_size<columns_type>::value - 1, Cols...>()(impl->table.columns, [&columnNames, this](auto &v){
columnNames.push_back(this->impl.column_name(v));
});
for(size_t i = 0; i < columnNames.size(); ++i) {
ss << columnNames[i];
ss << "'" << columnNames[i] << "'";
if(i < columnNames.size() - 1) {
ss << ",";
}
Expand Down
78 changes: 58 additions & 20 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,53 @@ void testThreadsafe() {

void testIn() {
cout << __func__ << endl;

struct User {
int id;
};

auto storage = make_storage("",
make_table("users",
make_column("id", &User::id, primary_key())));
storage.sync_schema();
storage.replace(User{ 1 });
storage.replace(User{ 2 });
storage.replace(User{ 3 });

{
auto rows = storage.get_all<User>(where(in(&User::id, {1, 2, 3})));
assert(rows.size() == 3);
struct User {
int id;
};

auto storage = make_storage("",
make_table("users",
make_column("id", &User::id, primary_key())));
storage.sync_schema();
storage.replace(User{ 1 });
storage.replace(User{ 2 });
storage.replace(User{ 3 });

{
auto rows = storage.get_all<User>(where(in(&User::id, {1, 2, 3})));
assert(rows.size() == 3);
}
{
std::vector<int> inArgument;
inArgument.push_back(1);
inArgument.push_back(2);
inArgument.push_back(3);
auto rows = storage.get_all<User>(where(in(&User::id, inArgument)));
assert(rows.size() == 3);
}
}
{
std::vector<int> inArgument;
inArgument.push_back(1);
inArgument.push_back(2);
inArgument.push_back(3);
auto rows = storage.get_all<User>(where(in(&User::id, inArgument)));
struct Letter {
int id;
std::string name;
};
auto storage = make_storage("",
make_table("letters",
make_column("id", &Letter::id, primary_key()),
make_column("name", &Letter::name)));
storage.sync_schema();

storage.replace(Letter{1, "A"});
storage.replace(Letter{2, "B"});
storage.replace(Letter{3, "C"});

auto letters = storage.get_all<Letter>(where(in(&Letter::id, {1, 2, 3})));
assert(letters.size() == 3);
auto rows = storage.select(columns(&Letter::name), where(in(&Letter::id, {1, 2, 3})));
assert(rows.size() == 3);
auto rows2 = storage.select(&Letter::name, where(in(&Letter::id, {1, 2, 3})));
assert(rows2.size() == 3);
}
}

Expand Down Expand Up @@ -2205,6 +2228,19 @@ void testRowId() {
}
}

void testEscapedIndexName() {
cout << __func__ << endl;

struct User{
std::string group;
};
auto storage = make_storage("index_group.sqlite",
make_index("index", &User::group),
make_table("users",
make_column("group", &User::group)));
storage.sync_schema();
}

int main(int argc, char **argv) {

cout << "version = " << make_storage("").libversion() << endl;
Expand Down Expand Up @@ -2286,4 +2322,6 @@ int main(int argc, char **argv) {
testIn();

testJournalMode();

testEscapedIndexName();
}