PDA

View Full Version : How to know not insert or delete query?



ramazangirgin
29th June 2010, 07:58
How to know is query string is only select query , not insert or delete query ?

I want to write function like that in my library. Is there any way it is SELECT query and not contains any insert,update or delete statements ?

Thanks in advance
Ramazan

My code will like this:

QList<T> executeCustomSelectQuery(const QString & iSelectQuery)
{
QList<T> retList;
QSqlQuery query(iSelectQuery);
if(isSelectQuery)//I dont know how to know is SELECT query and not contains any insert,update or //delete (One way may be seach in input query string but i don't know it is safe)
{
while ( query.next() )
{
T value= query.value(0).getValue<T>();
retList<<value;
}
}
return retList;
}



}

boudie
29th June 2010, 10:45
You should set the permissions on your database so that insert/delete/update can only be done by people who are granted those rights.
Do not mess up your code with difficult and un-save checks.

Bonus: That way you only have to deal with security at one place.

ramazangirgin
29th June 2010, 13:43
Thanks for your reply.

But at this point, I can't set any permission to table. I must do check with code.