FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Put Hash data into a dbf
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM

Put Hash data into a dbf

Posted: Mon May 24, 2021 10:06 PM

I was able to get a Hash, but not yet able to save the items to a dbf, since a hash is complex for me.

I tried to use todbf from xbrowser, but as far as I have been reading that is not supported yet.

It would be perfect is all elements from the hash can be converted to a dbf field. That I can use this for further use.

A Hashtodf functions is not in FW right ?

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Put Hash data into a dbf

Posted: Tue May 25, 2021 08:20 AM

FW_RecToHash()
FW_HashToRec( hHash )

Regards



G. N. Rao.

Hyderabad, India
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM

Re: Put Hash data into a dbf

Posted: Tue May 25, 2021 08:30 AM

cJSON := hb_jsonEncode( xValue [, lHuman] )

After save cJSON string in memo field

To Restore:

nLengthDecoded := hb_jsonDecode( cJSON, @xValue )

From https://www.kresin.ru/en/hrbfaq_3.html

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Put Hash data into a dbf

Posted: Tue May 25, 2021 09:20 AM
For storing a hash value in a memo field, you suggested converting to Json and save and then read the Json and convert back the Json value to hash.
Nice, but in this process, all values of the hash are converted to character values.

For example, consider this hash.
{ "Name" => "John", "Age" => 30, "DOB" => {^ 1991/02/02 } }
When we conver this hash to json and back, dob is converted to character type.

I suggest:

Storing:
Code (fw): Select all Collapse
FIELD->MEMOFIELD := FW_ValToExp( hHash )


Reading back to hash:
Code (fw): Select all Collapse
hHash := &( FIELD->MEMOFIELD )

In the resulting hash, dob's valtype is "D".
Regards



G. N. Rao.

Hyderabad, India
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM

Re: Put Hash data into a dbf

Posted: Tue May 25, 2021 02:22 PM

Thks

Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM

Re: Put Hash data into a dbf

Posted: Wed May 26, 2021 03:35 PM

For some hashes, the more easy once, i have no problem to write to dbf or edit them en write them.
Mostly a name and a data

for the complex one that I retrieve from a API it's a other thing. On the Spanisch forum there was recently (Jan 2021) a topic to have a hash to a sql database, and that that function would go into FWH

I want this hashdata to go into a dbf, but the hash is complex... (just 2 items from a shop)

I want all items insite a dbf for reasons of compare the my dbf, but inside the hash there are extra array's enz...

like

"image_alt":["","","","","","","","","","","",""]

"images":["bcwu03w.jpg","bcwu03w_black-pure.jpg","bcwu03w_candy-pink.jpg","bcwu03w_desert.jpg","bcwu03w_elephant-grey.jpg","bcwu03w_forest-green.jpg","bcwu03w_grey-fog.jpg","bcwu03w_hawaiian-blue.jpg","bcwu03w_heather-asphalt.jpg","bcwu03w_heather-dark-green.jpg","bcwu03w_heather-grey.jpg","bcwu03w_heather-mid-grey.jpg"]

Maybe there is already a function for the more complex hashes (i didn't find it) or could not use it.

Hash/

{"numRows":1182,"numPages":591,"pageNumber":0,"startIndex":0,"endIndex":2,"totalValue":"10819097.2000","totalPurchaseValue":"0.0000","totalMargin":"10819097.2000","totalQuantity":306361,"totalPhysicalQuantity":54,"totalMinimumQuantity":0,"lowestPrice":"0.0000","highestPrice":"365.0300","data":[{"uprid":"543","productId":543,"stockId":-1,"referenceId":0,"isBundle":0,"bundledProducts":[],"status":1,"quantity":"400","maximumQuantity":null,"ean":"","sku":"","model":"BCWU03W","hsCode":null,"name":"#Hoodie","price":"13.4280","taxClassId":"3","taxRate":"21.0000","isPhysical":"1","isDigital":"0","isQuotation":"1","url":"promotiekleding\/sweaters\/sweaters-met-kap\/hoodie","urlAbs":"https:\/\/www.maveco-webshop.be\/promotiekleding\/sweaters\/sweaters-met-kap\/hoodie","attributesString":"","backOrder":0,"onHome":0,"layover":1,"configurationAllowCheckout":1,"configurationStockCheck":0,"attributes":[],"description":"Uniseks <br> French Terry <br> Lange mouwen <br> Hooded <br> Regular fit <br> Voorgekrompen ringgesponnen katoen <br> Zijnaden <br> Gemakkelijke branding: geen B&C label <br> Binnenkant Single Jersey halfmoon in rug <br> Ongeborstelde stof <br> Sterke stof <br> Zacht handgevoel <br> Glad en gelijkmatig oppervlak <br> In zijnaad: Zacht satijnlabel","addonInstagramEnabled":"0","addonInstagram":"0","addonOcsEnabled":"0","dateAdded":"0000-00-00 00:00:00","lastModified":"2020-09-11 16:41:37","descriptions":{"description":"Uniseks <br> French Terry <br> Lange mouwen <br> Hooded <br> Regular fit <br> Voorgekrompen ringgesponnen katoen <br> Zijnaden <br> Gemakkelijke branding: geen B&C label <br> Binnenkant Single Jersey halfmoon in rug <br> Ongeborstelde stof <br> Sterke stof <br> Zacht handgevoel <br> Glad en gelijkmatig oppervlak <br> In zijnaad: Zacht satijnlabel","extra":"","intro":" 280 g\/m"},"images":["bcwu03w.jpg","bcwu03w_black-pure.jpg","bcwu03w_candy-pink.jpg","bcwu03w_desert.jpg","bcwu03w_elephant-grey.jpg","bcwu03w_forest-green.jpg","bcwu03w_grey-fog.jpg","bcwu03w_hawaiian-blue.jpg","bcwu03w_heather-asphalt.jpg","bcwu03w_heather-dark-green.jpg","bcwu03w_heather-grey.jpg","bcwu03w_heather-mid-grey.jpg"],"image_alt":["","","","","","","","","","","",""],"discounts":{"name":"0","groupDiscount":"0.00","groupDiscountCategory":"0.00","groupDiscountProduct":"0.00"},"category":{"id":"888963","name":"Sweaters met kap","categoryIds":"888963","cPath":"73_888904_888963"},"quantities":{"quantity":"400","physicalQuantity":"0","minimumQuantity":"0","maximumQuantity":null,"externalQuantity":"0","quantityStep":"1","trackQuantity":"1"},"prices":{"basePrice":"14.9200","normalPrice":"14.9200","price":"13.4280","specialPrice":"13.4280","purchasePrice":"0.0000"},"manufacturer":{"id":46,"name":"B&amp;C","image":"bc.jpg-preview72.jpg"},"dimensions":{"type":"0","width":0,"height":0,"area":0,"weight":0},"reviews":{"count":0,"avg":0},"resources":[],"addons":{"multicatalog":{"enabled":false},"layover":{"enabled":true}}},{"uprid":"561","productId":561,"stockId":-1,"referenceId":0,"isBundle":0,"bundledProducts":[],"status":1,"quantity":"400","maximumQuantity":null,"ean":"","sku":"","model":"BCWW04W","hsCode":null,"name":"#Hoodie Sweat \/Women","price":"13.4280","taxClassId":"3","taxRate":"21.0000","isPhysical":"1","isDigital":"0","isQuotation":"1","url":"promotiekleding\/dames\/dames-sweaters--fleece\/hoodie-sweat-women","urlAbs":"https:\/\/www.maveco-webshop.be\/promotiekleding\/dames\/dames-sweaters--fleece\/hoodie-sweat-women","attributesString":"","backOrder":0,"onHome":0,"layover":1,"configurationAllowCheckout":1,"configurationStockCheck":0,"attributes":[],"description":"French Terry <br> Lange mouwen <br> Hooded <br> Regular fit <br> Voorgekrompen ringgesponnen katoen <br> Zijnaden <br> Gemakkelijke branding: geen B&C label <br> Binnenkant Single Jersey halfmoon in rug <br> Ongeborstelde stof <br> Sterke stof <br> Zacht handgevoel <br> Glad en gelijkmatig oppervlak <br> In zijnaad: Zacht satijnlabel","addonInstagramEnabled":"0","addonInstagram":"0","addonOcsEnabled":"0","dateAdded":"2020-09-11 16:41:47","lastModified":"2020-09-11 16:41:47","descriptions":{"description":"French Terry <br> Lange mouwen <br> Hooded <br> Regular fit <br> Voorgekrompen ringgesponnen katoen <br> Zijnaden <br> Gemakkelijke branding: geen B&C label <br> Binnenkant Single Jersey halfmoon in rug <br> Ongeborstelde stof <br> Sterke stof <br> Zacht handgevoel <br> Glad en gelijkmatig oppervlak <br> In zijnaad: Zacht satijnlabel","extra":"","intro":" 280 g\/m"},"images":["bcww04w.jpg","bcww04w_black-pure.jpg","bcww04w_candy-pink.jpg","bcww04w_desert.jpg","bcww04w_elephant-grey.jpg","bcww04w_forest-green.jpg","bcww04w_grey-fog.jpg","bcww04w_hawaiian-blue.jpg","bcww04w_heather-asphalt.jpg","bcww04w_heather-dark-green.jpg","bcww04w_heather-grey.jpg","bcww04w_heather-mid-grey.jpg"],"image_alt":["","","","","","","","","","","",""],"discounts":{"name":"0","groupDiscount":"0.00","groupDiscountCategory":"0.00","groupDiscountProduct":"0.00"},"category":{"id":"888955","name":"Dames Sweaters & Fleece","categoryIds":"888955","cPath":"73_888940_888955"},"quantities":{"quantity":"400","physicalQuantity":"0","minimumQuantity":"0","maximumQuantity":null,"externalQuantity":"0","quantityStep":"1","trackQuantity":"1"},"prices":{"basePrice":"14.9200","normalPrice":"14.9200","price":"13.4280","specialPrice":"13.4280","purchasePrice":"0.0000"},"manufacturer":{"id":46,"name":"B&amp;C","image":"bc.jpg-preview72.jpg"},"dimensions":{"type":"0","width":0,"height":0,"area":0,"weight":0},"reviews":{"count":0,"avg":0},"resources":[],"addons":{"multicatalog":{"enabled":false},"layover":{"enabled":true}}}]}

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM

Re: Put Hash data into a dbf

Posted: Wed May 26, 2021 03:48 PM

Perhaps viewtopic.php?f=17&t=37597#p224751 from Cristobal Navarro master using HashToXml() .and. XmlToHash() methods

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Put Hash data into a dbf

Posted: Thu May 27, 2021 12:35 AM
Very simple.


{"numRows":1182,"numPages":591,"pageNumber":0,"startIndex":0,"endIndex":2,"totalValue":"10819097.2000","totalPurchaseValue":"0.0000","totalMargin":"10819097.2000","totalQuantity":306361,"totalPhysicalQuantity":54,"totalMinimumQuantity":0,"lowestPrice":"0.0000","highestPrice":"365.0300","data":[{"uprid":"543","productId":543,"stockId":-1,"referenceId":0,"isBundle":0,"bundledProducts":[],"status":1,"quantity":"400","maximumQuantity":null,"ean":"","sku":"","model":"BCWU03W","hsCode":null,"name":"#Hoodie","price":"13.4280","taxClassId":"3","taxRate":"21.0000","isPhysical":"1","isDigital":"0","isQuotation":"1","url":"promotiekleding\/sweaters\/sweaters-met-kap\/hoodie","urlAbs":"https:\/\/www.maveco-webshop.be\/promotiekleding\/sweaters\/sweaters-met-kap\/hoodie","attributesString":"","backOrder":0,"onHome":0,"layover":1,"configurationAllowCheckout":1,"configurationStockCheck":0,"attributes":[],"description":"Uniseks <br> French Terry <br> Lange mouwen <br> Hooded <br> Regular fit <br> Voorgekrompen ringgesponnen katoen <br> Zijnaden <br> Gemakkelijke branding: geen B&C label <br> Binnenkant Single Jersey halfmoon in rug <br> Ongeborstelde stof <br> Sterke stof <br> Zacht handgevoel <br> Glad en gelijkmatig oppervlak <br> In zijnaad: Zacht satijnlabel","addonInstagramEnabled":"0","addonInstagram":"0","addonOcsEnabled":"0","dateAdded":"0000-00-00 00:00:00","lastModified":"2020-09-11 16:41:37","descriptions":{"description":"Uniseks <br> French Terry <br> Lange mouwen <br> Hooded <br> Regular fit <br> Voorgekrompen ringgesponnen katoen <br> Zijnaden <br> Gemakkelijke branding: geen B&C label <br> Binnenkant Single Jersey halfmoon in rug <br> Ongeborstelde stof <br> Sterke stof <br> Zacht handgevoel <br> Glad en gelijkmatig oppervlak <br> In zijnaad: Zacht satijnlabel","extra":"","intro":" 280 g\/m"},"images":["bcwu03w.jpg","bcwu03w_black-pure.jpg","bcwu03w_candy-pink.jpg","bcwu03w_desert.jpg","bcwu03w_elephant-grey.jpg","bcwu03w_forest-green.jpg","bcwu03w_grey-fog.jpg","bcwu03w_hawaiian-blue.jpg","bcwu03w_heather-asphalt.jpg","bcwu03w_heather-dark-green.jpg","bcwu03w_heather-grey.jpg","bcwu03w_heather-mid-grey.jpg"],"image_alt":["","","","","","","","","","","",""],"discounts":{"name":"0","groupDiscount":"0.00","groupDiscountCategory":"0.00","groupDiscountProduct":"0.00"},"category":{"id":"888963","name":"Sweaters met kap","categoryIds":"888963","cPath":"73_888904_888963"},"quantities":{"quantity":"400","physicalQuantity":"0","minimumQuantity":"0","maximumQuantity":null,"externalQuantity":"0","quantityStep":"1","trackQuantity":"1"},"prices":{"basePrice":"14.9200","normalPrice":"14.9200","price":"13.4280","specialPrice":"13.4280","purchasePrice":"0.0000"},"manufacturer":{"id":46,"name":"B&amp;C","image":"bc.jpg-preview72.jpg"},"dimensions":{"type":"0","width":0,"height":0,"area":0,"weight":0},"reviews":{"count":0,"avg":0},"resources":[],"addons":{"multicatalog":{"enabled":false},"layover":{"enabled":true}}},{"uprid":"561","productId":561,"stockId":-1,"referenceId":0,"isBundle":0,"bundledProducts":[],"status":1,"quantity":"400","maximumQuantity":null,"ean":"","sku":"","model":"BCWW04W","hsCode":null,"name":"#Hoodie Sweat \/Women","price":"13.4280","taxClassId":"3","taxRate":"21.0000","isPhysical":"1","isDigital":"0","isQuotation":"1","url":"promotiekleding\/dames\/dames-sweaters--fleece\/hoodie-sweat-women","urlAbs":"https:\/\/www.maveco-webshop.be\/promotiekleding\/dames\/dames-sweaters--fleece\/hoodie-sweat-women","attributesString":"","backOrder":0,"onHome":0,"layover":1,"configurationAllowCheckout":1,"configurationStockCheck":0,"attributes":[],"description":"French Terry <br> Lange mouwen <br> Hooded <br> Regular fit <br> Voorgekrompen ringgesponnen katoen <br> Zijnaden <br> Gemakkelijke branding: geen B&C label <br> Binnenkant Single Jersey halfmoon in rug <br> Ongeborstelde stof <br> Sterke stof <br> Zacht handgevoel <br> Glad en gelijkmatig oppervlak <br> In zijnaad: Zacht satijnlabel","addonInstagramEnabled":"0","addonInstagram":"0","addonOcsEnabled":"0","dateAdded":"2020-09-11 16:41:47","lastModified":"2020-09-11 16:41:47","descriptions":{"description":"French Terry <br> Lange mouwen <br> Hooded <br> Regular fit <br> Voorgekrompen ringgesponnen katoen <br> Zijnaden <br> Gemakkelijke branding: geen B&C label <br> Binnenkant Single Jersey halfmoon in rug <br> Ongeborstelde stof <br> Sterke stof <br> Zacht handgevoel <br> Glad en gelijkmatig oppervlak <br> In zijnaad: Zacht satijnlabel","extra":"","intro":" 280 g\/m"},"images":["bcww04w.jpg","bcww04w_black-pure.jpg","bcww04w_candy-pink.jpg","bcww04w_desert.jpg","bcww04w_elephant-grey.jpg","bcww04w_forest-green.jpg","bcww04w_grey-fog.jpg","bcww04w_hawaiian-blue.jpg","bcww04w_heather-asphalt.jpg","bcww04w_heather-dark-green.jpg","bcww04w_heather-grey.jpg","bcww04w_heather-mid-grey.jpg"],"image_alt":["","","","","","","","","","","",""],"discounts":{"name":"0","groupDiscount":"0.00","groupDiscountCategory":"0.00","groupDiscountProduct":"0.00"},"category":{"id":"888955","name":"Dames Sweaters & Fleece","categoryIds":"888955","cPath":"73_888940_888955"},"quantities":{"quantity":"400","physicalQuantity":"0","minimumQuantity":"0","maximumQuantity":null,"externalQuantity":"0","quantityStep":"1","trackQuantity":"1"},"prices":{"basePrice":"14.9200","normalPrice":"14.9200","price":"13.4280","specialPrice":"13.4280","purchasePrice":"0.0000"},"manufacturer":{"id":46,"name":"B&amp;C","image":"bc.jpg-preview72.jpg"},"dimensions":{"type":"0","width":0,"height":0,"area":0,"weight":0},"reviews":{"count":0,"avg":0},"resources":[],"addons":{"multicatalog":{"enabled":false},"layover":{"enabled":true}}}]}


This is not Hash. This is Json.
Save the entire value to a memo-field.
When you want, read as cJson and convert to hash if and when you want.

Code (fw): Select all Collapse
FIELD->MEMOFIELD := cJsonValue
// when required
cJson := FIELD->MEMOFIELD
HB_JsonDecode( cJson, @hHash )
// use hHash


Do not worry about its complexity.
This works.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM

Re: Put Hash data into a dbf

Posted: Thu May 27, 2021 07:58 AM

If there a function to retrieve this info ?

Manufacturor name : B&W -> manufacturer":{"id":46,"name":"B&amp;C"

c_model = BCWU03W -> model":"BCWU03W" // this is more easy
c_CatID = 888963 -> "category":{"id":"888963","name":"Sweaters met kap","categoryIds":"888963"
c_Catname = Sweater met kap -> "category":{"id":"888963","name":"Sweaters met kap","categoryIds":"888963"

Or do I write to a memVar and use the functions to extract data from it

then I save to a dbf with the fields I need.

Marc Venken

Using: FWH 23.08 with Harbour

Continue the discussion