Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setAuthorizer to Pdo\Sqlite #17321

Open
stancl opened this issue Jan 2, 2025 · 2 comments · May be fixed by #17905
Open

Add setAuthorizer to Pdo\Sqlite #17321

stancl opened this issue Jan 2, 2025 · 2 comments · May be fixed by #17905

Comments

@stancl
Copy link

stancl commented Jan 2, 2025

Description

Since we now have separate classes for different PDO types, could we get Pdo\Sqlite::setAuthorizer()?

The SQLite3 extension supports it: https://www.php.net/manual/en/sqlite3.setauthorizer.php

The C interface is pretty straightforward: https://www.sqlite.org/c3ref/set_authorizer.html, you get the action as an int, some string parameters, and return one of these values:

The authorizer callback should return SQLITE_OK to allow the action, SQLITE_IGNORE to disallow the specific action but allow the SQL statement to continue to be compiled, or SQLITE_DENY to cause the entire SQL statement to be rejected with an error

The SQLite3 extension's setAuthorizer() has a bool return type so I'm assuming it's SQLITE_OK and SQLITE_DENY, since SQLITE_IGNORE probably has pretty niche use cases.

@cmb69
Copy link
Member

cmb69 commented Jan 2, 2025

If I remember correctly, the only hurdle to also have this for PDO_Sqlite was indeed the lack of driver specific subclasses. Since that has changed, I think this is a reasonbable feature request. PR welcome!

@stancl
Copy link
Author

stancl commented Jan 4, 2025

For some context, I had a use case where setting the authorizer would be helpful in a package I maintain. For now I went with bundling compiled dll/so/dylib files with the composer package. This feature would simplify that a lot.

Also, one thing I was trying to do before resorting to bundling compiled libraries with my package was seeing if I could use FFI to achieve this. I'm not sure if this is something you'd want, but imo it'd be very helpful if Pdo\Sqlite also exposed the sqlite3* pointer as FFI\CData.

Then you could just use FFI to do these things at the application level. libsqlite3 has pretty simple headers so I think it's a good fit for FFI.

One way to do this now is to load a SQLite extension which creates a function that returns the pointer as a u64, which then lets you do whatever you want using FFI, but the downside is you still need the actual compiled extension to create the function.

@nielsdos nielsdos self-assigned this Feb 23, 2025
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 23, 2025
@nielsdos nielsdos linked a pull request Feb 23, 2025 that will close this issue
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 23, 2025
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment