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

UUID Fix #1112

Merged
merged 4 commits into from
Feb 22, 2022
Merged

UUID Fix #1112

merged 4 commits into from
Feb 22, 2022

Conversation

benrlewis7450G
Copy link
Contributor

@benrlewis7450G benrlewis7450G commented Feb 18, 2022

Inserting a UUID as Expression<UUID> resulted in escaped quotes on either side of the uuidString and thus actual quotes stored inside the DB. When retrieving a row, the result of UUID(uudiString:) returns null when a uuidString with quotes on either side is given.
This appears to be an issue with JSONEncoder.
Fix pre-empts JSONEncoder and inserts a proper uuidString without escaped quotes on either side.

@benrlewis7450G
Copy link
Contributor Author

benrlewis7450G commented Feb 18, 2022

Upon further investigating I found this was only an issue when I was inserting Codables. I have duplicated the issue by inserting a Codable and then querying the table for the UUID - it won't find it because it will compare an unwrapped UUID to one wrapped in quotes.

@jberkel
Copy link
Collaborator

jberkel commented Feb 21, 2022

Thanks for the PR. Looks like there are still some linting errors.

@benrlewis7450G
Copy link
Contributor Author

benrlewis7450G commented Feb 21, 2022 via email

@jberkel
Copy link
Collaborator

jberkel commented Feb 21, 2022

Install swiftlint ($ brew install swiftlint) or see https://github.com/realm/SwiftLint, then do

$ make lint

@@ -207,6 +207,8 @@ private class SQLiteEncoder: Encoder {
encoder.setters.append(Expression(key.stringValue) <- data)
} else if let date = value as? Date {
encoder.setters.append(Expression(key.stringValue) <- date.datatypeValue)
} else if let uuid = value as? UUID {
encoder.setters.append(Expression(key.stringValue) <- uuid.uuidString)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<- uuid.datatypeValue

} else {
XCTFail("Search for uuid failed")
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tests should be in QueryTests.swift. Look for test_insert_encodable

@jberkel jberkel merged commit 0ecc452 into stephencelis:master Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants