Xbrowse complex export to dbf challenge...

Xbrowse complex export to dbf challenge...

Postby Marc Venken » Sat Oct 30, 2021 5:57 pm

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...)
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Xbrowse complex export to dbf challenge...

Postby James Bott » Sun Oct 31, 2021 12:50 am

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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Xbrowse complex export to dbf challenge...

Postby cnavarro » Sun Oct 31, 2021 4:37 am

Hi
Code: Select all  Expand view

#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

//----------------------------------------------------------------------------//
 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Xbrowse complex export to dbf challenge...

Postby Marc Venken » Sun Oct 31, 2021 10:26 am

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 !!!
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Xbrowse complex export to dbf challenge...

Postby Marc Venken » Sun Oct 31, 2021 12:22 pm

cnavarro wrote:Hi
Code: Select all  Expand view

#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 view

#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

 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

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