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

Method to collect session variables

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

    Method to collect session variables

    I've been using a codepage that I redirect users to when they login in order to set session variables. I've been using the sql_lookup() function to set several variables which I've been told is not the best practice and slows down the login process due to the fact that the function is opening and closing the connection to the database each time I am doing the lookup. I am trying to change my methodology but I'm doing something wrong.

    I'm using this script. I receive the error "function sequence error while getting result set data column 'FirstName'. Any help is appreciated.

    Code:
    dim conn as SQL::Connection
    dim args as SQL::Arguments
    dim sql as C
    dim rs as SQL::ResultSet
    
    args.set("userid",session.userid)
    sql = "SELECT * FROM Users where users_id = :userid"
    
    
    conn.Open("::name::MYDS")
    
    conn.Execute(sql,args)
    rs = conn.ResultSet
    
    dim session.firstname as C=rs.data("FirstName")
    dim session.lastname as C=rs.data("LastName")
    dim session.id as N=rs.data("users_id")
    dim session.bldrcode as C=rs.data("bldrcode")
    dim session.fullname as C=alltrim(session.firstname) + " " + alltrim(session.lastname)
    
    conn.FreeResult()

    #2
    Re: Method to collect session variables

    Hi,

    Have you tried specifying the field you want rather than using "Select * ". (That's what I usually do)

    (Good tip, I'm now going to replace SQL_Lookup in my login processing page)

    Cheers

    Comment


      #3
      Re: Method to collect session variables

      see this thread https://forum.alphasoftware.com/show...l=1#post661830
      Frank

      Tell me and I'll forget; show me and I may remember; involve me and I'll understand

      Comment


        #4
        Re: Method to collect session variables

        Josh,
        You have not closed the connection (not that this is your problem, as Frank has indicated):
        conn.close()
        conn.freeResult() does not close the connection.
        Also, I do not think that every call of sql_lookup() opens and closes the connection!! I am interested to know where you got that info from.

        Comment


          #5
          Re: Method to collect session variables

          Hi Josh,

          Like Peter mentioned, it is also more efficient to only specify the fields that you want. For example:

          sql = "SELECT FirstName, LastName, users_id, bldrcode FROM Users where users_id = :userid"

          You need to first position the result set to the first row before calling the "Data" method. You need to check the result of "NextRow" to make sure there is at least one row. "NextRow" will return .T. if you are positioned on a valid row and .F. if not. I have experienced interimittent problems using the debugger when there is only one row in the record set. It does not always return .T. when there is only one row. The example below is a way to counter this problem:

          conn.Execute(sql,args)
          rs = conn.ResultSet
          rs.NextRow()

          if .not. eval_valid("rs.data(1)")
          ' Show Error
          exit function
          end if

          dim session.firstname as C=rs.data("FirstName")
          dim session.lastname as C=rs.data("LastName")
          dim session.id as N=rs.data("users_id")
          dim session.bldrcode as C=rs.data("bldrcode")
          dim session.fullname as C=alltrim(session.firstname) + " " + alltrim(session.lastname)

          conn.Close()

          Comment


            #6
            Re: Method to collect session variables

            Also, I do not think that every call of sql_lookup() opens and closes the connection!!
            Hhmm.. Why wouldn't it close the connection? If that is the only code in a script or function, do you believe that Alpha would just leave the connection open "forever"? That wouldn't make sense.
            Peter
            AlphaBase Solutions, LLC

            [email protected]
            https://www.alphabasesolutions.com


            Comment


              #7
              Re: Method to collect session variables

              sql_lookup() takes either a string containing a connection string or an open sql::connection as the first argument.

              If you supply a connection string, sql_lookup() opens and the closes a connection.

              If you supply an sql::connection, that connection is used directly and is neither opened nor closed by sql_lookup(). This allows you to open a connection externally and reuse it across sql_lookup() calls.

              Lenny Forziati
              Vice President, Internet Products and Technical Services
              Alpha Software Corporation

              Comment


                #8
                Re: Method to collect session variables

                I think I mentioned that sql_lookup opens and closes the connection because Josh was using a connection string and not an open connection object. He was also calling sql_lookup 10 or more times to get one field at a time so I recommended opening the connection and using SQL::Connection::Execute instead.
                Last edited by DaveF; 12-19-2013, 11:20 AM.

                Comment


                  #9
                  Re: Method to collect session variables

                  Thank you all for your responses. Dave, can you tell me if this looks correct now? I am receiving the same error. It works in the interactive window when I hard set the session variable but I get a function sequence error when running it progromatically.

                  Code:
                  dim conn as SQL::Connection
                  dim rs as SQL::ResultSet
                  dim args as SQL::Arguments
                  dim sql as c
                  
                  args.set("userid",session.userid)
                  sql = "SELECT FirstName, LastName, users_id, bldrcode FROM Users where users_id = :userid"
                  conn.Open("::name::MYDS")
                  conn.Execute(sql,args)
                  rs = conn.ResultSet
                  rs.NextRow()
                  
                  if .not. eval_valid("rs.data(1)")
                  ' Show Error
                  exit function
                  end if
                  
                  dim session.firstname as C=rs.data("FirstName")
                  dim session.lastname as C=rs.data("LastName")
                  dim session.id as N=rs.data("users_id")
                  dim session.bldrcode as C=rs.data("bldrcode")
                  dim session.fullname as C=alltrim(session.firstname) + " " + alltrim(session.lastname)

                  Comment


                    #10
                    Re: Method to collect session variables

                    So in the debugger you can step through the code and it executes the rs.data("FirstName") correctly and sets session.firstname correctly to the value of the first name? How about if you remove the dim and just do the following?

                    session.firstname = rs.data("FirstName")

                    Comment


                      #11
                      Re: Method to collect session variables

                      As a result of this thread I replaced about 20 SQL_Lookup()s in one of my login processing pages with code basically the same as yours. Except as DaveF suggested without the Dim. Login performance improved significantly (no surprise). I did get the same error as you when I had a syntax error in the SQL.

                      Maybe try and simplify and see if you can get only the FirstName field from the users table.

                      Comment


                        #12
                        Re: Method to collect session variables

                        Peter,

                        Hhmm.. Why wouldn't it close the connection? If that is the only code in a script or function, do you believe that Alpha would just leave the connection open "forever"? That wouldn't make sense.
                        If sql_lookup is using "c as a pointer to an open connection" (see http://wiki.alphasoftware.com/~alpha...ookup+Function) why would it be opening and closing? If you don't close() a connection then yes I believe it will remain open, otherwise, why have the close() function?
                        My habit is to open connection, do sql lookups, close connection.

                        As Lenny says
                        If you supply an sql::connection, that connection is used directly and is neither opened nor closed by sql_lookup(). This allows you to open a connection externally and reuse it across sql_lookup() calls.

                        Comment


                          #13
                          Re: Method to collect session variables

                          Hi,

                          I was supplying a connection string for each SQL_Lookup so I assume it would open and close each time. As the file grew that became silly so I changed it as above. Yes if you used an SQL::Connection for SQL_Lookup then that would probably be fine, not that I have tried that.

                          I'm still learning

                          Cheers

                          Comment


                            #14
                            Re: Method to collect session variables

                            Garry

                            If you pass in an open connection pointer as Lenny says, I understand it does stay open. Funny thing is, I have never been able to get that method to work for me. Which is why I have always explicitly opened the connection in the lookup as in this method:

                            Code:
                            Dim args as SQL::Arguments
                            
                            
                            conn = "::Name::System"
                            table = "Defaults"
                            result = "DefValue"
                            filter = "DefId = " + vDefaultID
                            
                            
                            GetValue= sql_lookup(conn,table,filter,result,args)
                            Peter
                            AlphaBase Solutions, LLC

                            [email protected]
                            https://www.alphabasesolutions.com


                            Comment


                              #15
                              Re: Method to collect session variables

                              I just tried it with a pointer to an open connection object and it left the connection open as expected.

                              Code:
                              dim cn as sql::Connection
                              dim result as l
                              dim value as c 
                              result = cn.Open("::Name::My Database")
                              
                              value = sql_lookup(cn, "Users", "UserId = 'Test'", "UserId")
                              cn.Close()
                              However, if you pass a connection string, I would expect sql_lookup to open a second connection to the database and then close it:

                              Code:
                              dim cn as sql::Connection
                              dim result as l
                              dim value as c 
                              result = cn.Open("::Name::My Database")
                              
                              value = sql_lookup("::Name::My Database", "Users", "UserId = 'Test'", "UserId")
                              cn.Close()

                              Comment

                              Working...
                              X