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 string manipulation - replace single quotes with double quotes

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

    Xbasic string manipulation - replace single quotes with double quotes

    I'm using the following to return a delimited list of user groups for the current user.

    dim uname as c
    uname = A5ws_GetCurrentUser()
    session.usergroups = crlf_to_comma(A5WS_Get_User_Assignments(uname))

    This sets session.usergroups to this value (including the single quotes): 'Administrator,User,View Only'

    I need session.usergroups to look like this "Administrator","User","View Only" so I can use it in an IN Clause in an sql statement.

    In using stritran(session.usergroups, ",", "','") I can get the string to look like this 'Administrator","User","View Only'

    However I haven't been able to use strtran to replace the the single quotes at the beginning and end with double quotes? How can I do this please?

    #2
    If I understand what you're trying to accomplish, the code below should work.
    The image below illustrates the results of my code.

    Capture.PNG
    Code:
    session.usergroups = stritran(session.usergroups,"'",chr(34))
    session.usergroups = stritran(session.usergroups,",",chr(34)+","+chr(34))
    Gregg
    https://paiza.io is a great site to test and share sql code

    Comment


      #3
      Thanks but it ends up truncating the string to this: 'Administrator

      Seems to work ok in the immediate window for some reason but not when live.

      Have gone around in circles for some time on this so I'm going to park it for now. Thank you though.

      Comment


        #4
        Post the code you're using. There's probably a reason you come up with something different that what I end up with.
        Gregg
        https://paiza.io is a great site to test and share sql code

        Comment


          #5
          function onTabbedUIInitialize as v (e as p)


          dim uname as c
          uname = A5ws_GetCurrentUser()
          session.usergroups = crlf_to_comma(A5WS_Get_User_Assignments(uname)) 'works

          session.usergroupsForIN = stritran(session.usergroups,"'",chr(34))
          session.usergroupsForIN = stritran(session.usergroupsForIN,",",chr(34)+","+chr(34))


          end function

          Comment


            #6
            Hi Richard,

            Sorry about the delay, but I try to test things.
            CODE A should work for your function as written. I couldn't test exactly because I don't have web security enabled.
            CODE B was designed to immediately show the results.
            I think I nailed what you're trying to accomplish, but if not, please share your thoughts.

            Gregg

            CODE A
            Code:
            function onTabbedUIInitialize as V (e as p)
            
            dim session.usergroups as c
            dim session.usergroupsForIN as c
            dim uname as c
            
            uname = A5ws_GetCurrentUser()
            session.usergroups = A5WS_Get_User_Assignments(uname) 'works
            
            for each u in session.usergroups
            session.usergroupsForIN = session.usergroupsForIN + sql_quote(u.value) + crlf()
            next
            session.usergroupsForIN = crlf_to_comma(session.usergroupsForIN)
            
            end function
            CODE B
            Code:
            function onTabbedUIInitialize as c (e as p)
            ' This is the one I did the testing with. I set e.name = "Gregg98188" to call the function
            dim session.usergroups as c
            dim session.usergroupsForIN as c
            dim uname as c
            
            if e.name = "Gregg98188" then
            session.usergroups = <<%str%
            Administrators
            Users
            View Only
            %str%
            
            else
            uname = A5ws_GetCurrentUser()
            session.usergroups = A5WS_Get_User_Assignments(uname) 'works
            end if
            
            'debug(1)
            for each u in session.usergroups
            session.usergroupsForIN = session.usergroupsForIN + sql_quote(u.value) + crlf()
            playwithitnow = .t.
            next ' u
            session.usergroupsForIN = crlf_to_comma(session.usergroupsForIN)
            
            onTabbedUIInitialize = session.usergroupsForIN
            
            end function
            Gregg
            https://paiza.io is a great site to test and share sql code

            Comment


              #7
              Thanks.

              I tried CodeA which is close but it seems to keep putting a single quote at the beginning and end so I end up with '''Administrator'',''User''' for example.

              So I added another strtran function but still no luck.

              Here is the full code.

              dim session.usergroups as c
              dim session.usergroupsForIN as c
              dim uname as c

              uname = A5ws_GetCurrentUser()
              session.usergroups = A5WS_Get_User_Assignments(uname) 'works

              for each u in session.usergroups
              session.usergroupsForIN = session.usergroupsForIN + sql_quote(u.value) + crlf()
              next
              session.usergroupsForIN = crlf_to_comma(session.usergroupsForIN)

              'this is the line I added to try to eradicate the single quote at beginning and end but it gets rid of all of the double quotes and the result is 'Administrator,User'
              session.usergroupsForIN = stritran(session.usergroupsForIN,chr(39),"")



              Comment


                #8
                I added one more part that matches what I'm understanding as shown in the lower part of the image below.
                This has me confused because it goes against every bit of sql I've written.
                Just to satisfy my curiosity, could you share the where section of the working sql code .
                I am sure I can generate what you need.
                Code:
                select *
                from usertable
                where usergroup in ('Administrators','Users','View Only')
                Capture.PNG
                Capture.PNG
                Gregg
                https://paiza.io is a great site to test and share sql code

                Comment


                  #9
                  For simple sql sharing, I threw a quick table up at https://paiza.io/projects/p01U3NVPwMwxoFYNRCuCgw?language=mysql

                  Gregg
                  https://paiza.io is a great site to test and share sql code

                  Comment


                    #10
                    Ugly solution, but I think it works..

                    If you use

                    session.groups = A5WS_Get_User_Assignments(uname)

                    you can then use my_result = """+stritran(session.groups,crlf(),"","")+""" to build the required string

                    Comment


                      #11
                      I'm guessing you're setting up some kind of sql statement.
                      Can you share what that statement should look like ?
                      Gregg
                      https://paiza.io is a great site to test and share sql code

                      Comment


                        #12
                        To view the result of the code I'm setting the Initial Value of the quick search field in the grid to session.usergroupsForIN and it looks like this: '''Administrator'',''Hosp1","Hosp2'''

                        I am also using session.usergroupsForIN in the AlphaDAO SQL SELECT Statement for the dynamic choices in a drop down field in the same grid. The SQL code looks like this:

                        SELECT
                        Hospital
                        FROM tblCodeHospitals
                        WHERE Hospital IN (session.usergroupsForIN)

                        Note: The whole reason for trying to build the string for the IN clause is that when setting up the choices for the drop down you can create an argument but you don't seem to be able to set its value to a session variable, whereas you can in other parts of alpha such as the query for the grid's recordset. If I could do this I could use an array_argument just fine.

                        I'm using V4.6.2.9 - 7564-5566 21 MAR-2021


                        Comment


                          #13
                          You might have to make some minor adjustments for your project but the should work.
                          The code above union all in the image shown displays all the data in the table.
                          The code below union all shows the results using arguments in the where section.

                          Capture.PNG
                          Code:
                          dim itWorked as L ' this is used to determine if the sql executed successfully
                          args.set("A","Administrators")
                          args.set("B","Hosp1")
                          args.set("C","Hosp2")
                          sqlCode = <%txt%
                          select hospital
                          from tblCodeHospitals
                          where hospital in (:A,:B,:C)
                          <%txt%>
                          cn.open(sqlConnection)
                          itWorked = cn.execute(sqlCode,args)
                          Gregg
                          https://paiza.io is a great site to test and share sql code

                          Comment

                          Working...
                          X