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

Hbpgsql length timestamp field #236

Open
marcoprodata opened this issue Apr 1, 2021 · 2 comments
Open

Hbpgsql length timestamp field #236

marcoprodata opened this issue Apr 1, 2021 · 2 comments

Comments

@marcoprodata
Copy link
Contributor

In function tableStruct timestamp fields are converted in char with length 20, but sometimes the timestamp fields are filled with more char, ex: "2021-02-01 12:53:59.555394"

@alcz
Copy link
Contributor

alcz commented Apr 2, 2021

Knowledge gathering: there is also timestamp with timezone type in Postgres, which is even longer in representation.

Another wrapper we have https://github.com/harbour/core/blob/master/contrib/sddpg/core.c
declares lengths for this as follows:

 case TIMESTAMPOID:
            dbFieldInfo.uiType = HB_FT_STRING;
            dbFieldInfo.uiLen  = 23;
            break;

 case TIMESTAMPTZOID:
            dbFieldInfo.uiType = HB_FT_STRING;
            dbFieldInfo.uiLen  = 26;
            break;

It's a bit to low to represent them as strings, but if the date/time separators are stripped, it could fit.
The best would be to reuse Harbour's timestamp type, but if it's done for timestamp with timezone too... the timezone information be lost(?)

@marcoprodata
Copy link
Contributor Author

marcoprodata commented Apr 3, 2021

In harbour user list a user suggested to implement timestamp in hbpgsql:

METHOD Refresh( lQuery, lMeta ) CLASS TPQquery
...
   CASE "timestamp" $ cType
       cType := "T" // "C"
       nSize := 20
...

same in:
METHOD TableStruct( cTable ) CLASS TPQserver

in:
METHOD FieldGet( nField, nRow ) CLASS TPQquery
...
        elseif cType == "T"
            if ! ISNIL(result)
                result:= strtran( result, "-", "" )
                result:= strtran( result, ":", "" )
                result:= strtran( result, " ", "" )
                result := StoT( result )
            else
               IF !lReturnNil
                  result := StoT('')
               ENDIF
            end

in:
Static Function DataToSql(xField)
...
        elseif cType == "T"
                   result := "'"+TRAN(ttos( xField),"@R 9999-99-99 99:99:99")+"'"

and:
Static Function ValueToString(xField)
        elseif cType == "T"
                IF !EMPTY(xField)
                   result := ttos( xField )
                ENDIF

//-----------------
Function DtoQ(cData)
Return "'" + Str(Year(cData),4) + "-" + StrZero(Month(cData), 2) + "-" + StrZero(Day(cData), 2) + "'"

//------------------
Function StoQ(cData)
Return "'" + ALLTRIM(cData) + "'"

//------------------
Function TtoQ(cData)
Return "'" + Str(Year(cData),4) + "-" + StrZero(Month(cData), 2) + "-" + StrZero(Day(cData), 2) +;
       ' ' + HB_NTOS(HB_HOUR(cData)) + ':' + HB_NTOS(HB_MINUTE(cData)) + ':' + HB_NTOS(HB_SEC(cData)) + "'"

its possible to implement this?

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

No branches or pull requests

2 participants