[odb-users] If I want to do case insensetive search do I need to make the case lower myself in a string or can ODB issue an case insensetive lookup?

Rafal Gm grasmanek94 at gmail.com
Wed Jul 10 02:18:48 EDT 2013


I have created a username-to-userid table/class but it seems it doesn't
support case insensetive lookup, which I am thinking : do I need to make
all the strings lowecase myself or does ODB provide a feature?

As for now I have this resolver class:

//resolves user names to user id to load them directy with load<>()
#pragma db object
class user_resolver
{
public:
user_resolver () {}
user_resolver
(std::string nickname, user* User): nickname_(nickname), User_(User){}

user* GetUser () { return User_; }
private:
friend class odb::access;

#pragma db id
std::string nickname_;

//the user which will be loaded from database, table: user
user * User_;
};

and whenever I use this code it works:

//start transaction
user server("server","X",0,0,0,0,0,0,0,0,0);
user_resolver rs("server",&server);
Database::users->persist (server);
Database::users->persist (rs);
//commit

//new scope
//start transaction
user_resolver * temp = Database::users->load<user_resolver>("seRVEr");
if(temp)
{
ServerLog::Printf("server username found and loaded, testing user:");
user * test = temp->GetUser();
test->experience(Rand());
ServerLog::Printf("Set experience to %d",test->experience());
Database::users->update(*test);
delete temp;
//keep user, don't delete
}
//commit

but when I change the first part to this:

user_resolver * temp = Database::users->load<user_resolver>("seRVEr");

it gives me an exception that the object is not persistent. Do I need to
change my class to make all the nickname_ input lower?


More information about the odb-users mailing list