hbfbird: fix TFbQuery:FieldGet() returning a blank DATE in dialect 3 - #413
hbfbird: fix TFbQuery:FieldGet() returning a blank DATE in dialect 3#413kamilprzyb2 wants to merge 1 commit into
Conversation
* contrib/hbfbird/tfirebrd.prg
! fixed TFbQuery:FieldGet() returning an empty date for every DATE
column in SQL dialect 3. FBGetData() formats SQL_TYPE_DATE as
"YYYY-MM-DD ", so the positional slicing picked up the separators
and hb_SToD() rejected the result. Strip them instead, which does
not depend on where they sit
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
It doesn't truncate, but anyway the code looks like it is left halfway during some modifications, i'd expect that someone wanted to get rid of date separators. Is anyone else familiar why all FBGetData() has a blank space suffix, for other SQL data types too? Without digging much, C test-code "pads" to 10 If there is no feedback from others, I will just fix the positionals. |
* contrib/hbfbird/firebird.c
* contrib/hbfbird/tfirebrd.prg
! fix desync between C and .prg source codes when parsing the date.
I'm keeping ISO 8601 date format in case someone uses "raw"
FBGetData() function to dump or pass-trough data to another SQL server.
Reported by Kamil Przybylski in #413 with slightly different fix.
|
Commited slightly different fix, |
|
Thanks for jumping on this so fast!
Yes code quality of this contrib is questionable, to say the least.
I use hbfbird for read-only operations, so I don't have live environment to test it at the moment. I can prepare a dedicated test later. Anyway this PR can be closed now, as the original issue was resolved. |
* contrib/hbfbird/firebird.c
* contrib/hbfbird/tfirebrd.prg
! fix desync between C and .prg source codes when parsing the date.
I'm keeping ISO 8601 date format in case someone uses "raw"
FBGetData() function to dump or pass-trough data to another SQL server.
Reported by Kamil Przybylski in harbour#413 with slightly different fix.
TFbQuery:FieldGet()returns an empty date for every DATE column in SQLdialect 3.
FBGetData()formatsSQL_TYPE_DATEas"YYYY-MM-DD "- the"%04d-%02d-%02d"branch incontrib/hbfbird/firebird.c, then paddedthrough
"%*s "with width 8, which does not truncate a 10-characterstring, so what reaches PRG is 11 characters with a trailing space.
FieldGet()then does:That reads like an attempt to drop the separators, but the offsets are off
by one: for
"2026-09-01 "it builds"2026" + "-0" + "9-"="2026-09-",and
hb_SToD()- strictly positional, expecting a bare"YYYYMMDD"-rejects it. So every DATE column comes back as an empty date.
The positional correction would be
SubStr( result, 6, 2 )andSubStr( result, 9, 2 ). I usedStrTran( AllTrim( result ), "-" )instead so it does not depend on where the separators sit; happy to switch
to the two-offset version if you prefer the smaller diff.
Scope. Dialect 3 only. There a DATE column is
SQL_TYPE_DATE, whichStructConvert()maps to"D"andFieldGet()converts. In dialect 1 aDATE column is really
SQL_TIMESTAMP, mapped to"T", whichFieldGet()has no case for at all and returns as the raw string - untouched by this
change, though arguably its own gap.
SQL_TYPE_TIMEmaps to"C"and islikewise returned as-is.
Evidence, and how I tested it - please read this part. I ran a probe
against Firebird 5.0.4 embedded, printing the raw
FBGetData()output andevaluating the expressions against it:
The caveat: that probe was built against the 3.4 fork, not against core.
contrib/hbfbird/firebird.cis byte-identical between the two trees inthe
SQL_TYPE_DATEbranch, soFBGetData()produces the same string, andI evaluated core's exact expression against that real string rather than
against my reading of it - but I have not run a core build end to end. If
you want that before merging, say so and I will do it.
The 3.4 fork has the same bug by a different route - it passes the raw
string to
hb_SToD()with no stripping at all. Filed there asvszakats/hb#348.
ChangeLog.txtentry included.