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 with unbound fields

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

  • SQL with unbound fields

    Hi All,

    Here is what I am trying to achieve ...

    I have a UX component bound to an MS SQL Server 2008 view. That's all working properly. It's only for display, so no update needed on the tables in the view.

    I have some additional unbound fields which relate to another table. All good so far.

    Now ... here is where I am having trouble and I just can't get my head around the Alpha way of doing things ... I have a button on the UX which when pressed will write add a new record to the unbound table.

    Once this button has been pressed, or when the user enters the UX component, if that record already exists in the unbound table, I want to delete the record. If it doesn't exist, I want to add a new record. The whole UX is filtered by UserName, which is a session variable. Because there could be many records in the unbound table relating to the User, just toggling a flag in the UserName table wouldn't work.

    The unbound table consists of four fields :
    idPK int, Primary key autoinc
    PromotionIDFK, int
    DateSaved, date
    UserName, varchar(120)

    There is also an index on UserName and PromotionIDFK which is unique ... Each UserName can only have one PromotionIDFK.

    The bound view has the field PromotionID, int, and UserName, varchar(120) which would be the link for me to relate to the unbound data.

    Essentially we have a user who can choose promotions and store them as favourites or delete them from their favourite list.

    I guess what I am looking for is the code to click a button to access the unbound table, and if a record is found with the values which match the current username and promotion ID, then display it as being flagged as a favourite, and if not found, then add a new record.

    My thinking was varied (or is that random!>) ... for example to write a SQL BEGIN TRY, BEGIN CATCH ... so in pseudocode

    Code:
    BEGIN TRY
    INSERT INTO SAVEDPROMOTIONS (PROMOTIONIDFK, DATESAVED,USERNAME) VALUES (UX_IDPROMOTIONSPK, UX_DATESAVED, UX_USERNAME)
    CATCH
    DELETE SAVEDPROMOTIONS WHERE IDPK = IDPROMOTIONSPK 
    END CATCH
    But catches all errors that might have caused the insert to fail, not just a duplicate key.

    Alternatively, I could do something like

    Code:
    INSERT INTO SAVEDPROMOTIONS (PROMOTIONIDFK, DATESAVED,USERNAME) VALUES (UX_IDPROMOTIONSPK, UX_DATESAVED, UX_USERNAME)
    IF 
        ErrorMsg 2627 THEN DELETE SAVEDPROMOTIONS WHERE IDPK = IDPROMOTIONSPK 
    END IF
    But I am uncertain where and how to trap errorcodes in this situation and deal with them.

    Then I thought to myself (which can be dangerous) ... Why not look up on entry to the UX with something like the following and then we could perhaps set a flag on the UX to set buttons hidden or shown? So I have also tried

    Code:
    dim LookUpCn as sql::Connection
    dim args as sql::Arguments
    LookUpCn.open("::name::conn")
    table = "SavedPromotions"
    'I created arguments based on the Username field (aUserName) and PromotionIDFK (aPromotionID) and DateSaved (aDateSaved) in the UX component.
    filter = "username=:aUserName AND PromotionIDFK = :aPromotionID"
    result = ":aDateSaved"
    filter = evaluate_string(filter)
    if sql_lookup(LookUpCn,table,filter,result) <> null_value()
    	ui_msg_box("Promotion","Already Saved") 'This never pops up!
    end if
    cn.close()

    I seem to have trouble grasping how to use the fields from the UX in the SQL ... I come from a very different background where you could just add those 'screen' variables into the SQL. Alpha confuses me on this ... I am sure I will get it once I am shown the light I am sure if I had it hammered into my little brain how to translate the variables in the UX into the SQL query, I could probably work it out from there. I'm newish to both SQL and Alpha, but getting there (I hope).

    Hopefully I have explained this adequately. All assistance would be gratefully received and if clarification is required, please don't hesitate to ask.

    Thanks,

    Phil

  • #2
    Re: SQL with unbound fields

    It strikes me that the info contained in http://www.ajaxvideotutorials.com/V1...operations.swf is close to what I want to do, and use 'Autodecide', but it seems to be a little too constrained to do what I need it to do. Or perhaps someone could shed some light for me on how to configure it, when I don't already have the primary key field information?

    Any assistance, gratefully accepted.

    Phil

    Comment


    • #3
      Re: SQL with unbound fields

      No bites.

      OK, Simple question, hopefully.

      Say I want to assign the value of the unbound field 'UserID' to an argument in a function? How do I get at the value of the field within the function and assign it to an argument?

      Comment


      • #4
        Re: SQL with unbound fields

        You can find examples of how to reference your UX fields on the server-side in the afterDialogValidate event. There are several variations. You can access your unbound fields anytime on the server-side as long as you have access to the “e” object. All of the Alpha server-side events have access to the “e” object and so do Ajax callbacks.

        For example, if you create an Ajax callback on a button click event and want to do something with the UserID field, you would use the following variable name to reference it:

        request.variables.v.r1.userid

        If you want to add the value of your UserID field to an argument list?

        args.add("aUserID", request.variables.v.r1.userid)

        "aUserID" is the name of the temporary argument. "userid" in "request.variables.v.r1.userid" must be the same as the name you assigned to your control. All Xbasic alpha characters are case insensitive.

        Comment


        • #5
          Re: SQL with unbound fields

          Hi Dave

          What I finally ended up with is as follows ... using Firebug, I saw the values I wanted in the e.oldDataSubmitted values, so I used those.

          Code:
          function CheckFav as L (e as p)
          dim LookUpConn as sql::Connection
          dim args as sql::Arguments
          dim rs as sql::ResultSet
          dim sqlQuery as c
          dim delSQL as c
          dim insSQL as c
          args.Add("PID", e.oldDataSubmitted.idPromotionsPK)
          args.Add("UN", e.oldDataSubmitted.aUserID)
          args.Add("sDATE", e.oldDataSubmitted.aDateSaved)
          LookUpConn.open("::name::conn")
          sqlQuery = "Select count(*) from SavedPromotions where UserID = :UN AND PromotionIDFK = :PID"
          delSQL = "DELETE FROM SavedPromotions WHERE PromotionIDFK=:PID AND UserID =:UN"
          insSQL = "Insert into SavedPromotions (PromotionIDFK,DateSaved,UserID) VALUES(:PID,:sDATE,:UN)"
          sqlQuery = evaluate_string(sqlQuery)
          delSQL = evaluate_string(delSQL)
          insSQL = evaluate_string(insSQL)
          LookUpConn.execute(sqlQuery,args)
          rs = LookUpConn.ResultSet
          if rs.data(1) > 0 	
          	LookUpConn.Execute(delSQL, args)
          	LookUpConn.close()
          	return .T.
          else
          	LookUpConn.Execute(insSQL, args)
          	LookUpConn.close()
          	return .F.
          end if
          end function
          Thanks for pointing me in the right direction and taking the time to respond. I now have the function working as I want

          Comment

          Working...
          X