Page 1 of 1

Xbrowse complex export to dbf challenge...

Posted: Sat Oct 30, 2021 5:57 pm
by Marc Venken
My API return a complex data string, that xbrowse can read. I can even read the more complex data insite a xbrowse column :

Colums header : quantities
Colums data :

{"quantity":"0","physicalQuantity":"0","minimumQuantity":"0","maximumQuantity":null,"externalQuantity":"0","quantityStep":"1","trackQuantity":"1"}

Xbrowse will show that data when i look into it.

How nice would it be if Xbrowse could also export these field into a dbf. (physicalquantity, minimum, .....)
The dbf would have than ALL the fields insite. Now the complex data stay blank (at least tested Xbrowse to exell)

That way we would let xbrowse do the hard work :D :D :wink: (I do it for exel files...)

Re: Xbrowse complex export to dbf challenge...

Posted: Sun Oct 31, 2021 12:50 am
by James Bott
Marc,

Why not put the data into a DBF first then read it into a browse. You can replace all the colons with a comma to create a standard comma delimited file. Then just append the comma delimited records into the DBF. Finally browse the DBF.

Actually, you will need to strip out the fieldnames before you browse the file. I would append the records (with fieldnames) into a temp DBF, then export all the values (only) into the final DBF.

James

Re: Xbrowse complex export to dbf challenge...

Posted: Sun Oct 31, 2021 4:37 am
by cnavarro
Hi

Code: Select all | Expand


#include "Fivewin.ch"

//----------------------------------------------------------------------------//

Function Main()

   local hDatos    := { => }
   local uResponse
   uResponse := '{"quantity":"0","physicalQuantity":"0","minimumQuantity":"0",' + ;
                '"maximumQuantity":null,"externalQuantity":"0","quantityStep":"1",' + ;
                '"trackQuantity":"1"}'

   hb_JsonDecode( uResponse, @hDatos )     // -> Hash
   XBrowse( hb_hKeys( hDatos ) )           // -> Array
   XBrowse( hb_hValues( hDatos ) )         // -> Array
   XBrowse( hDatos )

Return nil

//----------------------------------------------------------------------------//
 

Re: Xbrowse complex export to dbf challenge...

Posted: Sun Oct 31, 2021 10:26 am
by Marc Venken
James Bott wrote:Marc,

Why not put the data into a DBF first then read it into a browse. You can replace all the colons with a comma to create a standard comma delimited file. Then just append the comma delimited records into the DBF. Finally browse the DBF.

Actually, you will need to strip out the fieldnames before you browse the file. I would append the records (with fieldnames) into a temp DBF, then export all the values (only) into the final DBF.

James


James,

Normaly I would do it like you suggest... and spend time in doing so (could take hours in my case)
But i also learned that in FW and Harbour there is so much done (functions) that it just takes a question in the forum to find the allready built functions. (GREAT) and thanks for every one here !!!

Re: Xbrowse complex export to dbf challenge...

Posted: Sun Oct 31, 2021 12:22 pm
by Marc Venken
cnavarro wrote:Hi

Code: Select all | Expand


#include "Fivewin.ch"

//----------------------------------------------------------------------------//

Function Main()

   local hDatos    := { => }
   local uResponse
   uResponse := '{"quantity":"0","physicalQuantity":"0","minimumQuantity":"0",' + ;
                '"maximumQuantity":null,"externalQuantity":"0","quantityStep":"1",' + ;
                '"trackQuantity":"1"}'

   hb_JsonDecode( uResponse, @hDatos )     // -> Hash
   XBrowse( hb_hKeys( hDatos ) )           // -> Array
   XBrowse( hb_hValues( hDatos ) )         // -> Array
   XBrowse( hDatos )

Return nil

//----------------------------------------------------------------------------//
 


Working with your sample, I came very close to a solution.
This program will read the data and even the subdata (arrays that are in fields) are seen and this data i can see.
I found a link to the Harbour functions, but failt to make a array with all the possible fieldnames and data.
As you see, the building of the aFields is not working. What is needed for this ? Maybe the approich is also not optimal...

Code: Select all | Expand


#include "FiveWin.ch"

Function Main()
   local oWnd, oActiveX1, oActiveX2, cTemp

   DEFINE WINDOW oWnd TITLE "FiveWin multiple ActiveX support"

   @ 9,5 BUTTON "&Hash"   OF oWnd SIZE 40, 20  ACTION TestHash()

   ACTIVATE WINDOW oWnd

return nil

//----------------------------------------------------------------------------//

Function TestHash()

   local hDatos    := { => }
   local aTest    := {}
   local aResult  := {}
   local aFields  := {}

   local uResponse, cCookies, I

   uResponse := '{"uprid":"2550","productId":"2550","stockId":"-1","referenceId":"0","isBundle":"0","bundledProducts":"[]","status":"1","quantity":"0","maximumQuantity":"null","ean":"98745123456","sku":"skuData","model":"APITEST","hsCode":"","name":"Noyca","price":"0.0000","taxClassId":"3","taxRate":"21.0000","isPhysical":"1","isDigital":"0","isQuotation":"0","url":"onderhoud\/api-test","urlAbs":"https:\/\/http://www.maveco-webshop.be\/onderhoud\/api-test","attributesString":"","backOrder":0,"onHome":0,"layover":0,"configurationAllowCheckout":0,"configurationStockCheck":0,"attributes":[],"description":"Memo<b>Data<\/b>","addonInstagramEnabled":"0","addonInstagram":"0","addonOcsEnabled":"0","dateAdded":"2021-10-30 18:40:57","lastModified":"2021-10-30 19:17:39","descriptions":{"description":"Memo<b>Data<\/b>","extra":"","intro":""},"images":["5101000.jpg","","","","","","","","","","",""],"image_alt":["","","","","","","","","","","",""],"discounts":{"name":"0","groupDiscount":"0.00","groupDiscountCategory":"0.00","groupDiscountProduct":"0.00"},"category":{"id":"888982","name":"Onderhoud","categoryIds":"888982","cPath":"888982"},"quantities":{"quantity":"0","physicalQuantity":"0","minimumQuantity":"0","maximumQuantity":null,"externalQuantity":"0","quantityStep":"1","trackQuantity":"1"},"prices":{"basePrice":"0.0000","normalPrice":"0.0000","price":"0.0000","specialPrice":"0.0000","purchasePrice":"0.0000"},"manufacturer":{"id":0,"name":"","image":""},"dimensions":{"type":"0","width":0,"height":0,"area":0,"weight":0},"reviews":{"count":0,"avg":0},"resources":[],"addons":{"multicatalog":{"enabled":false},"layover":{"enabled":true}}}'

   hb_JsonDecode( uResponse, @hDatos )     // -> Hash
   XBrowse( hb_hKeys( hDatos ) )           // -> Array
   XBrowse( hb_hValues( hDatos ) )         // -> Array
   XBrowse( hDatos )

   // simple key
   cCookies := If( hb_HHasKey( hDatos, "name" ), hb_hGet( hDatos, "name" ), "Not Found" )
   msginfo(cCookies) // Found

   // complex key a array insite a field //  "prices":{"basePrice":"0.0000","normalPrice":"0.0000","price":"0.0000","specialPrice":"0.0000","purchasePrice":"0.0000"}
   // Extract 1 complex key if the keyname is known
   if hb_HHasKey( hDatos, "prices" )
     msginfo("Found")
     XBrowse( hb_hKeys( hDatos["prices"] ) )           // is showing the items insite the sub array
     XBrowse( hb_hValues (hDatos["prices"] ) )         // -> Array
     XBrowse( hDatos["prices"] )         // Items and Values subarray
     //  At this point, I could stuff the data insite a dbf.  I have fields and values
   else
     msginfo("Not Found")
   endif

   // extract all keys, not knowing if there are subarray (keys)
   aTest = hb_hKeys( hDatos )           // -> Array
   xbrowse(aTest)

   for i = 1 to len(aTest)
     cZoek = aTest[i]
     msginfo(cZoek)
     if hb_HHasKey( hDatos, cZoek )
       aResult = hDatos[cZoek]          // -> Array
       XBrowse( aResult )           // is showing the items, also the subitems

       //  Here I want to build a array (aFields) with all the keys that are seen, with there values.
       //  not working

       for m = 1 to len(aResult)
         aadd(aFields,aResult[m])
       next m

       //XBrowse( aResult )           // is showing the items insite the sub array
     endif
     //XBrowse( aFields )           // is showing the items insite the sub array
     // Build the dbf with the array.

     // Maybe better to build a single Hash with all fields.  Than a hashtodbf save can be done.

   next

Return nil