HASH to File and File to HASH

HASH to File and File to HASH

Postby Otto » Thu Nov 24, 2022 7:21 am

Hello friends,
Is there a Harbour function to save a HASH to a file and then read it back in.

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: HASH to File and File to HASH

Postby Antonio Linares » Thu Nov 24, 2022 7:30 am

Dear Otto,

good morning

You have to convert the hash into a JSON string using hb_jsonEncode( hTheHash ) --> cJson then you can save it to disk using hb_memoWrit()

to recover the hash from the file you use hb_memoRead() and then call to hb_jsonDecode( cJson, @hTheHash ), simply declare local hTheHash before
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: HASH to File and File to HASH

Postby Otto » Thu Nov 24, 2022 7:32 am

Dear Antonio,
now as I have written down my question, I remembered.
Thank you so much and have a nice day.
Best regards,
Otto

Code: Select all  Expand view

 local hPost
//memowrit( "c:\www\htdocs\booking_new1\room.txt", hb_jsonencode( hPairs ) )
 
hb_jsondecode( memoread( "c:\www\htdocs\booking_new1\room.txt" ), @hPost )
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: HASH to File and File to HASH

Postby Otto » Thu Nov 24, 2022 7:37 am

Dear Antonio,
This is real time support from you.
Thank you very much.
There is no better forum and programming community than this.
Best regards,

Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: HASH to File and File to HASH

Postby Antonio Linares » Thu Nov 24, 2022 8:07 am

Dear Otto,

thank you

We all together make these forums as good as they are :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: HASH to File and File to HASH

Postby Enrico Maria Giordano » Thu Nov 24, 2022 8:44 am

Otto wrote:Dear Antonio,
This is real time support from you.
Thank you very much.
There is no better forum and programming community than this.


I totally agree!
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: HASH to File and File to HASH

Postby nageswaragunupudi » Sat Nov 26, 2022 12:51 pm

I prefer
Code: Select all  Expand view
HB_MEMOWRIT( cFile, HB_ValToExp( hHash ) )
// Reading back
hHash := &( MEMOREAD( cFile ) )
 


There is one problem with HASH --> JSON --> HASH.
Any date values in the original hash are converted to character stings "yyyymmdd". Unless we scan the hash and convert all such values back to date type, the hash can not be used in date calculations.

Please try this simple test to prove the point.
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local hHash1, hHash2, cJson, cHash

   SET DATE GERMAN
   SET CENTURY ON

   hHash1 := { "date" => Date() }
   cJson  := hb_jsonEncode( hHash1 )
   hb_jsonDecode( cJson, @hHash2 )
   ? hHash1[ "date" ], ValType( hHash1[ "date" ] ), ;
     hHash2[ "date" ], ValType( hHash2[ "date" ] )

   hHash1   := { "date" => Date() }
   cHash    := hb_ValToExp( hHash1 )
   hHash2   := &cHash
   ? hHash1[ "date" ], ValType( hHash1[ "date" ] ), ;
     hHash2[ "date" ], ValType( hHash2[ "date" ] )

return nil
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 82 guests