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

What to do with variables shared or global

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

    What to do with variables shared or global

    Hi all
    I wanted to loop through a DBF table and insert the records into a MySQL table using a script and not with a form open. Managed to do it using the Genie but I first had to Dim the variables as global to map the fields to the variables in the Genie. Then I changed the variables as shared in script. I just want to know why one cannot see shared variables in the genie while mapping it to fields. Also I am closing the connection after each insert. Can one leave the connection open throughout the loop and then close it?

    My Code:
    Code:
    dim tbl as p
    dim shared vDriver as c
    dim shared vFirstSTartDateTime as t
    dim shared vStartDate_Grp as d
    dim shared vCountStartDateTime as n
    dim shared vLastEndDateTime as t
    dim shared vTotalTripTime as n
    dim shared vTotalIdleTime as n
    dim shared vTotalDrive_Time as n
    dim shared vTotalDistance as n
    dim shared vMax_Max_Speed as n
    dim shared vMaxRpm as n
    tbl = table.open("satlog_summary")
    'debug(1)
    tbl.fetch_first()
    while .not. tbl.fetch_eof()
        'do something here
        vDriver = tbl.drivername
        vFirstSTartDateTime = tbl.first_start_date_time
        vStartDate_Grp = tbl.first_start_date_time
        vCountStartDateTime = tbl.count_start_date_time
        vLastEndDateTime = tbl.last_end_date_time
        vTotalTripTime = tbl.total_trip_time
        vTotalIdleTime = tbl.total_idle_time
        vTotalDrive_Time = tbl.total_drive_time
        vTotalDistance = tbl.total_total_distance
        vMax_Max_Speed = tbl.maximum_max_speed
        vMaxRpm = tbl.maximum_max_rpm
        '======================================================
        'Insert a new record into a remote SQL database.
        'DIM a connection variable
        DIM cn as SQL::Connection
        dim flagResult as l
        flagResult = cn.open("::Name::Tankers_Local")
        if flagResult = .f. then
            ui_msg_box("Error","Could not connect to database. Error reported was: " + crlf() + cn.CallResult.text)
            end
        end if
        
        '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
        
        if a5_eval_valid_expression("=Var->vDriver",local_variables()) then
            args.add("Drivername",convert_type(a5_eval_expression("=Var->vDriver",local_variables()),"C"))
        end If
        if a5_eval_valid_expression("=Var->vStartDate_Grp",local_variables()) then
            args.add("Start_Date_Grp",convert_type(a5_eval_expression("=Var->vStartDate_Grp",local_variables()),"D"))
        end If
        if a5_eval_valid_expression("=Var->vFirstSTartDateTime",local_variables()) then
            args.add("First_Start_Date_Time",convert_type(a5_eval_expression("=Var->vFirstSTartDateTime",local_variables()),"T"))
        end If
        if a5_eval_valid_expression("=Var->vCountStartDateTime",local_variables()) then
            args.add("Count_Start_Date_Time",convert_type(a5_eval_expression("=Var->vCountStartDateTime",local_variables()),"N"))
        end If
        if a5_eval_valid_expression("=Var->vLastEndDateTime",local_variables()) then
            args.add("Last_End_Date_Time",convert_type(a5_eval_expression("=Var->vLastEndDateTime",local_variables()),"T"))
        end If
        if a5_eval_valid_expression("=Var->vTotalTripTime",local_variables()) then
            args.add("Total_Trip_Time",convert_type(a5_eval_expression("=Var->vTotalTripTime",local_variables()),"N"))
        end If
        if a5_eval_valid_expression("=Var->vTotalIdleTime",local_variables()) then
            args.add("Total_Idle_Time",convert_type(a5_eval_expression("=Var->vTotalIdleTime",local_variables()),"N"))
        end If
        if a5_eval_valid_expression("=Var->vTotalDrive_Time",local_variables()) then
            args.add("Total_Drive_Time",convert_type(a5_eval_expression("=Var->vTotalDrive_Time",local_variables()),"N"))
        end If
        if a5_eval_valid_expression("=Var->vTotalDistance",local_variables()) then
            args.add("Total_Total_Distance",convert_type(a5_eval_expression("=Var->vTotalDistance",local_variables()),"N"))
        end If
        if a5_eval_valid_expression("=Var->vMax_Max_Speed",local_variables()) then
            args.add("Maximum_Max_Speed",convert_type(a5_eval_expression("=Var->vMax_Max_Speed",local_variables()),"N"))
        end If
        if a5_eval_valid_expression("=Var->vMaxRpm",local_variables()) then
            args.add("Maximum_Max_Rpm",convert_type(a5_eval_expression("=Var->vMaxRpm",local_variables()),"N"))
        end If
        
        dim sqlInsertStatement as c
        sqlInsertStatement = <<%txt%
    INSERT INTO satlog_summary  (Drivername, Start_Date_Grp,  First_Start_Date_Time, Count_Start_Date_Time, Last_End_Date_Time,  Total_Trip_Time, Total_Idle_Time, Total_Drive_Time,  Total_Total_Distance, Maximum_Max_Speed, Maximum_Max_Rpm) VALUES  (:Drivername, :Start_Date_Grp, :First_Start_Date_Time,  :Count_Start_Date_Time, :Last_End_Date_Time, :Total_Trip_Time,  :Total_Idle_Time, :Total_Drive_Time, :Total_Total_Distance,  :Maximum_Max_Speed, :Maximum_Max_Rpm)
    %txt%
        
        dim flag as l
        flag = cn.Execute(sqlInsertStatement,args)
        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
                'USING THIS PART TO INCREMENT A RECORD COUNTER
                'ui_msg_box("Notice","Record was created.",UI_INFORMATION_SYMBOL)
            else
                'USING THIS TO UPDATE A LOG FILE
                'ui_msg_box("Error","Record was not inserted." ,UI_STOP_SYMBOL)
            end if
        end if
        
        'Now, close the connection
        cn.close()
        '======================================================
        tbl.fetch_next()
    end while
    Any pointer would be appreciated.
    Last edited by gagsoft; 04-26-2014, 10:59 AM.

    #2
    Re: What to do with variables shared or global

    I don't know the answer to the second question (about re-using the connection), but it sounds like the genie opens in its own session ( the same way a report might ). Variables shared in one form are not available in other sessions.

    Comment


      #3
      Re: What to do with variables shared or global

      Peter,
      you wrote:
      using a script and not with a form open.
      The documentation for A5_EVAL_EXPRESSION()
      The A5_EVAL_EXPRESSION() function evaluates an expression in the context of the current form or browse window.
      That is an action scripting entry, and you shouldn't need it.
      Also, all the variables are dimmed to there respective types to begin with, why the act of convert type to the type they already are when assigning them to the argument?
      And you should be able to open the table once, write the data, and close the table. If you open it every iteration, the "can't open" may occur and you'll have 1/2 your data written and 1/2 not, and you will have to figure out where it left off.
      Mike W
      __________________________
      "I rebel in at least small things to express to the world that I have not completely surrendered"

      Comment


        #4
        Re: What to do with variables shared or global

        Hi Guys
        Thanks for the help. I must apologize for not being clear on the opening and closing bit of my question. I actually meant the opening and closing of cn the SQL Connection. My concern really is the processing time it might take to insert a few thousand records.

        Many Thanks
        Peter G

        Comment


          #5
          Re: What to do with variables shared or global

          Originally posted by gagsoft View Post
          Hi Guys
          Thanks for the help. I must apologize for not being clear on the opening and closing bit of my question. I actually meant the opening and closing of cn the SQL Connection. My concern really is the processing time it might take to insert a few thousand records.

          Many Thanks
          Peter G
          Peter

          What is the amount of time that is acceptable? seconds, minutes, hours?

          I've found that adding data is fairly fast.

          The fastest way to add data to SQL is to import the data with a native function on the server. But that involves preparing the data, sending it to the server and then running an import on the server.

          How many records are you adding and how long does it take when you test your script?

          You should open the connection, add all the records, and then close the connection. Just like you would do with a dbf - open the table, add all the records, and close that table.
          Al Buchholz
          Bookwood Systems, LTD
          Weekly QReportBuilder Webinars Thursday 1 pm CST

          Occam's Razor - KISS
          Normalize till it hurts - De-normalize till it works.
          Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
          When we triage a problem it is much easier to read sample systems than to read a mind.
          "Make it as simple as possible, but not simpler."
          Albert Einstein

          http://www.iadn.com/images/media/iadn_member.png

          Comment


            #6
            Re: What to do with variables shared or global

            Hi Al
            Thanks for the help. So I have to move the cn.close() to the outside of the "end while" loop.
            The records that will have to be inserted will most probably be in the region of about 16 000 at the and of each week.
            Thanks quys
            Much appreciated
            Peter G

            Comment


              #7
              Re: What to do with variables shared or global

              If you can just dump the records in, it should be quick.
              If you have constraints, you will bump into errors I suspect.
              See our Hybrid Option here;
              https://hybridapps.example-software.com/


              Apologies to anyone I haven't managed to upset yet.
              You are held in a queue and I will get to you soon.

              Comment

              Working...
              X