Structure a table Groups:
@TABLE Groups (name VARCHAR(30) PRIMARY KEY, creator VARCHAR(30),exhibitors TEXT, files TEXT, password VARCHAR(20))@
New situation with sql query has arrived.
Here is a code:
@
QString MyServer::getListOfContact(QString name)
{
QSqlQuery query;
query.exec("SELECT listOfUsers FROM users WHERE login='"+name+"'");
// if(query.isActive()&&query.isValid())
// {
QString listOfContact;
while(query.next())
listOfContact=query.value(0).toString();
QStringList l=listOfContact.split(",");
listOfContact.clear();
for(int i=0;i<l.count();i++)
if(l.at(i)=="NULL")
l.removeAt(i);
for(int i=0;i<l.count();i++)
listOfContact+=l.at(i)+",";
listOfContact.remove(listOfContact.size()-1,1);
query.clear();
return listOfContact;
// }
// else
// {
// qDebug()<<query.isValid();
// qDebug()<<query.lastError();
// }
}
@
I belive issue is a similar to the previous. When program using this method in a first time, it's fine, exept check the validity. My consideration about follow below.
After what, when program using this procedure again, AND VARIABLE name HAS A SAME VALUE, query is empty. There no calls to database, between first and last query. What it can be?
Now about check for validity. Here is one of procedure of adding new element to table:
@
QString nameOfCreator;
QString nameOfTheGroup;
QString listOfTheGroupExhibitors;
QString passwordOfTheNewGroup;
QStringList listOfAlreadyExistingGroups;
/////////////////////////////
if(!listOfAlreadyExistingGroups.contains(nameOfTheGroup))
{
query.exec("INSERT INTO Groups(name, creator, exhibitors, files, password)" "VALUES(:name,:creator,:exhibitors,:files,:password)");
query.bindValue(":name",nameOfTheGroup);
query.bindValue(":creator",nameOfCreator);
query.bindValue(":exhibitors",listOfTheGroupExhibitors);
query.bindValue(":files",NULL);
query.bindValue(":password",NULL);
@
Not a single query does not pass for validity, but i don't understand why. I already try create table with TEXT fileds - result is a same: query is not valid and lastError return @QSqlError(-1, "", "")@. It's more than just a strange, because database open correctly and first query was execute file. I'm stuck.
Many thanks in advance.