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

Expose SqliteError::new #3235

Open
ColonelThirtyTwo opened this issue May 17, 2024 · 3 comments
Open

Expose SqliteError::new #3235

ColonelThirtyTwo opened this issue May 17, 2024 · 3 comments
Labels
db:sqlite Related to SQLite enhancement New feature or request

Comments

@ColonelThirtyTwo
Copy link

Is your feature request related to a problem? Please describe.
SqliteError has a new function that takes a C handle and generates an error using sqlite3_extended_errcode and sqlite3_errmsg, but it's crate-private. This function would be convenient for anyone working with the C API, for example in SqlitePoolOptions::after_connect to register a custom SQLite function, so that they don't have to write sqlx::Error-compatible error handle themselves.

Describe the solution you'd like
Change SqliteError::new to pub and add unsafe to it (it technically should be unsafe even if crate-private since it requires the passed in handle to be valid).

Describe alternatives you've considered
Writing my own boilerplate to get the error code and message myself. But it's boilerplate.

Additional context
N/A

@ColonelThirtyTwo ColonelThirtyTwo added the enhancement New feature or request label May 17, 2024
@abonander
Copy link
Collaborator

I agree with adding unsafe, but instead of exposing a constructor for SqliteError, why not add last_error(&mut self) -> Option<SqliteError> to LockedSqliteHandle?

@abonander abonander added the db:sqlite Related to SQLite label Jul 26, 2024
@ColonelThirtyTwo
Copy link
Author

LockedSqliteHandle::last_error could work as well. Only reason I can think of for SqliteError::new instead would be if you had a sqlite3_handle but not the LockedSqliteHandle that it came from, and I'm not sure if that's an issue.

@abonander
Copy link
Collaborator

Only reason I can think of for SqliteError::new instead would be if you had a sqlite3_handle but not the LockedSqliteHandle that it came from, and I'm not sure if that's an issue.

I mean, if you think there's a real use for it, but my gut says "YAGNI".

Would you be interested in opening a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
db:sqlite Related to SQLite enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants