-
-
Notifications
You must be signed in to change notification settings - Fork 731
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
GRDB seems to be treating empty arrays as null when inserting records #448
Comments
Hello @mallman, You definitely found a bug, thank you! Empty arrays are not encoded (the same problem affects empty dictionaries). #449 brings a fix, and the missing tests. It will be soon be merged in GRDB 3.6.0, but I can't announce any release date. Meanwhile, you can use the feature/fixEmptyContainersJSONEncoding branch. |
Hi @groue. Thanks for being so responsive! I've been using a rather simple workaround. I have a special case in my code that runs custom SQL when I want to store an empty array. It's not a big deal but will be nice to eliminate once your bug fix has been merged into a release. As an aside, I've been using GRDB for over a year now and have found it to be rock solid. I think this really is the first and only bug I've encountered. Conversely, I'm continually impressed by how capable it is. In my 15+ years programming, I would have to say that GRDB is easily in the top 5% if not top 1% in my experience in terms of documentation, project direction, execution, dependability and code quality. I don't know how you pull it off. Perhaps you should write a book on the secrets of success in open source development??? 😄 Cheers. |
Wow, thank you very, very much! 😊 I don't know the secret of success, but it looks like I know one secret or two that make the life of fellow developers easier ;-) And I'm glad you already had a workaround. |
#449 has been merged. The fix is now available in the development branch. Let's keep this issue open until the next release. |
The fix has shipped in v3.6.0! Thanks for your report, and your patience, @mallman! |
What did you do?
I created a table named
selectedFolders
with the following schema:This table is intended to have a single row, with
folderIds
a text field consisting of a (possibly empty) JSON-array of integers.I created a struct
(BTW,
FolderRecord.Id
is a type alias forInt64
.)I then ran
What did you expect to happen?
I expected GRDB to run the equivalent of the following SQL statements:
What happened instead?
GRDB (attempted to) run the following SQL:
Subsequently, SQLite rolled-back the transaction because the
insert
violated the non-null constraint on thefolderIds
column. (Although that's incidental to my problem with GRDB's behavior here. The real problem for me is that it isn't inserting'[]'
into thefolderIds
column when the value of theSelectedFoldersRecord.folderIds
property is[]
.)Environment
GRDB flavor(s): (GRDB, GRDBCipher, GRDBCustom?)
GRDB built from source. I think it's linked against macOS SQLite.
GRDB version:
Built from git clone, HEAD detached at v3.5.0
Installation method: (CocoaPods, SPM, manual?)
Manual sub-project of my app
Xcode version:
Version 10.1 (10B61)
Swift version:
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
Platform(s) running GRDB: (iOS, macOS, watchOS?)
macOS
macOS version running Xcode:
Version 10.14.1 (18B75)
Demo Project
I don't have something immediately available. LMK if it would be valuable to you for me to supply you with one.
Thanks for helping out!
The text was updated successfully, but these errors were encountered: