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

Show numeric code instead of UNKNOWN_ERROR #689

Merged
merged 5 commits into from Aug 3, 2022

Conversation

mdavidsaver
Copy link
Contributor

Helps in interpreting extended error codes which aren't included in the current SQLiteErrorCode.

In my case, allowed me to discover that

... org.sqlite.SQLiteException: [UNKNOWN_ERROR] unknown error (attempt to write a readonly database)

was really

... org.sqlite.SQLiteException: 0x608 (attempt to write a readonly database)

aka. SQLITE_READONLY_DIRECTORY because while my DB file was writable, the directory was not...

@gotson
Copy link
Collaborator

gotson commented Jul 28, 2022

@mdavidsaver can you check the failing CI?

@gotson
Copy link
Collaborator

gotson commented Jul 28, 2022

Seems formatting only, you can use the Spotless plugin: mvn spotless:check and mvn spotless:apply

@mdavidsaver
Copy link
Contributor Author

Seems formatting only, you can use the Spotless plugin: mvn spotless:check and mvn spotless:apply

Done.

@gotson
Copy link
Collaborator

gotson commented Jul 29, 2022

I have 2 questions:

  1. why display the code as 0x608 while the SQLite website display them as decimal, like 1544 ?
  2. could we also include more error codes in SQLiteErrorCode ?

@gotson gotson added the waiting for feedback Waiting for a feedback from the issue creator label Jul 29, 2022
@mdavidsaver
Copy link
Contributor Author

fyi. this small PR came about while troubleshooting an afternoon project ~9 months ago. I'd like to help others avoid some frustration, but there are limits to the time I can spend on it. If there are some quick changes I can make to get this merged, then please state this clearly. I'm not going to be offended. Likewise if someone would like to take this PR and go further, or do something different.

  1. I think I looked at the C headers. These are defined as two decimal numbers, combined with or+shift, which is kind of confusing.
$ grep SQLITE_READONLY /usr/include/sqlite3.h
#define SQLITE_READONLY     8   /* Attempt to write a readonly database */
...
#define SQLITE_READONLY_DIRECTORY      (SQLITE_READONLY | (6<<8))
  1. Sure.

As a further idea. I also noticed const char *sqlite3_errstr(int), which seems more future proof than maintaining a duplicate of the error string table. However, I'm personally not keen to wade into JNI again.

@gotson
Copy link
Collaborator

gotson commented Aug 2, 2022

I think your PR has value, and i approach it with external eyes, hopefully we can make it beneficial for everyone.

I think the error code displayed will make more sense if it can be looked up using the SQLite webpage.

As a further idea. I also noticed const char *sqlite3_errstr(int), which seems more future proof than maintaining a duplicate of the error string table. However, I'm personally not keen to wade into JNI again.

I think having the enums in Java make sense, as it can be used within the code to perform various conditions and checks. I also agree with you, we shouldn't touch JNI more than necessary 😅


I will try to update your PR to display decimal codes, and i will try to include the missing codes too.

@gotson gotson added enhancement needs rework and removed waiting for feedback Waiting for a feedback from the issue creator labels Aug 2, 2022
@gotson gotson self-assigned this Aug 2, 2022
@gotson gotson marked this pull request as draft August 2, 2022 07:41
@gotson gotson marked this pull request as ready for review August 3, 2022 07:14
@gotson gotson merged commit bb84601 into xerial:master Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants