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

SQL and ARGs help please

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

    SQL and ARGs help please

    I'm embarrassed to say how many hours I've worked on this and variations of it and I'm no further in understanding why it's not working. The first code example works fine if I hardcode the CapSat_Main_Tbl.UID)=97, but it fails if I put in CapSat_Main_Tbl.UID)=:LastID


    Another thing, when I hardcode the number, it does add the records to the table but when stepping through the code it hits the line below highlighted. I'm not sure why it adds them anyway if supposedly there is an error.

    flag = cn.Execute(sqlInsertStatement)
    if flag = .f. then
    ui_msg_box("Error","Record was not inserted. Error reported was: " + crlf(2) + cn.CallResult.text,UI_STOP_SYMBOL)
    else
    if cn.AffectedRows() = 1 then
    ui_msg_box("Notice","Record was created.",UI_INFORMATION_SYMBOL)
    else
    ui_msg_box("Error","Record was not inserted." ,UI_STOP_SYMBOL)
    end if
    end if



    Can somebody see what's wrong with the code below?

    Thanks

    -John



    dim args as sql::arguments
    dim sqlInsertStatement as c

    args.add("LastID","UID")

    sqlInsertStatement = <<%txt%
    INSERT INTO CapSat_Scores_Horiz ( YR, CapSat_Main_ID_fk, Component, Element, Element_ID_fk, PC_ID_fk, Program_ID_fk, Partner_ID_fk )
    SELECT CapSat_Main_Tbl.YR, CapSat_Main_Tbl.UID, CapSat_Components_Tbl.Component_Name, CapSat_Elements_Tbl.Element, CapSat_Elements_Tbl.UID_Element, CapSat_Main_Tbl.PC_ID_fk, CapSat_Main_Tbl.PGM_ID_fk, CapSat_Main_Tbl.Partner_ID_fk
    FROM CapSat_Main_Tbl, CapSat_Elements_Tbl INNER JOIN CapSat_Components_Tbl ON CapSat_Elements_Tbl.Component_ID_fk = CapSat_Components_Tbl.UID_Component
    WHERE (((CapSat_Components_Tbl.ShowThis)=True) AND ((CapSat_Elements_Tbl.ShowThis)=True) AND ((CapSat_Main_Tbl.UID)=97))
    %txt%

    #2
    Re: SQL and ARGs help please

    You get used to the embarrassment after a while...

    This is the source of your trouble. You're making the argument, LastID, equal to the character string "UID".

    Code:
    args.add("LastID","UID")
    Code:
    CapSat_Main_Tbl.UID = 'UID'
    You can see this if you debug the code and run replace_arguments_in_string(sqlInsertStatement,args,3).

    If you do this I'm betting your code would work...

    Code:
    args.add("LastID",[B][COLOR="#FF0000"]97[/COLOR][/B])
    The question is what should be in it's place?
    Mike Brown - Contact Me
    Programmatic Technologies, LLC
    Programmatic-Technologies.com
    Independent Developer & Consultant​​

    Comment


      #3
      Re: SQL and ARGs help please

      Where you are adding the argument you are entering a character field whereas it looks like it should be an integer.

      Also in the execute statement you need to pass the arguments so this should change to cn.Execute(sqlInsertStatement,args)

      Finally personally I would use args.set instead of args.add
      Glen Schild



      My Blog

      Comment


        #4
        Re: SQL and ARGs help please

        Originally posted by glenschild View Post
        Also in the execute statement you need to pass the arguments so this should change to cn.Execute(sqlInsertStatement,args)
        Nice catch! Didn't see that myself.
        Mike Brown - Contact Me
        Programmatic Technologies, LLC
        Programmatic-Technologies.com
        Independent Developer & Consultant​​

        Comment


          #5
          Re: SQL and ARGs help please

          Hi Mike,

          Oh jeez, so obvious when you look at it with a fresh set of eyes.

          I forgot to put a few more lines of code in there

          UID = convert_type(e.lastIdentityValue,"n")

          so the 97 is really supposed to be the value of the e.lastIdentityValue

          I'll go give it a shot.


          Hi Glenn,

          Yes, as I've been flip flopping around that has bitten me in the butt a few times.

          Thank you both.

          -John

          Comment


            #6
            Re: SQL and ARGs help please

            Mike, that worked! thanks. I also debugged and put the replace_arguments_in_string(sqlInsertStatement,args,3) and saw it was now using the correct number.

            Thanks again both of you.

            -John

            Comment


              #7
              Re: SQL and ARGs help please

              I could be wrong, but [code]args.add("LastID","UID")] is actually setting the value for LastID to a character value of "UID".
              My guess is that UID is a variable meant to be set at "97" or perhaps "98", or even an integer value of 97 or 98.

              Based on this , I would use
              Code:
              args.set("LastID",UID)
              . This will set the value of the LastID to the value of the variable UID.

              I didn't see which version of SQL you're using, so I'm including samples using MS-SQL and MySQL.
              As long as LastID is truly an integer, the query should work with or without the single quotes as shown in the attached images.
              mssqlExample.PNG
              mysqlExample.png
              Hope this helps.

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

              Comment


                #8
                Re: SQL and ARGs help please

                Hi Gregg,

                Thanks. That was the problem. I had "UID" instead of UID.

                Glenn also mentioned using args.set instead of args.add, what's the difference between the two?

                Thanks

                -John

                Comment


                  #9
                  Re: SQL and ARGs help please

                  From memory, args.add will add a new argument whereas args.set will update an existing argument if exists otherwise creates a new one.
                  Glen Schild



                  My Blog

                  Comment


                    #10
                    Re: SQL and ARGs help please

                    Hi John,

                    Glad to hear the problem is solved.

                    I'm not sure about the difference between .add and .set, but I think .add is a legacy option.
                    I've been using .set for years.
                    Gregg
                    https://paiza.io is a great site to test and share sql code

                    Comment


                      #11
                      Re: SQL and ARGs help please

                      Ok, got it. Thanks all for the help.

                      -J

                      Comment

                      Working...
                      X