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

Show Results of Xbasic SQL Query in UX

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

  • Show Results of Xbasic SQL Query in UX

    Hi all,

    I'm tying to make my own "SQL Genie" to allow select commands only and make it available to certain users of my application. I've got it working in so far as they can pick a database, select a table and select columns from that table. What I'm trying to figure out is the best and fastest way to display the query results to the user in a table format so that they can copy and paste them. Basically just like MSSQL server management studio would or like the built in alpha genie does when building a component.

    A list doesn't seem to work because there is no way I can find to easily and dynamically change the fields and layout.

    If I loop through the result set, it get's really slow so I don't want to build the HTML or something that way.

    There are some handy xbasic functions available:
    Result Set.......
    .ToString()
    .ToCSV()
    .ToJSON
    .ToJSONObjectSyntax()

    etc....

    They look interesting and they seem to work quickly.

    I'm just having trouble getting that data formatted correctly for the users to see and manipulate on my UX

    Any ideas?
    Last edited by -Jinx-; 05-14-2015, 12:39 PM.

  • #2
    Re: Show Results of Xbasic SQL Query in UX

    I have been fighting with a very similar problem for months. The only solution I have found so far is to run the query using Xbasic, put the results in two tables (header for column names and detail for data) with generic column names and then build a report on those tables. The result is not very pretty - made worse by the fact that alpha reports translate nulls in numeric fields into zeros on the report. If you find another solution, I would love to hear about it in detail.

    Comment


    • #3
      Re: Show Results of Xbasic SQL Query in UX

      Well,
      I have it working good enough to debug it. It's still pretty slow when the query has a lot of results but if you filter it, it works OK.

      I ended up having Xbasic write some javascript to populate the inner html of a div with a table. The table is pretty basic right now but it has dynamic column names in the table head and a column left for the row number. I'm working on getting it to look more like MSSQL management studio with results and stuff.

      I wish I knew the methods Alpha 5 is using to pull results for grids and lists and such and if they were exposed somewhere. That would be much nicer.

      One of the reasons that it's so slow is that I have to not only convert the result set using .ToJSONObjectSyntax() but I have to use crlf_to_comma() to convert that from crlf delimited to comma delimited (or it won't work in JavaScript) and then I have to js_escape() it because there might be stuff in the sql that javascript doesn't like. Shouldn't .ToJSONObjectSyntax() just DO that?
      Last edited by -Jinx-; 05-15-2015, 02:41 PM.

      Comment


      • #4
        Re: Show Results of Xbasic SQL Query in UX

        Shouldn't .ToJSONObjectSyntax() just DO that?
        actually in version 11, which is what I have, rs.toJSONObjectSyntax produces single quoted values which are not good as they are not standard. I have to convert not only crlf_to_comma and then single quotes to double quotes. (for example {"name":'gandhi'})
        it is lot easier for me to write directly to json object syntax myself sometimes, without worrying about converting a string to some other string.

        however so far I have not found writing to a table being slow. or may be my dataset is small.
        thanks for reading

        gandhi

        version 11 3381 - 4096
        mysql backend
        http://www.alphawebprogramming.blogspot.com
        ggandhi344@gmail.com
        Skype:ggandhi344@gmail.com
        1 914 924 5171

        Comment


        • #5
          Re: Show Results of Xbasic SQL Query in UX

          Originally posted by GGandhi View Post
          however so far I have not found writing to a table being slow. or may be my dataset is small.
          Hi Gandhi,
          Yeah, I tried to loop through the result set instead of using one of the functions described above but it got really slow at some point. I'm not sure the exact number of records. Using the functions is faster but it's still slow with a large set.

          I've got another issue. For some reason the table styling is affecting my whole page. I need to figure out how not to do that. Stick this code in a button on a UX and make sure you have a edit combo box on it somewhere. That should reproduce the issue of the edit combo box getting a border when clicking the button. On a tabbed UI it's even worse. Lots of stuff magically gets borders.

          Anyway, here is the snippet of JavaScript code that my Xbasic sends back to my client.
          Code:
          var data = '[{"tnumber" : "06900", "file_location" : "P:\\\\Secured\\\\ReleasedPDF\\\\Tooling\\\\069\\\\06900.pdf"},\n{"tnumber" : "06901", "file_location" : "P:\\\\Secured\\\\ReleasedPDF\\\\Tooling\\\\069\\\\06901.pdf"},\n{"tnumber" : "06902", "file_location" : "P:\\\\Secured\\\\ReleasedPDF\\\\Tooling\\\\069\\\\06902.pdf"},\n{"tnumber" : "06903", "file_location" : "P:\\\\Secured\\\\ReleasedPDF\\\\Tooling\\\\069\\\\06903.pdf"},\n{"tnumber" : "06904", "file_location" : "P:\\\\Secured\\\\ReleasedPDF\\\\Tooling\\\\069\\\\06904.pdf"},\n{"tnumber" : "06905", "file_location" : "P:\\\\Secured\\\\ReleasedPDF\\\\Tooling\\\\069\\\\06905.pdf"},\n{"tnumber" : "06906", "file_location" : "P:\\\\Secured\\\\ReleasedPDF\\\\Tooling\\\\069\\\\06906.pdf"},\n{"tnumber" : "06907", "file_location" : "P:\\\\Secured\\\\ReleasedPDF\\\\Tooling\\\\069\\\\06907.pdf"},\n{"tnumber" : "06908", "file_location" : "P:\\\\Secured\\\\ReleasedPDF\\\\Tooling\\\\069\\\\06908.pdf"},\n{"tnumber" : "06909", "file_location" : "P:\\\\Secured\\\\ReleasedPDF\\\\Tooling\\\\069\\\\06909.pdf"},\n{"tnumber" : "06910", "file_location" : "P:\\\\Secured\\\\ReleasedPDF\\\\Tooling\\\\069\\\\06910.pdf"}]';
          var obj = JSON.parse(data);
          var inhtml = '<style>table, th, td {border: 1px solid black;border-collapse: collapse;}th,td{padding: 5px;}</style><table style=width:100%><tr><th></th><th>tnumber</th><th>file_location</th></tr>'
          for (i = 0; i <11; i++){
          inhtml = inhtml + '<tr><td>' + i +'</td><td>' + obj[i].tnumber+'</td><td>' + obj[i].file_location+'</td></tr>';
          }
          inhtml = inhtml + '</tr></table>';
          $('RESULTS').innerHTML= inhtml;
          $('MESSAGE').innerHTML= 'Success<br>11: Row(s) Affected';
          {dialog.object}.showContainerWindow(this,'WINDOW_1');
          You will need two divs on the page for this info to get into.

          Code:
          <div id = "MESSAGE"></div>
          <div id = "RESULTS"></div>

          Comment


          • #6
            Re: Show Results of Xbasic SQL Query in UX

            BTW, if I clear the inner HTML of the div that the table is in when I close the window, the page returns to normal. Maybe this is just something about CSS that I don't get. I know next to nothing about it.

            Comment


            • #7
              Re: Show Results of Xbasic SQL Query in UX

              I tested your code it does not take a lot of time either in a dialog or in an a5w page, I am trying to beautify the table by alternating color somehow not yet possible.
              I will try some more and let you know.
              edit:
              I can alternate the colors but I am not sure what is your end results would be.
              Last edited by GGandhi; 05-15-2015, 08:53 PM.
              thanks for reading

              gandhi

              version 11 3381 - 4096
              mysql backend
              http://www.alphawebprogramming.blogspot.com
              ggandhi344@gmail.com
              Skype:ggandhi344@gmail.com
              1 914 924 5171

              Comment


              • #8
                Re: Show Results of Xbasic SQL Query in UX

                Originally posted by GGandhi View Post
                I tested your code it does not take a lot of time either in a dialog or in an a5w page, I am trying to beautify the table by alternating color somehow not yet possible.
                I will try some more and let you know.
                edit:
                I can alternate the colors but I am not sure what is your end results would be.
                That code is fast. It's the XBasic that creates the JavaScript above which is slow with a lot of rows.

                Comment


                • #9
                  Re: Show Results of Xbasic SQL Query in UX

                  Would you please show that portion and how you are getting the result?
                  thanks for reading

                  gandhi

                  version 11 3381 - 4096
                  mysql backend
                  http://www.alphawebprogramming.blogspot.com
                  ggandhi344@gmail.com
                  Skype:ggandhi344@gmail.com
                  1 914 924 5171

                  Comment


                  • #10
                    Re: Show Results of Xbasic SQL Query in UX

                    Originally posted by GGandhi View Post
                    Would you please show that portion and how you are getting the result?
                    I'll post the relevant portion when I get back to work.

                    The XBasic puts the table information into the 'data' variable in the above code. The more results you get from your query, the bigger the data variable gets. At around 7,000 rows of data, it takes about 8 seconds to run the XBasic, and another 5 to run the JavaScript. It goes up exponentially as you add columns and rows.

                    Comment


                    • #11
                      Re: Show Results of Xbasic SQL Query in UX

                      just the code segment or sample where you get the data from your server after the connection string, for example the sql statement, I think.
                      I am wondering why it should take 8 seconds because all sql servers do the query in milliseconds.

                      edit: or there may be problem before the code goes to the server?
                      Last edited by GGandhi; 05-16-2015, 12:11 PM.
                      thanks for reading

                      gandhi

                      version 11 3381 - 4096
                      mysql backend
                      http://www.alphawebprogramming.blogspot.com
                      ggandhi344@gmail.com
                      Skype:ggandhi344@gmail.com
                      1 914 924 5171

                      Comment


                      • #12
                        Re: Show Results of Xbasic SQL Query in UX

                        The SQL is fast, it's the XBasic operations that I need to perform on the result set in order to make the JSON string for the 'data' variable that's slow.

                        Comment


                        • #13
                          Re: Show Results of Xbasic SQL Query in UX

                          it's the XBasic operations that I need to perform on the result set
                          this is what confusing me.
                          it is just one operation to convert to json syntax. then fill in what alpha should have done correct to start with to fit your need.
                          anyway you can post whatever you feel right when you get back to work.
                          thanks for reading

                          gandhi

                          version 11 3381 - 4096
                          mysql backend
                          http://www.alphawebprogramming.blogspot.com
                          ggandhi344@gmail.com
                          Skype:ggandhi344@gmail.com
                          1 914 924 5171

                          Comment


                          • #14
                            Re: Show Results of Xbasic SQL Query in UX

                            Originally posted by GGandhi View Post
                            this is what confusing me.
                            it is just one operation to convert to json syntax. then fill in what alpha should have done correct to start with to fit your need.
                            anyway you can post whatever you feel right when you get back to work.
                            You really need to try it with a large amount of returned rows to see the speed difference. Just getting the result set itself (coverting it to Xbasic from SQL or whatever Alpha does behind the scenes) takes a long time.

                            In the code below, I have a timer that gets the current time before the Xbasic runs and then the time just before it exits the Xbasic. It finds the difference and gives that to you as "Elapsed Time"

                            Here is an exerpt of the code that I think you can work with.

                            columns comes in as an array of data for me as the individual columns that are part of the query.

                            You should be able to play with this as you like. I haven't had time to optimize or clean up the code yet, so it's still a little messy.

                            Code:
                            function GetResult as c (e as p)
                            
                            	
                            dim stm as c = time()
                            dim t1 as Y = ctot(stm)
                            
                            dim result as c
                            dim results as c
                            dim inhtml as c = "'<style>table, th, td {border: 1px solid black;border-collapse: collapse;}th,td{padding: 5px;}</style><table style=width:100%><tr><th></th>"
                            dim cmd as c
                            dim db as c
                            dim table as c
                            dim columns as p = e.dataSubmitted.COLUMNS
                            dim cnt as n = 0
                            dim callres as c
                            dim cn as SQL::Connection
                            dim args as SQL::Arguments
                            	if cn.open("::Name::")	then
                            		dim sqlCmd as c = cmd
                            		if cn.Execute(sqlCmd) then
                            			dim rs as SQL::ResultSet
                            			rs = cn.ResultSet
                            				if rs.NextRow() then
                            					result = rs.ToJSONObjectSyntax()
                            					cnt = w_count(result,chr(13))
                            					results = "["
                            						for i = 1 to cnt
                            							results = results + word(result,i,chr(13)) + crlf()
                            						next
                            					results = crlf_to_comma(results)
                            					results = js_escape(results)
                            					results = "var data = '" + results
                            					results = results + "]';" + crlf()+ "var obj = JSON.parse(data);"
                            					if columns[1] <> "" then
                            						clmcnt = columns.SIZE()
                            							for i = 1 to clmcnt
                            								inhtml = inhtml + "<th>" + columns[i] + "</th>"
                            							next
                            						inhtml = inhtml + "</tr>'"
                            						results = results  + crlf() + "var inhtml = " + inhtml + crlf() + "for (i = 0; i <"+cnt+"; i++){" + crlf() + "inhtml = inhtml + '<tr><td>' + i +'</td>"
                            							for i = 1 to clmcnt
                            								results = results + "<td>' + obj[i]."+columns[i]+"+'</td>"
                            							next
                            						results = results + "</tr>'" + ";" + crlf() + "}"+ crlf() + "inhtml = inhtml + '</tr></table>';" + crlf() + "$('RESULTS').innerHTML= inhtml;"
                            					end if
                            				end if
                            		end if
                            	end if
                            
                            
                            dim ftm as c = time()
                            dim t2 as Y = ctot(ftm)
                            dim qt as N = (t2 - t1)
                            
                            callres = js_escape(cn.CallResult.Text)
                            results = results + crlf() + "$('MESSAGE').innerHTML= '" + callres + "<br>Elapsed Time: " + qt +" Sec <br>" + cnt + ": Row(s) Affected" + "';"
                            results = results + crlf() +"{dialog.object}.showContainerWindow(this,'WINDOW_1');"
                            	if cn.CallResult.Text <> "Success" then
                            		results = results + crlf() + "{grid.object}.selectTabPane('TAB_1','Messages');"
                            	end if
                            	
                            debug(1)
                            
                            GetResult= results
                            end function

                            Comment


                            • #15
                              Re: Show Results of Xbasic SQL Query in UX

                              yes there are lots of things going on in your code
                              result = rs.ToJSONObjectSyntax()
                              what doeS that return? it seems that you are working too much on the resultset to me
                              I am not sure why you need cnt.
                              thanks for reading

                              gandhi

                              version 11 3381 - 4096
                              mysql backend
                              http://www.alphawebprogramming.blogspot.com
                              ggandhi344@gmail.com
                              Skype:ggandhi344@gmail.com
                              1 914 924 5171

                              Comment

                              Working...
                              X