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

How to generate nested Json objects from MySql to resultSet using xBasic?

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

    How to generate nested Json objects from MySql to resultSet using xBasic?

    Nested Json objects for the Northwind database fro example like this:

    Code:
    {
    "CustomerID": "ALFKI",
    "CompanyName": "Alfreds Futterkiste"
    "City": "Berlin", 
    "Country": "Germany",
    "orders":[INDENT][
    {"OrderID": 10643, "OrderDate": "1995-09-25 00:00:00.000000", "CustomerID": "ALFKI", "EmployeeID": 6}, 
    {"OrderID": 10692, "OrderDate": "1995-11-03 00:00:00.000000", "CustomerID": "ALFKI", "EmployeeID": 4}, 
    {"OrderID": 10702, "OrderDate": "1995-11-13 00:00:00.000000", "CustomerID": "ALFKI", "EmployeeID": 4}, 
    {"OrderID": 10835, "OrderDate": "1996-02-15 00:00:00.000000", "CustomerID": "ALFKI", "EmployeeID": 1}, 
    {"OrderID": 10952, "OrderDate": "1996-04-15 00:00:00.000000", "CustomerID": "ALFKI", "EmployeeID": 1}, 
    {"OrderID": 11011, "OrderDate": "1996-05-09 00:00:00.000000", "CustomerID": "ALFKI", "EmployeeID": 3}
    ],  
    [/INDENT]
    }
    I obtained the above json definition directly from Mysql database by using the json_object function available in the latest version of MySQl (5.7), you can try it yourself if you're interested:

    Code:
    select json_object(
    'CustomerID', customers.`customerid`
    , 'CompanyName',customers.`companyName`
    , 'City', customers.`City`
    , 'Country', customers.`Country`
    , 'orders', (select cast(concat('[',
     GROUP_CONCAT(
     json_object(
    'OrderID',orderID, 'CustomerID', `CustomerID`, 'EmployeeID', EmployeeID, 'OrderDate', OrderDate)),
     ']') 
     as JSON) from orders where customers.customerID = orders.customerID)
     ) as json_definition from customers where customers.customerID = "ALFKI";
    The challenge is that I'm unable to obtain the resultset and to convert it to string so that I can parse the json definition.
    The errors I ger are highlighted in red.

    Code:
    function json_def as v (e as p)[INDENT]'debug(1)
    
    dim cn as sql::Connection
    cn.Open("::Name::NorthwindMySQL57")
    cn.PortableSQLEnabled = .T.
    
    dim args as sql::Arguments 
    args.Set("whatCustomer","ALFKI")
    
    dim SQLSelect as c
    'SQLSelect is in one single line
    SQLSelect ="select json_object('CustomerID', customers.`customerid`, 'CompanyName',customers.`companyName`, 'City', customers.`City`, 'Country', customers.`Country`, 'orders', (select cast(concat('[',GROUP_CONCAT(json_object('OrderID',orderID, 'CustomerID', `CustomerID`, 'EmployeeID', EmployeeID, 'OrderDate', OrderDate)),']') as JSON) from orders where customers.customerID = orders.customerID)) as json_definition from customers where customers.customerID = :whatCustomer
    
    cn.Execute(SQLSelect, args) 
    cn.ResultSet.nextRow()
    [COLOR=#ff0000]'ERROR: Variable does not contain a valid result set while getting result set next row.'[/COLOR]
    
    dim rs as sql::ResultSet
    rs=cn.ResultSet
    
    dim definitionJson as c
    definitionJson = rs.ToString()
    [COLOR=#ff0000]'ERROR OCCURRED: Database API specific error while converting ResultSet to String Unexpected MySql data type BINARY 245 for colomn json_definition in 'CA5SQLDataTypeInfoMySQL::GetData[/COLOR]
    
    definitionJson = "[" + stritran(definitionJson,crlf(),"," + crlf()) + "]"
    
    cn.Close()
    
    'The goal is to parse the JSON definition so that I would insert it somewhere else
    dim p as p
    p = json_parse(definitionJson)
    dim i as n 
    dim count as n 
    count = p.size()
    
    'more code here
    [/INDENT]
    
    end function
    I'm hoping that someone would be kind enough to test this code & provide some help on why this is occuring! It's been 3 days and I can't figure it out.

    I'll appreciate it
    Thank you

    #2
    Re: How to generate nested Json objects from MySql to resultSet using xBasic?

    Would this help?

    Code:
    function json_def as c (e as p)
    debug(1)
    
    dim ops as p
    ops.connectionString = "::Name::northwind"
    
    ops.sql = <<%txt%
    {sql: 'select CustomerId, CompanyName, City, Country from customers where customerid = :whatCustomer', name: 'customer' }
    	{sql: 'select OrderId, CustomerId, EmployeeId, OrderDate from orders', name: 'orders', parentKey: 'customerid', key: 'customerId'}
    %txt%
    
    dim args as sql::Arguments
    args.set("whatCustomer","ALFKI")
    
    dim jsonObj as p
    jsonObj = a5_sql_nested_query_to_json_document(ops,args)
    dim jsonData as c
    jsonData = jsonObj.data
    
    end function
    This will produce a nested JSON structure. But... I'm not sure it can be parsed into an XBasic pointer variable. What do you want to do with the JSON?

    Comment


      #3
      Re: How to generate nested Json objects from MySql to resultSet using xBasic?

      Thank you David

      You're right! I'm not sure it can be parsed into an xbasic pointer variable either. There's got to be another way to accomplish what I need to do.

      I'm trying to allow users to dynamically generate forms.

      Check out "Understanding custom controls" in the video library specifically video 3 to have an idea about what I'd like to do.

      I thought getting the table definition directly as Json would be easier but I guess I thought wrong. Maybe it's be better to obtain the form definition directly from the database tables:

      Parent Table FIELDS that store form fields (F_ID, fieldName, controlType, fieldLabel, required, allowMultipleSelections)
      child Table FIELDVALUES that store values for checkboxes radiobuttons and dropdowns (FV_ID, F_ID, choice, value)

      I get to generate the form when the control type is textbox by querying only the FIELDS table but when it comes to checkboxes radiobuttons I get confused about how to get there.

      Comment


        #4
        Re: How to generate nested Json objects from MySql to resultSet using xBasic?

        Get in touch with Alpha, Dan has built a form builder. They are Beta testing it at the moment. It supports parent-child relationships. It looks super cool.

        Comment


          #5
          Re: How to generate nested Json objects from MySql to resultSet using xBasic?

          Thanks for the sales pitch Michael! I'm building the form builder according to specific requirements one line code at a time. So far I was able to implement the textbox checkbox and radio button controls dynamically from a parent child relationships tables in a SaaS framework, and it looks hyper super cool too. I like a good challenge and enjoy the satisfaction of overcoming difficult milestones.
          Last edited by Maroine81; 02-07-2017, 04:50 AM.

          Comment


            #6
            Re: How to generate nested Json objects from MySql to resultSet using xBasic?

            Not really a sales pitch it is code written in Alpha. The whole app is built in Alpha.

            https://www.youtube.com/watch?v=kAXt...ature=youtu.be

            I guess it will be available in the next release.

            Comment


              #7
              Re: How to generate nested Json objects from MySql to resultSet using xBasic?

              Oh my bad. The form builder app does look interesting for developers to quickly design forms for their users although I think it's somewhat complicated for the not so savvy end users to design their forms themselves. I might be wrong, will have end users test use it when it becomes available & see how it goes.

              Thanks for sharing.

              Comment


                #8
                Re: How to generate nested Json objects from MySql to resultSet using xBasic?

                I know Alpha are putting a lot of effort into making this as simple as possible. They see this as "computer savvy" user level. So a manager needs a picture of problems in a house. He builds an "app" to capture this data. It is meant to be quick to build quick to use. Some apps will be discarded, some will be developed into house apps after positive feedback.

                Comment


                  #9
                  Re: How to generate nested Json objects from MySql to resultSet using xBasic?

                  Sorry, referring to the original question I have always wondered if you could use the datacache to achieve your objective.

                  Comment


                    #10
                    Re: How to generate nested Json objects from MySql to resultSet using xBasic?

                    Originally posted by Michael1954 View Post
                    Sorry, referring to the original question I have always wondered if you could use the datacache to achieve your objective.
                    If I was allowing users to design their own forms using their mobile devices, I'd seriously consider data cache, but since the form building is only done online with a computer in a web portal, no data cache is needed.

                    Too bad the json_object function in MySQL didn't work well with xbasic to generate the nested JSON objects, It would have been a straight forward solution. The wprk around process was to first get the parent data then get the children data using toPropertyArray() function. After that, associate the children data with the parent data using *array_append() function. Then use json_generate() to get the json definition.

                    Comment


                      #11
                      Re: How to generate nested Json objects from MySql to resultSet using xBasic?

                      Here is a video from Selwyn.

                      http://www.ajaxvideotutorials.com/V1...sidedata_4.swf

                      Comment

                      Working...
                      X