xsharp.eu • RDD and DbDate Data Type
Page 1 of 1

RDD and DbDate Data Type

Posted: Mon Jul 19, 2021 10:41 am
by leon-ts
Hi,

When writing a date to a DBF file field from a VO application, the DATE type is used.

Code: Select all

OVERRIDE METHOD PutValue(nFldPos AS INT, oValue AS OBJECT) AS LOGIC
   ...
   SWITCH oField:FieldType
   ...
   CASE DbFieldType.Date
	// DATE
	LOCAL dDate := (DATE)oValue AS DATE
        ...

The opposite is also true, reading the date from the DBF file returns us the DATE type packed into the USUAL type. But I noticed that inside X# RDD dates are treated as DbDate type. Then, when reading the field value, for example, with the VoDbFieldGet function, the value is returned through the USUAL type, where it is converted from DbDate type to the DATE type.

I have an RDD (SQL) in which I use the DATE type directly when working with dates (sample code above). Since the date value comes from the application to the IRDD:PutValue method as a DATE type (packed in OBJECT). But there was a problem with the TransRec method (default implementation from the base class Workarea). In the TransRec method, values ​​are directly retrieved from the source RDD (GetValue method) and written to the target RDD (PutValue method), bypassing the packaging into the USUAL type. Thus, the date value comes into my RDD from DBFCDX RDD as a DbDate type. When I try to explicitly convert oValue (AS OBJECT) to DATE, an error occurs that this convertion is invalid.

What is the correct way to perceive this problem? In X#, the implicit or at least explicit convertion of the DbDate type to the DATE type is missing, or I need to take into account in my RDD that date values in the PutValue method can come not only as a DATE type, but also as a DbDate type, and the DbDate type cannot be converted to DATE type.

I think X# lacks the convertion of the related types DbDate and DATE. For example, DateTime can be converted to DATE.

Best regards,
Leonid

RDD and DbDate Data Type

Posted: Mon Jul 19, 2021 11:57 am
by robert
Leonid,
Because of the way we structured the runtime we cannot refer to the DATE type inside the RDD system.
We have therefore designed the IDate (and IFloat) interfaces inside XSharp.Core.
DbDate (and DbFloat) are implementations of these interfaces.
There is a DATE constructor that accepts an IDate and the DATE type implements IDate.
In the same way there is a FLOAT constructor that accepts an IFloat and float implements IFloat.
The Object -> USUAL conversion code inside the usual type detects that the object is an IDate or an IFloat and correctly interprets these types.

I am not sure that I understand what you are missing.
My advise would be that inside your RDD system in the PutValue() you check for IDate and IFloat and then GetValue() returns a DbDate or a DbFloat, or an object of a type that you create yourself that implements IDate and/or IFloat.

Robert

RDD and DbDate Data Type

Posted: Mon Jul 19, 2021 12:09 pm
by leon-ts
robert wrote: I am not sure that I understand what you are missing.
Robert,
A simple convertion between DbDate and DATE is missing (in my opinion).
For example, there is such a cast between DateTime and DATE:

Code: Select all

LOCAL oDateTime AS DateTime
oDateTime := DateTime{ 2021, 07, 19 }
LOCAL oDbDate AS XSharp.RDD.DbDate
oDbDate := XSharp.RDD.DbDate{ 2021, 07, 19 }

LOCAL dDate AS DATE
dDate := (DATE)oDateTime // Compiles without errors
dDate := (DATE)oDbDate // Compiler error: XS0030 Cannot convert type 'XSharp.RDD.DbDate' to 'DATE'
Best regards,
Leonid

RDD and DbDate Data Type

Posted: Mon Jul 19, 2021 2:50 pm
by robert
Leonid,

I'll see what I can do. For now try this:

Code: Select all

LOCAL oDateTime AS DateTime
oDateTime := DateTime{ 2021, 07, 19 }
LOCAL oDbDate AS XSharp.RDD.DbDate
oDbDate := XSharp.RDD.DbDate{ 2021, 07, 19 }

LOCAL dDate AS DATE
dDate := (DATE)oDateTime // Compiles without errors
dDate := (XSharp.IDate) oDbDate 
Robert

RDD and DbDate Data Type

Posted: Mon Jul 19, 2021 4:36 pm
by leon-ts
Robert,

In fact, I need a DateTime type in RDD to send a date to a SQL server. I use the DATE type there only for intermediate calculations. But I decided to replace them with DataTime too. And as I saw, the DbDate type has a Value property that returns a DateTime type. In general, I also worked with my RDD code and just added a check to the PutValue method:

Code: Select all

IF oValue IS XSharp.RDD.DbDate VAR oDbDate
    oDateTime := oDbDate:Value
    ....
As far as I understand, the DbDate type was developed by you for private use in RDD, then I think that you do not need to waste time on my request for type casting. Excuse for troubling.

Best regards,
Leonid