Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql: allow query on an otherwise inaccesible column?

Tags:

sql

mysql

I have a table with a column that I want to prevent certain users from seeing. I understand that I should be able to do this using a view, i.e. have a view which excludes the particular column, and deny access to the table but allow access to the view (note, users do not need to be able to update the table/view).

I do however want to allow an equality query against the field. Such as:

SELECT * FROM some_table_or_view WHERE hidden_field = 'some_value';

To clarify:

  • it should not be possible to have the hidden_field values be returned in a general query
  • it should be possible to run a query with a constraint (preferably only an equality constraint) on the hidden_field value

Is this possible?

(EDIT: if there's a solution in a dbms other than Mysql, I'd be happy to hear about that, too).

like image 554
davmac Avatar asked Oct 09 '22 02:10

davmac


1 Answers

You can create a stored procedure which would return all the fields you allowed it to return, and then you can pass the hidden_value (filtering criterion) as a parameter.

Forbid your database users accessing the table, but allow them to call stored procedures.

Then of course, you would have to create several stored procedures if you had several types of queries against the table. But at least it solves your problem with the rights.

like image 148
Dmytro Shevchenko Avatar answered Oct 12 '22 21:10

Dmytro Shevchenko