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 SQL "UPDATE" syntax help

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

    XBasic SQL "UPDATE" syntax help

    I need a xbasic function that will update a SQL BIT field in a specific row (in a different table/grid than this xbasic function is in) when two values match. Value A is in the grid-detail view where this xbasic function is and value B is in the table that this xbasic function will update....I hope that wasn't too convoluted ...

    I want the function to fire after a record is saved .... so I'd write this function in the 'AfterUpdateRecord' server-side event, right?

    Below is something I came up with ...I know it isn't right. The script should update the 'Assessment_Screening' field in the patient table to a value of 1 where the 'Patient_ID_Num' field in the detail view (where this xbasic function is located) equals the ID field in the row I want updated.


    Code:
    'The below script sends the data to the Patient Table
    function Send_to_Patient_Table as c (e as p)
    
    dim cn as sql::connection
    cn.Open("::Name::SQL") 'saved connection string
    dim args as sql::arguments
    
    cn.Execute("UPDATE Patient (Assessment_Screening) WHERE e.DataSubmitted.Patient_ID_Num = dbo.PATIENT.Id, VALUE ('1')", )
    
    cn.close()
    
    end function
    Mike Brown - Contact Me
    Programmatic Technologies, LLC
    Programmatic-Technologies.com
    Independent Developer & Consultant​​

    #2
    Re: XBasic SQL "UPDATE" syntax help

    Code:
    FUNCTION an_ajax_callback as c (e as p)
    
    dim sql as c = "UPDATE table_name SET field_name1 = :new_field1_value, field_name2 = :new_field2_value WHERE my_field_pk = :primary_key"
    dim args as sql::arguments
    args.set("new_field1_value","this is a string")
    args.set("new_field2_value",12)
    args.set("primary_key",e.dataSubmitted.PRIMARY_KEY)
    
    dim cn as sql::connection
    if (cn.open("::Name::SQL")) then
      if (cn.execute(sql,args)) then
        'success
      else
       'failure
        an_ajax_callback = "alert('" + js_escape(cn.callResult.text) + "');"
      end if
      cn.close()
    else
      an_ajax_callback = "alert('Unable to open connection');"
    end if
    
    END FUNCTION
    What DBMS are you using?
    Alpha Anywhere latest pre-release

    Comment


      #3
      Re: XBasic SQL "UPDATE" syntax help

      SQL Server Management Studio (for SQL 2012)

      Thanks for the code!
      Mike Brown - Contact Me
      Programmatic Technologies, LLC
      Programmatic-Technologies.com
      Independent Developer & Consultant​​

      Comment


        #4
        Re: XBasic SQL "UPDATE" syntax help

        Originally posted by mikeallenbrown View Post
        SQL Server Management Studio (for SQL 2012)

        Thanks for the code!
        The SQL::Connection object has a property: PortableSQLEnabled

        PortableSQLEnabled is, by default, False (.f.). If you set it to true (.t.), then Portable SQL syntax rules apply.

        Otherwise, you can write MSSQL syntax and it will work just fine. Here's some links about writing UPDATE statements in MSSQL:

        http://msdn.microsoft.com/en-us/libr...=vs.80%29.aspx
        http://stackoverflow.com/questions/2...ing-sql-server

        Unless you're writing portable SQL syntax, your best bet will be the MSSQL documentation for syntax for writing SQL statements. ;)

        Good Luck!
        ---
        Sarah
        Alpha Anywhere latest pre-release

        Comment


          #5
          Re: XBasic SQL "UPDATE" syntax help

          http://wiki.alphasoftware.com/Learni...20SQL%20Tables

          this is from alphapedia, all information regarding sql and xbasic can be found here.
          I want the function to fire after a record is saved .... so I'd write this function in the 'AfterUpdateRecord' server-side event, right?
          that function is better called onAfterSqlCommandExecute event in the server side. there you can check if this event successfully inserted into the first table then you can go ahead and insert or update the data in the second table. if there were any problems then you can skip the second insertion/update.
          thanks for reading

          gandhi

          version 11 3381 - 4096
          mysql backend
          http://www.alphawebprogramming.blogspot.com
          [email protected]
          Skype:[email protected]
          1 914 924 5171

          Comment


            #6
            Re: XBasic SQL "UPDATE" syntax help

            I must not have done this right.... I wrote the below code and then added an ajax callback to my submit button. Not only is the 'Patient' table not updated but I don't receive an error either.

            Code:
            FUNCTION Send_To_Patient_Table as c (e as p)
            
            dim sql as c = "UPDATE Patient SET Assessment_Screening = :arg1, WHERE ID = :arg2"
            dim args as sql::arguments
            args.set("arg1",1)
            args.set("arg2",e.dataSubmitted.Patient_ID_Num)
            
            dim cn as sql::connection
            if (cn.open("::Name::SQL")) then
              if (cn.execute(sql,args)) then
                'success
              else
               'failure
                Send_To_Patient_Table = "alert('" + js_escape(cn.callResult.text) + "');"
              end if
              cn.close()
            else
              Send_To_Patient_Table = "alert('Unable to open connection');"
            end if
            
            END FUNCTION
            Mike Brown - Contact Me
            Programmatic Technologies, LLC
            Programmatic-Technologies.com
            Independent Developer & Consultant​​

            Comment


              #7
              Re: XBasic SQL "UPDATE" syntax help

              dim sql as c = "UPDATE Patient SET Assessment_Screening = :arg1, WHERE ID = :arg2"
              remove the comma in red and see if it works
              thanks for reading

              gandhi

              version 11 3381 - 4096
              mysql backend
              http://www.alphawebprogramming.blogspot.com
              [email protected]
              Skype:[email protected]
              1 914 924 5171

              Comment


                #8
                Re: XBasic SQL "UPDATE" syntax help

                No joy...same result

                Let me back up and clarify what I want the function to do (in case my explanation above was confusing):

                Update the "Assessment_Screening" field in the Patient table to 'True' where the field "Patient_ID_Num" in the AssessmentScreening table is equal to "ID" in the Patient table.

                This xbasic function is located in a grid/detail-view component associated with the 'AssessmentScreening' table.

                Also, I found an error in my args .... arg1 should be "True" since Assessment_Screening is a BIT field. Even after changing to "True" the code isn't doing anything.
                Mike Brown - Contact Me
                Programmatic Technologies, LLC
                Programmatic-Technologies.com
                Independent Developer & Consultant​​

                Comment


                  #9
                  Re: XBasic SQL "UPDATE" syntax help

                  Why not use a trigger?
                  Gary S. Traub, Ph.D.

                  Comment


                    #10
                    Re: XBasic SQL "UPDATE" syntax help

                    since Assessment_Screening is a BIT field
                    Code:
                    dim sql as c = "UPDATE Patient SET Assessment_Screening = 1 WHERE ID = :arg2"
                    in that case you don't need another argument, just set to 1
                    thanks for reading

                    gandhi

                    version 11 3381 - 4096
                    mysql backend
                    http://www.alphawebprogramming.blogspot.com
                    [email protected]
                    Skype:[email protected]
                    1 914 924 5171

                    Comment


                      #11
                      Re: XBasic SQL "UPDATE" syntax help

                      If it helps, I always use Alpha's Sql UpdateStatement Object to handle updates, which does not require setting the native sql flag. The sample below is a function taken from a working application.

                      One other point, if you use ON ERROR, error_generate(), and error_text_get() instead of individual js alerts, you can trap all errors within your function
                      Code:
                      function SampleFunction as c (e as p)
                      
                      ON ERROR GOTO ERRORSendClosingDocs
                      
                      '*******************************
                      'update the database
                      '*******************************
                      dim sql as c = ""
                      dim upd as SQL::UpdateStatement
                      dim cn as sql::Connection
                      
                      sql = <<%sql%
                      UPDATE [MY TABLE]
                      SET CURRENT_PROC_STATUS = 'Completed', 
                      TIME_FINAL_PROC = getdate()
                      WHERE CLS_APP_DATA_ID = :AppDataID;"
                      %sql%
                      
                      upd.Arguments.set("appDataID",e._currentRowDataNew.CLS_APP_DATA_ID)  'this is for a grid, change as appropriate for a ux
                      
                      'test the sql
                      if .not. upd.parse(sql) then
                      	error_generate("Could not update the database- the update statement is invalid: "+upd.CallResult.text)
                      end if
                      
                      'open the connection
                      if .not. cn.open("::Name::[My DB NAME]") then
                      	error_generate("Could not open the connection to update the database: "+cn.CallResult.text)
                      end if
                      
                      'execute the update statement
                      if .not. upd.Execute(cn) then
                      	cErr = cn.CallResult.text
                      	cn.Close()
                      	error_generate("Could not update the database: "+cErr)
                      end if
                      'close the connection
                      cn.Close()
                      
                      SampleFunction = "alert('Success');"
                      
                      exit function
                      
                      '*******************************
                      'error handling
                      '*******************************
                      ERRORSendClosingDocs: 
                      on error goto next
                      SampleFunction = "alert('"+js_escape(error_text_get())+"');"
                      
                      end function
                      Last edited by marvinbase; 02-27-2014, 12:45 PM.

                      Comment


                        #12
                        Re: XBasic SQL &quot;UPDATE&quot; syntax help

                        Originally posted by drgarytraub View Post
                        Why not use a trigger?
                        Because I'm a SQL novice (and xbasic novice ...) and it didn't occur to me that a SQL trigger is probably what is best. I asked about this in a separate forum: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=192302
                        Mike Brown - Contact Me
                        Programmatic Technologies, LLC
                        Programmatic-Technologies.com
                        Independent Developer & Consultant​​

                        Comment


                          #13
                          Re: XBasic SQL &quot;UPDATE&quot; syntax help

                          okay I made a little screencast to show you finally I am able to update the mssql table with logical field defined as bit.
                          the trick is to declare the logical field in alpha as logical and assign a value of "True" or "False"
                          then it works well
                          here take a look:
                          http://screencast.com/t/75bBWa5O
                          thanks for reading

                          gandhi

                          version 11 3381 - 4096
                          mysql backend
                          http://www.alphawebprogramming.blogspot.com
                          [email protected]
                          Skype:[email protected]
                          1 914 924 5171

                          Comment


                            #14
                            Re: XBasic SQL &quot;UPDATE&quot; syntax help

                            Thank you ...I'll check it out.
                            Mike Brown - Contact Me
                            Programmatic Technologies, LLC
                            Programmatic-Technologies.com
                            Independent Developer & Consultant​​

                            Comment


                              #15
                              Re: XBasic SQL &quot;UPDATE&quot; syntax help

                              Mike,

                              Dr Gary is right, triggers are great things.

                              I think the reason your code didn't work is that e.dataSubmitted.Patient_ID_Num returns a character value and your ID field is numeric.
                              Code:
                              args.set("arg2",[COLOR="#FF0000"]convert_type([/COLOR]e.dataSubmitted.Patient_ID_Num[COLOR="#FF0000"],"N")[/COLOR])
                              Should work

                              Comment

                              Working...
                              X