FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour ADO and empty Dates [SOLVED]
Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
ADO and empty Dates [SOLVED]
Posted: Sat May 23, 2015 10:09 AM
Hello,

With ADORDD and Harbour there is a problem with emtpy dates.

When issuing an append blank, putting a ctod('') fails.

Also, FW_DateToSQL( , "D" ) fails too.

As I workarround, I set to date(), but there are some cases I need an emty date().

This is the code:


Code (fw): Select all Collapse
   aStruct := ADOSTRUCT( oRs )


   FOR n := 1 TO LEN( aStruct )
        IF aStruct[ n, 6 ]

            AADD( aCols, aStruct[ n, 1 ] )
            AADD( aVals, HB_DECODE( aStruct[ n, 2 ], 'C', Space( aStruct[ n, 3 ] ), 'D', FW_DateToSQL( , "D" ), 'L', .f., ;
                 'M', "", 'm', "", '+', 0, ;
                 'N', If( aStruct[ n, 3 ] == 0, 0, Val( "0." + Replicate( '0', aStruct[ n, 3 ] ) ) ), ;
                 'T', CTOT( '' ), '' ) )

         ENDIF
    NEXT


         oRs:AddNew( aCols, aVals )
     oRs:Update()


Thank you.
Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: ADO and empty Dates
Posted: Sat May 23, 2015 10:24 AM
FW_DateToSQL() and FW_ValToSQL() are meant to be used while constructing SQL statements.

FW_DateToSQL( CTOD( "" ) ) returns "NULL"

Example usage:
if we want to update a datefield:

Code (fw): Select all Collapse
cSql := "UPDATE MYTABLE SET DOCDT = " + FW_DateToSQL( dDate ) + " WHERE ID = 10"
oCn:Execute( cSql )

Even better
cSql := SQL UPDATE MYTABLE SET DOCDT = dDate WHERE ID - 0

For ado, you may use FW_AdoNull() for updating or inserting empty dates
Regards



G. N. Rao.

Hyderabad, India
Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
Re: ADO and empty Dates
Posted: Sat May 23, 2015 10:54 AM
Mr. Nages,

Thank you very much.

This is working:

Code (fw): Select all Collapse
            AADD( aVals, HB_DECODE( aStruct[ n, 2 ], 'C', Space( aStruct[ n, 3 ] ), 'D', AdoNull(), 'L', .f., ;
                 'M', "", 'm', "", '+', 0, ;
                 'N', If( aStruct[ n, 3 ] == 0, 0, Val( "0." + Replicate( '0', aStruct[ n, 3 ] ) ) ), ;
                 'T', AdoNull(), '' ) )


Best regards,
Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.

Continue the discussion