How to know not insert or delete query?
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;
}
}
Re: How to know not insert or delete query?
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.
Re: How to know not insert or delete query?
Thanks for your reply.
But at this point, I can't set any permission to table. I must do check with code.