go-sqlite3
go-sqlite3 copied to clipboard
added ability for callbacks to have time.Time as arguments
go-sqlite3 can store time.Time values, and also has the fetaure to register callback function to provide additionaly functions.
However these callback cannot take the mentioned time.Time columns as input as there is no "dynamic-casting" of these values from TEXT to time.Time.
With this patch that become possible letting user write custom functions to do fancy filtering these time.Time columns
If the features is acceptable then if required I will add tests
please add test.
I have added tests. but I dont understand why the callbacks are failing for struct{}
Coverage decreased (-0.6%) to 57.348% when pulling 3d52bcbd4e40a903f720860339e2d2fd6b749717 on sum12:timecallback into 3aefd9f0a162514f66d0e4ceda3edc44e66b502e on mattn:master.
Coverage decreased (-0.7%) to 57.657% when pulling 7791e15be137ea5e584c061ba3ee85f4642a6096 on sum12:timecallback into 31f5bb843b7852e28d5a66d1d539c042c3bb623a on mattn:master.
okay that should do it. Let me know what you think
Any reviews on this one ?
Seems good to me. cc @GJRTimmer
thanks for fixing travis, I have dropped the commit from the PR.
@GJRTimmer do you have any more reviews?
In recent changes, time.Time can be passed correctly. So IMO, this hack is not required. @sum12 Do you think?
Could you please point me to the commit that added this functionality? I looked at callback.go and it doesnot have it.
Or may be you could help me convert this hack to something that is not a hack ?
@sum12 I do have a few comments on your changes.
- Please use
errors.New
overfmt.Errorf
if there are no format verbs (like%v
). - Please remove "an" from the error message.
- Please use
C.GoStringN
to account for embedded null bytes. - If the input fails to parse to a
time.Time
, you aren't actually returning an error. Is that the intended behavior? It seems inconsistent to complain about it not being TEXT, but to be fine with it not being an actual time string. - What if the input is an integer or float? It could be reasonable to interpret it as a Julian day or Unix timestamp. https://www.sqlite.org/lang_datefunc.html
- What about blobs? Elsewhere this library tries to treat blobs and strings equivalently. (See
callbackArgString
.)
@sum12 I do have a few comments on your changes.
1. Please use `errors.New` over `fmt.Errorf` if there are no format verbs (like `%v`).
done
2. Please remove "an" from the error message.
hrm, done.
3. Please use `C.GoStringN` to account for embedded null bytes.
this one was good for learning, thanks.
4. If the input fails to parse to a `time.Time`, you aren't actually returning an error. Is that the intended behavior? It seems inconsistent to complain about it not being TEXT, but to be fine with it not being an actual time string.
make sense, corrected.
5. What if the input is an integer or float? It could be reasonable to interpret it as a Julian day or Unix timestamp. https://www.sqlite.org/lang_datefunc.html
the library does not recognize the other formats, only SQLiteTimestampFormats
are recognized.
I would love to add support for other formats, but in a different PR, after this.
6. What about blobs? Elsewhere this library tries to treat blobs and strings equivalently. (See `callbackArgString`.)
Accepted and corrected
Thanks for reviews, however I am still learning Go. Do you see anything else not in line ? may be @mattn or @GJRTimmer ?
@rittneje This is acceptable?