Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute query only if it is select statement. How?

string sqlQuery = "unknown";

I need to write a function which receives a sql query as parameter e.g. sqlQuery. I would like to execute it only if it is select statement and return data. In other case, if parameter sqlQuery contains delete, update or truncate, the function should return null.

I wonder if there is way to achieve this without parsing contents of parameter sqlQuery. I would like to do this using c sharp for oracle queries.

Any tips. Thanks.

Update:

  1. This should work for all kinds of users with all privileges.
like image 464
Saar Avatar asked Sep 08 '26 02:09

Saar


1 Answers

Run the query in the context of a user who only has select privileges. Any other type of query will error out.

like image 146
Seva Alekseyev Avatar answered Sep 10 '26 15:09

Seva Alekseyev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!