Announcement

Collapse
No announcement yet.

restoring dynamic string array

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • restoring dynamic string array

    PB has great facilities for storing and retrieving dynamic string arrays to a file, but I want to I want to take a copy of a DSA string array into a database blob field and restore it from the same. I suspect that this won't work as something in the PB program (I'm guessing) keeps track of the DSA's memory utilisation and therefore has to know about the DSA, and there is no API for it. Or maybe it is a Windows string type and there is an API. Or there is another way of doing it.

    I thought I would ask for help rather than suffering.

  • #2
    What is 'DSA?'

    BUt that's not really important, because.....

    If you want to store a dynamic string array, all you have to do is JOIN$() it into a big string using a delimiter which does not appear in the data and store that string; when you retrieve it you can just PARSE it out using the same delimter.

    I know, I know: "But Mike, I can't know if a delimiter will or won't appear in the data." Well, boo-hoo. Then you just build a big string consisting of element count followed by as many <element length, elementdata> pairs as required and store that string.

    Should take you maybe 15 minutes to write and test either way. Add database store and retrieve code and you're done.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Originally posted by Michael Mattias View Post
      What... is 'DSA?'
      Dynamic String Array

      Originally posted by Michael Mattias View Post
      Well, boo-hoo.
      quite.

      What you say is true and I may have to do it, though I would prefer to deal with the array rather than its components.

      Comment


      • #4
        Originally posted by Michael Mattias View Post
        I know, I know: "But Mike, I can't know if a delimiter will or won't appear in the data." Well, boo-hoo. Then you just build a big string consisting of element count followed by as many <element length, elementdata> pairs as required and store that string.

        Michael, Michael, Michael...

        Somehow, Someway, I just know you really meant to suggest JOIN$ with the BINARY option to create the big string, didn't you? That's one line of code. And then you can use PARSE with the BINARY option to take it apart... Again, just one line of code. Tell me that's what you really meant to suggest?

        Best regards,

        Bob Zale
        PowerBASIC Inc.

        Comment


        • #5
          Chris, I'm writing a little example which I think shows you how to do it just like you want, no extra delimiters. Added: Oopsie, Sir Bob replied already, prolly you don't need the 'zample now, no?
          Last edited by John Gleason; 27 Jul 2008, 06:07 PM.

          Comment


          • #6
            Originally posted by Bob Zale View Post
            Tell me that's what you really meant to suggest?
            Yes, that's what he meant, all right.

            Thanks!

            Comment


            • #7
              Originally posted by Chris Holbrook View Post
              Yes, that's what he meant, all right.
              Thanks!
              Good! I was beginning to worry... {smile}


              Bob Zale
              PowerBASIC Inc.

              Comment


              • #8
                Here is an example:
                Code:
                #COMPILE EXE
                #DIM ALL
                
                FUNCTION PBMAIN () AS LONG
                   DIM strArr(2) AS STRING
                   LOCAL blobField AS STRING, ii AS LONG
                   
                   KILL "c:\blobFieldTest01.dat"
                   OPEN "c:\blobFieldTest01.dat" FOR BINARY AS #1
                      FOR ii = 0 TO 2
                         blobField = REPEAT$(ii, "12339dkdkjfkdldsessededdddeeeee" & STRING$(RND(1,25), 177))
                         strArr(ii) = blobField
                         ? blobField
                      NEXT
                      
                      blobField = JOIN$(strArr(), BINARY)
                      PUT #1,, blobField       'you put it to your database here
                      CLOSE #1
                
                      'then to get it back:
                   OPEN "c:\blobFieldTest01.dat" FOR BINARY AS #1 'standin for your database
                   GET #1,, strArr()
                   
                   FOR ii = 0 TO 2
                      ? strArr(ii)
                   NEXT
                
                END FUNCTION

                Comment


                • #9
                  No, I did not mean BINARY. Matter of fact, I had to look up that JOIN$() option, as I was not even aware of its existence.

                  But I should have meant it, as it's a lot easier to let the compiler handle all the <length word, data>, <length word, data>... pairs than to do it myself.

                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    Just wanted to point out, you can PUT it without even JOINing it and save a line of code:
                    Code:
                          PUT #1,, strArr() 'blobField       'you put it to your database here

                    Comment


                    • #11
                      Y'all don't "PUT hFile, ,data" to a BLOB datatype in a database.

                      I have some code here somewhere to do it via ODBC if someone really wants it.
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        I will post a SQLite example soon if no-one beats me to it...

                        Comment

                        Working...
                        X