Saving an array

Saving an array

Postby TimStone » Fri Nov 30, 2007 9:42 pm

I can write a function to do this, but why re-invent the wheel if it exists.

Is there a function to save the data contained in the elements of an array to a database field ? I'm using DBFCDX and ADS.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Postby James Bott » Fri Nov 30, 2007 11:45 pm

Tim,

Here is one. I haven't tried it.

Regards,
James

Code: Select all  Expand view
From: "Luis Krause Mantilla" <luis_krause@hotmail.com>
Subject: Re: Flexfile III
Date: Wednesday, December 22, 2004 6:19 PM

Colin

The 32 dll's (or whatever it was) from FF3 are unfinished and don't
work.  I spend several days trying to make it work, but I realized
I was just wasting my time.

Because I only stored text and arrays in FF2 (I didn't use FF3),
DBFCDX or ADS will work just fine.

For storing arrays in xHarbour, usind ADS, I just created a function
to "stringify" the array before storing it in the memo field, and
a simple macro evaluation from the memo to get the array back.

If you use the V_xxx() functions, you'll also have to work your
way around this, but it won't be that difficult.

So far it's been more than I year since we've been using our app
with xHarbour + ADSCDX and we haven't missed FF.

This is the function to convert an array to a string (will work
with nested arrays)

* ÉÍ͹  Funci¢n  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
* º  Nombre     : wfAToC()                                                   º
* º  Autor      : C.P. Luis Krause Mantilla                                  º
* º  Objetivo   : Convierte Arreglo a Cadena para almacenar en campos memo   º
* º  Fecha      : 31/07/2003                                                 º
* º  Hora       : 17:38:52                                                   º
* ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ
* º  Argumentos : aArray                                                     º
* ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ
* º  Retorna    : cArray                                                     º
* ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
Function wfAToC( aArray )
Local nI, nJ, cArray, nLen := Len( aArray ), cType, cString

cArray := "{"
For nI := 1 To nLen
    cType := ValType( aArray[nI] )
    If cType == "C" .or. cType == "M"
       cString := aArray[nI]
       // Considerar que la doble comilla puede ser parte de la cadena
       Do While ( nJ := At( '"', cString ) ) > 0
          cArray += '"' + SubStr( cString, 1, nJ - 1 ) + '"+["]+'
          cString := SubStr( cString, nJ + 1 )
       Enddo
       cArray += '"' + cString + '"'
    Elseif cType == "N"
       cArray += LTrim( Str( aArray[nI] ) )
    Elseif cType == "D"
       cArray += "SToD(" + DToS( aArray[nI] ) + ")"
    Elseif cType == "L"
       cArray += If( aArray[nI], ".T.", ".F." )
    Elseif cType == "A"                           // llamada recursiva para
       cArray += wfAToC( aArray[nI] )             // procesar arreglos anidados
    #ifdef __XHARBOUR__
    Elseif cType == "P"                           // Pointer - s¢lo xHarbour
       cArray += HB_NumToHex( aArray[nI] )
    Elseif cType == "H"                           // Hash - s¢lo xHarbour; llamada recursiva para
       cArray += wfAToC( aArray[nI] )             // procesar hashes anidados
    #endif
    Else                                          // objects & codeblocks can't be stored anyway
       cArray += "NIL"
    Endif
    If nI < nLen
       cArray += ","
    Endif
Next
cArray += "}"

Return cArray


This is the one that retrieves the array

* ÉÍ͹  Funci¢n  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
* º  Nombre     : wfCToA()                                                   º
* º  Autor      : C.P. Luis Krause Mantilla                                  º
* º  Objetivo   : Convierte Cadena a Arreglo para restaurar de campos memo   º
* º  Fecha      : 31/07/2003                                                 º
* º  Hora       : 17:38:52                                                   º
* ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ
* º  Argumentos : cArray                                                     º
* ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ
* º  Retorna    : aArray                                                     º
* ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
Function wfCToA( cArray )
Local aArray, bArray

If wfCompile( cArray, .F., @bArray )             // no queremos mensaje si truena
    aArray := Eval( bArray )
Endif
If ! ValType( aArray ) == "A"                    // par metro no proporcionado o
    aArray := {}                                  // error al intentar convertir
Endif

Return aArray


Replace wfCompile() for you function that will test and trap
a possible error, i.e. Eval( &( "{||" + cArray + "}" ) )

HTH.

Colin Wisbey wrote:
> I am a FW (16 bit) user and have delayed going 32 bit due to extensive use
> of Flexfile functions in all my current apps. I love Flexfile. ADS doesn't
> suit my needs and I want to avoid using traditional memo fields if at all
> possible.
>
> I had the impression that Flexfile was not available for 32 bit but I just
> discovered that GrafX currently sell Flexfile III, including 32 bit.
>
> Is anyone using it with xHarbour? If so, I'd be grateful for any feedback on
> reliability etc in the 32 bit environment.
>
> (I've already emailed Grafx too and am awaiting their reply)
>
> TIA
> Colin Wisbey
>
>

--
Luis Krause Mantilla
lkrausem at shaw dot ca
luis_krause at hotmail dot com
"May the Source be with GNU"
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Array save

Postby TimStone » Sat Dec 01, 2007 12:04 am

Encoding is the way I anticipated. I'm a bit puzzled by the decoding logic ... and Replace comment.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Postby James Bott » Sat Dec 01, 2007 12:15 am

Tim,

Here is another string to array function. It appears that this only works with single dimension arrays though.

James

Code: Select all  Expand view
// Convert a string to an array
// cSeparator is the separator character, defaults to TAB
function string2array(cString,cSeparator)
   local nCount:=1,aArray:={},cToken:=""
   default cSeparator:=chr(9)
   do while .t.
      cToken:= strToken(cString,nCount,cSeparator)
      if ! empty(cToken)
         aadd(aArray,cToken)
         nCount++
      else
         exit
      endif
   enddo
return aArray
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Array

Postby TimStone » Sat Dec 01, 2007 12:25 am

I'm only using single dimensional arrays with the module I'm working on. I was going to store the array elements plus separators to a string, and then save that value to a memo field. Since it is only a list, one dimension is all that is needed, and it will be only character data. Of course I could see expanding the capability, needing to do multi-dimensional arrays, plus numeric and logical values, so I'll probably "build it strong" to start !
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Postby James Bott » Sat Dec 01, 2007 12:29 am

Tim,

I just found this reference in my notes too. You might want to check into it also.

James

From: "Ron Pinkas" <Ron@remove-this.xharbour.com>
Subject: Re: Array in memo field?
Date: Thursday, December 02, 2004 9:13 AM

> Is it possible write an array in a memo field with xHarbour or
> Harbour?

Yes, xHarbour has ValToPrg() and ValToPrgExp() which will save ANY TYPE
(Even Objects) into a String.

Ron
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Arrays

Postby TimStone » Sat Dec 01, 2007 12:42 am

I'll have to play with that. You can use ValToPrgExp( ), and then reverse the result with PrgExpToVal( ).

I did a search on the xHarbour newsgroup, and a search of the docs, but apparently didn't have the keywords to find those.

Thanks.

Is it wet enough yet ?
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Postby James Bott » Sat Dec 01, 2007 12:51 am

Tim,

> You can use ValToPrgExp( ), and then reverse the result with PrgExpToVal( ).

I'm putting this in my notes. Keep us posted on your progress with this.

>Is it wet enough yet ?

Judging from the water in the cat food dish on our patio, we have had over an inch so far today. Boy do we need it! The cats are not happy though...

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Antonio Linares » Sat Dec 01, 2007 1:12 am

Tim,

FWH provides:

ASave( aArray ) --> cText

ARead( cText ) --> aArray

Here you have a sample:
Code: Select all  Expand view
function Main()

   local aInfo := { { "one", 1, .T. }, { "two", 2, .F. }, { "three", 3, Date() } }
   local cText := ASave( aInfo )

   aInfo := nil

   aInfo = ARead( cText )

   MsgInfo( Len( aInfo ) )
   MsgInfo( aInfo[ 1 ][ 1 ] )
   MsgInfo( aInfo[ 3 ][ 3 ] )

return nil
Last edited by Antonio Linares on Sat Dec 01, 2007 1:17 am, edited 1 time in total.
regards, saludos

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

Postby James Bott » Sat Dec 01, 2007 1:16 am

Antonio,

ASave(), ARead()

I am wondering if these will handle multidimensional arrays too? What about numeric and logical arrays?

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Antonio Linares » Sat Dec 01, 2007 1:18 am

James,

Yes, they manage all of them. The only limitation is nested arrays.

See the above little working sample
regards, saludos

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

ASave / ARead

Postby TimStone » Sat Dec 01, 2007 1:23 am

OK Antonio ... you're working late again ... go hang with your family !

James and I are getting our first real rain in quite awhile ... and hopefully it will be short enough to not cause mud slides in the fire areas !

I looked at ASave and ARead in the docs, but I thought it meant it put the names of the arrays into memory, not the values of the array elements.

Parameters:
<aArray> Array to code.

Returns:
<cInfo> String containing the coded array.

Thanks for the sample. I asked the question after reading that.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Postby James Bott » Sat Dec 01, 2007 1:24 am

Antonio,

Nice. Thanks for pointing those functions out and the example.

Tim, it looks like these functions are all you need.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Antonio Linares » Sat Dec 01, 2007 1:27 am

Tim,

> OK Antonio ... you're working late again ...

You are right :-)

Time to go to bed. Good night my friends :-)
regards, saludos

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 41 guests