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

help with sql insert into statement

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

    help with sql insert into statement

    I am trying to follow the info here about Inserting a Row Into a SQL Database, p. 22: http://www.alphasoftware.com/whitepa...chitecture.pdf

    I'm trying to just append an audit record about a deletion into my back end Access database. In the code below, the connection has already been opened, etc. The piece of code shown here produces a fatal error (which doesn't surprise me since I'm such an Alpha newbie). I've been studying everything I can find about INSERT INTO and am now throwing my appeal for help to the message board. Thanks.

    Code:
    'append an audit record about the Cost Type(PROD_CODE) deletion to the TblGLAudit
    	'NOTE:  PROD_CODE value from TblProducts is appended to AP_PRODUCT_ID field in TblGLAudit
    	
    	dim sqlaudit as c
    	sqlaudit = "INSERT INTO TblGLAudit(GL_JOURNAL, GL_DATE, GL_MAIN_ACCT_NUM, GL_DESCRIPTION, AP_PRODUCT_ID, GL_ENTRY_NOTES, AUDIT_DATE, USER_NAME)
    	VALUES (:GL_JOURNAL, :GL_DATE, :GL_MAIN_ACCT_NUM, :GL_DESCRIPTION, :AP_PRODUCT_ID, :GL_ENTRY_NOTES, :AUDIT_DATE, :USER_NAME)"
    	
    	delete args 
    	dim args as sql::arguments
    	'set the value of the arguments.
    	'NOTE:  If field is a numeric field, the code would have to be like this (per Selwyn):
    	'args.add("whatCriteria", convert_type( FieldName, "N") )
    	'ones I wonder about are the date and time fields...
    	
    	dim AuditValue as c
    	AuditValue = e._currentRowDataOld.PROD_CODE
    	dim AuditNote as c
    	AuditNote = "User confirmed deletion of Cost Type: "+ AuditValue
    	
    	args.add("GL_JOURNAL", "NONE")
    	args.add("GL_DATE",Date) 'today's date? is this right? need to convert to character?
    	args.add("GL_MAIN_ACCT_NUM","0") 'GL_MAIN_ACCT_NUM is a text field
    	args.add("GL_DESCRIPTION","Cost Type Deletion Request")
    	args.add("AP_PRODUCT_ID",AuditValue)
    	args.add("GL_ENTRY_NOTES", AuditNote)
    	args.add("AUDIT_DATE",Now) 'date and time? is this right?  need to convert to character?
    	args.add("USER_NAME","Alpha Test")
    		
    	'execute the audit append query with a flag to let us know if the query was executed successfully.
    	flag = cn.Execute(sqlaudit,args)
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

    #2
    Re: help with sql insert into statement

    Hi Carol,

    Can you post the error message you're getting?

    Also, which event did you add this logic to?

    Thanks,

    Robert
    Earl Allin
    REAInc.net

    We can help you with mentoring and custom programming services in Alpha, .NET, React, PHP, ColdFusion, and more..

    Comment


      #3
      Re: help with sql insert into statement

      I tried adding this code to a much longer function that was already successfully deleting a record after looking up some criteria with sql statements to verify that the delete should occur. I am using a button I created for the delete and it's activated by the OnClick event.

      After putting in the new code to append an audit record, I now get this error:

      Fatal Error: Could not compile Xbasic: 'LookupInChildTablesThenDeleteIfNotFound'
      Carol King
      Developer of Custom Homebuilders' Solutions (CHS)
      http://www.CHSBuilderSoftware.com

      Comment


        #4
        Re: help with sql insert into statement

        Sorry - editing..

        I misread your note.

        Can you show me the full xbasic for the onclick?

        Thanks,

        Robert
        Earl Allin
        REAInc.net

        We can help you with mentoring and custom programming services in Alpha, .NET, React, PHP, ColdFusion, and more..

        Comment


          #5
          Re: help with sql insert into statement

          Originally posted by kingcarol View Post
          I tried adding this code to a much longer function that was already successfully deleting a record after looking up some criteria with sql statements to verify that the delete should occur. I am using a button I created for the delete and it's activated by the OnClick event.

          After putting in the new code to append an audit record, I now get this error:

          Fatal Error: Could not compile Xbasic: 'LookupInChildTablesThenDeleteIfNotFound'
          the error is telling you that there is a syntax error in this function that you have defined:

          LookupInChildTablesThenDeleteIfNotFound

          the easiest way to figure out what the error is, is as follows:

          1. copy the function to the clipboard.
          2. go to the a5 control panel (not the web control panel)
          3. go to the code tab
          4. create a new empty xbasic scrpt
          5. paste the code from the clipboard.
          6. on the toolbar you will see a button called 'check syntax' (7 from left). click that. it will tell you what the xbasic syntax error is.

          Comment


            #6
            Re: help with sql insert into statement

            Originally posted by kingcarol View Post
            I am trying to follow the info here about Inserting a Row Into a SQL Database, p. 22: http://www.alphasoftware.com/whitepa...chitecture.pdf

            I'm trying to just append an audit record about a deletion into my back end Access database. In the code below, the connection has already been opened, etc. The piece of code shown here produces a fatal error (which doesn't surprise me since I'm such an Alpha newbie). I've been studying everything I can find about INSERT INTO and am now throwing my appeal for help to the message board. Thanks.

            Code:
            'append an audit record about the Cost Type(PROD_CODE) deletion to the TblGLAudit
            	'NOTE:  PROD_CODE value from TblProducts is appended to AP_PRODUCT_ID field in TblGLAudit
            	
            	dim sqlaudit as c
            	sqlaudit = "INSERT INTO TblGLAudit(GL_JOURNAL, GL_DATE, GL_MAIN_ACCT_NUM, GL_DESCRIPTION, AP_PRODUCT_ID, GL_ENTRY_NOTES, AUDIT_DATE, USER_NAME)
            	VALUES (:GL_JOURNAL, :GL_DATE, :GL_MAIN_ACCT_NUM, :GL_DESCRIPTION, :AP_PRODUCT_ID, :GL_ENTRY_NOTES, :AUDIT_DATE, :USER_NAME)"
            	
            	delete args 
            	dim args as sql::arguments
            	'set the value of the arguments.
            	'NOTE:  If field is a numeric field, the code would have to be like this (per Selwyn):
            	'args.add("whatCriteria", convert_type( FieldName, "N") )
            	'ones I wonder about are the date and time fields...
            	
            	dim AuditValue as c
            	AuditValue = e._currentRowDataOld.PROD_CODE
            	dim AuditNote as c
            	AuditNote = "User confirmed deletion of Cost Type: "+ AuditValue
            	
            	args.add("GL_JOURNAL", "NONE")
            	args.add("GL_DATE",Date) 'today's date? is this right? need to convert to character?
            	args.add("GL_MAIN_ACCT_NUM","0") 'GL_MAIN_ACCT_NUM is a text field
            	args.add("GL_DESCRIPTION","Cost Type Deletion Request")
            	args.add("AP_PRODUCT_ID",AuditValue)
            	args.add("GL_ENTRY_NOTES", AuditNote)
            	args.add("AUDIT_DATE",Now) 'date and time? is this right?  need to convert to character?
            	args.add("USER_NAME","Alpha Test")
            		
            	'execute the audit append query with a flag to let us know if the query was executed successfully.
            	flag = cn.Execute(sqlaudit,args)

            here is how you can use an alpha five genie to help you generate an alphaDAO insert statement:

            http://screencast.com/t/MDZhMDE4ZmEt

            Comment


              #7
              Re: help with sql insert into statement

              Thanks, Selwyn, for the video. I'm going to go try that now. Wanted to a post a little Jing here because the screens in my Alpha are different than yours, and I had a little trouble finding the Xbasic Genie following your directions. Here's how I found it:

              http://screencast.com/t/NzkxNmI1MTg
              Carol King
              Developer of Custom Homebuilders' Solutions (CHS)
              http://www.CHSBuilderSoftware.com

              Comment


                #8
                Re: help with sql insert into statement

                Originally posted by kingcarol View Post
                Thanks, Selwyn, for the video. I'm going to go try that now. Wanted to a post a little Jing here because the screens in my Alpha are different than yours, and I had a little trouble finding the Xbasic Genie following your directions. Here's how I found it:

                http://screencast.com/t/NzkxNmI1MTg
                maybe my video was not clear, but it is actually simpler than your video indicates.

                the first button on the toolbar is 'new xbasic script'

                the second button is 'new action script'.

                it is the second button that you need to click to create a new action script. once you are in the action script editor, you can then click the button to add new action.

                Comment


                  #9
                  Re: help with sql insert into statement

                  ok, I have generated code with the genie, copied what I needed, and am pasting it into the Xbasic function declaration. However, even if I comment out all the code I just pasted, I cannot save it. I get a message that says "Extra characters at end of expression." See Jing..

                  http://screencast.com/t/NWI1NjczMj

                  This code isn't tested, and I'm sure needs tweaking, but I can't save it in order to start testing... here's the code from the genie that I'm sure I'll probably need to alter some.

                  Code:
                  	'Specify that we are using Portable SQL syntax
                  	cn.PortableSQLEnabled = .t.
                  	
                  	'Dim a SQL arguments object, create arguments and set their values
                  	DIM args as sql::arguments
                  	
                  	args.add("GL_JOURNAL","NONE")
                  	if a5_eval_valid_expression("=Date()",local_variables()) then 
                  		args.add("GL_DATE",convert_type(a5_eval_expression("=Date()",local_variables()),"T"))
                  	end If
                  	args.add("GL_DESCRIPTION","User confirmed delete of Cost Type:  ")
                  	args.add("GL_MAIN_ACCT_NUM","0")
                  	if a5_eval_valid_expression("=e._currentRowDataOld.PROD_CODE",local_variables()) then 
                  		args.add("AP_PRODUCT_ID",convert_type(a5_eval_expression("=e._currentRowDataOld.PROD_CODE",local_variables()),"C"))
                  	end If
                  	if a5_eval_valid_expression("=Now()",local_variables()) then 
                  		args.add("AUDIT_DATE",convert_type(a5_eval_expression("=Now()",local_variables()),"T"))
                  	end If
                  	args.add("USER_NAME","Alpha Test")
                  	
                  	dim sqlInsertStatement as c 
                  	sqlInsertStatement = <<%txt%
                  	INSERT INTO TblGLAudit  (GL_JOURNAL, GL_DATE, GL_DESCRIPTION, GL_MAIN_ACCT_NUM, AP_PRODUCT_ID, AUDIT_DATE, USER_NAME) VALUES (:GL_JOURNAL, :GL_DATE, :GL_DESCRIPTION, :GL_MAIN_ACCT_NUM, :AP_PRODUCT_ID, :AUDIT_DATE, :USER_NAME)
                  	%txt%
                  	
                  	dim flag as l 
                  	flag = cn.Execute(sqlInsertStatement,args)
                  Carol King
                  Developer of Custom Homebuilders' Solutions (CHS)
                  http://www.CHSBuilderSoftware.com

                  Comment


                    #10
                    Re: help with sql insert into statement

                    OK, i see the problem.

                    You are using %txt% as your long string delimiter.
                    But the Grid component also uses this as its long string delimiter. (If you go to the Xbasic tab in the Grid Builder, you will see that).

                    Change your code to use some other long string delimiter.
                    e.g. instead of using %txt%, you could use %sqltxt%

                    We actually made a change yesterday to automatically fix up long string delimiter conflicts. That fix will be in the next update.

                    Thanks.

                    Comment


                      #11
                      Re: help with sql insert into statement

                      Great! making that change lets me save the code. Now on to testing and tweaking it. Thanks, Selwyn
                      Carol King
                      Developer of Custom Homebuilders' Solutions (CHS)
                      http://www.CHSBuilderSoftware.com

                      Comment


                        #12
                        Re: help with sql insert into statement

                        AND success! I didn't have to tweak the code. It's appending the record to my audit table nicely...

                        here's the code that works. and I'm done for the day :) Thanks again, Selwyn.

                        Code:
                        'append an audit record about the Cost Type(PROD_CODE) deletion to the TblGLAudit
                        	'NOTE:  PROD_CODE value from TblProducts is appended to AP_PRODUCT_ID field in TblGLAudit
                        	
                        	'Specify that we are using Portable SQL syntax
                        	cn.PortableSQLEnabled = .t.
                        	
                        	'Dim an SQL arguments object, create arguments and set their values
                        	DIM args as sql::arguments
                        	
                        	args.add("GL_JOURNAL","NONE")
                        	if a5_eval_valid_expression("=Date()",local_variables()) then 
                        		args.add("GL_DATE",convert_type(a5_eval_expression("=Date()",local_variables()),"T"))
                        	end If
                        	args.add("GL_DESCRIPTION","User confirmed delete of Cost Type:  ")
                        	args.add("GL_MAIN_ACCT_NUM","0")
                        	if a5_eval_valid_expression("=e._currentRowDataOld.PROD_CODE",local_variables()) then 
                        		args.add("AP_PRODUCT_ID",convert_type(a5_eval_expression("=e._currentRowDataOld.PROD_CODE",local_variables()),"C"))
                        	end If
                        	if a5_eval_valid_expression("=Now()",local_variables()) then 
                        		args.add("AUDIT_DATE",convert_type(a5_eval_expression("=Now()",local_variables()),"T"))
                        	end If
                        	args.add("USER_NAME","Alpha Test")
                        		
                        	dim sqlInsertStatement as c 
                        	sqlInsertStatement = <<%sqltxt%
                        	INSERT INTO TblGLAudit  (GL_JOURNAL, GL_DATE, GL_DESCRIPTION, GL_MAIN_ACCT_NUM, AP_PRODUCT_ID, AUDIT_DATE, USER_NAME) VALUES (:GL_JOURNAL, :GL_DATE, :GL_DESCRIPTION, :GL_MAIN_ACCT_NUM, :AP_PRODUCT_ID, :AUDIT_DATE, :USER_NAME)
                        	%sqltxt%
                        	
                        	dim flag as l 
                        	flag = cn.Execute(sqlInsertStatement,args)
                        	
                        	'if audit append query could not execute, give the user a message and exit the function.
                        	if flag = .f. then 
                        		'there was an error - close the connection and exit
                        		cn.Close()
                        		dim msg as c 
                        		msg = "Could not append audit record, so delete will not occur. Please contact your program administrator for help.  Error reported was: " + cn.CallResult.text
                        		msg = js_escape(msg)
                        		dim jscmd as c 
                        		jscmd = "alert('" + msg + "');"
                        		DoDeleteAfterConfirm = jscmd
                        		exit function 
                        	end if
                        Carol King
                        Developer of Custom Homebuilders' Solutions (CHS)
                        http://www.CHSBuilderSoftware.com

                        Comment

                        Working...
                        X