Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Xbasic JSON to and from MySQL using Json_parse() Json_Generate()

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

    Xbasic JSON to and from MySQL using Json_parse() Json_Generate()

    Hi

    I know no xbasic and I am trying to use a Json like object of the format

    [{"col":1,"row":1,"size_x":2,"size_y":2},{"col":3,"row":7,"size_x":1,"size_y":1}]

    I would like to use this in a SQL update statement.

    At a later date I need to produce an output from MySQL in the following format.

    [
    {
    col: 1,
    row: 1,
    size_x: 2,
    size_y: 2
    },

    {
    col: 2,
    row: 5,
    size_x: 1,
    size_y: 1
    }
    ];

    This I can do using a5_MergeDataIntoTemplate()

    So the part I am stuck on is building my update data.

    I have seen

    txt = <<%txt%
    [
    {"col":1,"row":1,"size_x":2,"size_y":2},
    {"col":3,"row":7,"size_x":1,"size_y":1}
    ]
    %txt%

    dim arr[0] as p
    a5_JSON_PopulateArray(arr,txt)

    in the wiki

    Can someone please help with the syntax.

    Michael

    P.S. I find xbasic daunting!

    #2
    Re: Xbasic JSON to and from MySQL using Json_parse() Json_Generate()

    Hey Michael,

    Need a bit more context.

    So the part I am stuck on is building my update data.
    Can you expand a bit? What is it you'd like to do.

    If you have an array of a json object like...

    txt = <<%txt%
    [
    {"col":1,"row":1,"size_x":2,"size_y":2},
    {"col":3,"row":7,"size_x":1,"size_y":1}
    ]
    %txt%

    And you want to populate an XBasic array with it...

    dim arr[0] as p
    a5_JSON_PopulateArray(arr,txt)

    This populates the XBasic array with the json data... so in XBasic you could do...

    x = arr[1].row

    and x would have the value 1

    Comment


      #3
      Re: Xbasic JSON to and from MySQL using Json_parse() Json_Generate()

      Hi David

      If I am using drag and drop or gridster it uses the serialise function (Miss spelled as Serialize).
      So the above is returning a position and size.
      I wish to save 1 in the col field, 1 in the row field, 2 in the size_x field, and 2 in the size_y field
      {"col":1,"row":1,"size_x":2,"size_y":2}

      I think I am trying to do the reverse of this

      delete cn
      dim cn as sql::Connection
      dim flag as l
      cn.open("::Name::MySQL_Bagel")
      cn.Execute("SELECT * FROM Home")
      rs = cn.ResultSet

      This function as you know takes my view called Home and gives me a results set that I can use with a5_MergeDataIntoTemplate()

      I assume I can get help from Alpha to pass the array into an update statement as values

      dim conn as SQL::Connection
      dim upd as SQL::UpdateStatement
      dim cs as SQL::CallResult
      dim connString as C
      dim sql_update as C
      connString = "{A5API='Access', FileName='c:\program files\a5v7\mdbfiles\alphasports.mdb'}"
      sql_update = "update customer set bill_city = 'Phoenix', bill_postal_code = '08000', bill_state_region = 'AZ' where customer_id = 1"





      This example is hard coded and I cannot make the step (LEAP) to using an array.

      sql_update = "update Gridster set col = 'help!', row = 'help!', size_x = 'help!', size_y = 'help!' where Grid_id = 1"

      Thanks in advance David.

      Michael

      Comment


        #4
        Re: Xbasic JSON to and from MySQL using Json_parse() Json_Generate()

        Michael,

        I wonder if there is a better (read "cleaner") way of doing this... but...

        This takes your Array of JSON Objects (2 in your example) and creates a SQL Update statement for each object within a loop.
        I think this is what you're after. Change the connection to your own... then run through it with debug and you'll see how it works.

        Code:
        function ProcessJSON as c (e as p)
        
        debug(1)
        
        'here is the array of JSON Objects you say you already have
        dim myJSON as c = "[{col:1,row:1,size_x:2,size_y:2},{col:3,row:7,size_x:1,size_y:1}]"
        dim arr[0] as p 
        a5_JSON_PopulateArray(arr,myJSON)
        'Now you have your Array of JSON Object inside an XBasic Array
        
        delete cn
        dim cn as sql::Connection
        dim flag as l
        flag = cn.open("::Name::Test")
        
        if flag then
        
        	dim p as p
                dim replaceArray as p
        
        
        
                'because the data is in an XBasic array, we can use that for a loop for each record update
        	for i = 1 to arr.size()
        
        sql_update = <<%txt%
        update Gridster set col = p.col, row = p.row, size_x = p.size_x, size_y = p.size_y where Grid_id = 1
        %txt%
                        'the following creates a pointer array and assigns the current element of our data array to it.  Then we use replace_varibles... to set up the update sql statement.
        		replaceArray = arr[i]
        		sql_update = replace_variables_in_string(sql_update, replaceArray, "p")
        	
        		flag = cn.Execute(sql_update)
        		if flag then
        			'nothing else to do
        		else
        			'there was an error - close the connection and exit
        			cn.Close()
        			dim msg as c 
        			msg = "Could not execute the query. Error reported was: " + cn.CallResult.text
        			msg = js_escape(msg)
        			dim jscmd as c 
        			jscmd = "alert('" + msg + "');"
        			ProcessJSON = jscmd
        		end if  
        		
        	next i		
                cn.close()
        
        else
        	'there was an error - close the connection and exit
        	dim msg as c 
        	msg = "Could not open the connection. Error reported was: " + cn.CallResult.text
        	msg = js_escape(msg)
        	dim jscmd as c 
        	jscmd = "alert('" + msg + "');"
        	ProcessJSON = jscmd
        end if
        
        end function
        
        EDIT: corrected sql_update line
        Last edited by Davidk; 03-31-2014, 02:15 PM.

        Comment


          #5
          Re: Xbasic JSON to and from MySQL using Json_parse() Json_Generate()

          Thanks David

          I will give this a try

          Michael

          Comment


            #6
            Re: Xbasic JSON to and from MySQL using Json_parse() Json_Generate()

            Hi David

            I am getting an error msg = "Could not execute the query.Line 41 Error reported was: " + cn.CallResult.text "Not currently connected to the database"

            flag = cn.Execute(sql_update)

            turns to false it was true upto this point.


            "update Gridster set col = 1, row = 1, size_x = 2, size_y = 2 where Grid_id = 1"

            If I strip out " " the parenthesis I can run the SQL statement at the command line and the update is performed.
            Does Alpha need them or should they be removed?

            If so how to remove?

            Michael

            Comment


              #7
              Re: Xbasic JSON to and from MySQL using Json_parse() Json_Generate()

              Yes... sorry... I just copied your line of code in there... should be...

              Code:
              sql_update = <<%txt%
              update Gridster set col = p.col, row = p.row, size_x = p.size_x, size_y = p.size_y where Grid_id = 1
              %txt%

              Comment


                #8
                Re: Xbasic JSON to and from MySQL using Json_parse() Json_Generate()

                Hi David

                Really sorry but I have nearly got it working. I removed a cn.close()

                if flag then
                'nothing else to do
                'removed cn.Close()
                else

                However the first update works and the second does not.

                It appears to be a leading , I remember Selwyn mentioning this in a video.

                How would I strip these in xbasic?

                Michael

                P.S. do you know NienKamper they appear to be just down the road.

                http://www.nienkamper.com/ good people.

                Comment


                  #9
                  Re: Xbasic JSON to and from MySQL using Json_parse() Json_Generate()

                  Sorry... I usually run the code... didn't this time...

                  Yes... I forgot we're in a loop... take out that cn.Close... put it after the next i statement... when we're all done.

                  Move the sql_update = statement to just after the start of the loop... I've corrected the code above.

                  We need to reset the sql_update variable in order to do the replace.

                  No... I haven't heard of that company... interesting.

                  Comment

                  Working...
                  X