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

script help

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

    script help

    I have a database with 2 fields:

    TYPE and ID

    I would like to mark for deletion all records with type 2, but also records with type 1 that have the same ID that type 2 has.
    So I need to read type 2 ID field and delete Type 1 and Type 2 with the same ID.
    the number of records vary all the time, but if there's a Type 2 then there's a type 1 with the same ID.

    #2
    Re: script help

    How many ID's are we talking about?

    Comment


      #3
      Re: script help

      Here is a script that will work regardless of how many ID's:

      Create an index with an expression: Type-ID (that is type minus ID), filtered to only have Type 2 and let's call this index "type_ID"
      Code:
      t=table.open("your_table")
      t.fetch_first()
      while .not. t.fetch_eof()
      if t.type="type 2".or.exists(t.type-t.id,"your_table","type_ID")
      t.change_begin()
      t.mark()
      t.change_end(.t.)
      t.fetch_next()
      end while

      Comment


        #4
        Re: script help

        There should be no more than type 1 and type 2 for the same ID, so one ID could exist maximum of 2 times.
        Last edited by Anis; 05-09-2008, 08:25 PM.

        Comment


          #5
          Re: script help

          Originally posted by Anis View Post
          There should be no more than type 1 and type 2 for the same ID, so one ID could exist maximum of 2 times.
          I understand that..my question was: how many different ID's are there?
          That's irrlevant anyway.. The above script should do the job.
          Last edited by G Gabriel; 05-09-2008, 10:06 PM.

          Comment


            #6
            Re: script help

            usually close to 40,000 in total

            Comment


              #7
              Re: script help

              Originally posted by G Gabriel View Post
              The above script should do the job.

              Comment


                #8
                Re: script help

                Gabe's got the general concept right. The details are lacking which means the result won't work. (Gabe, I know time is precious but you need to take more time thinking these through and testing them.)

                General comment / disclaimer: t.type-t.id will only work IF both are character fields but you didn't tell us what types of fields these are. If they are both numbers and Gabe's index is used, then there is too much chance of matching with a record that really shouldn't match. And if they are mixed - Type is Numeric and ID is character - then setting an index like this won't work at all. Also, FWIW, if both are character fields, then t.type-t.id gives exactly the same result in this case as t.type+t.id; it just "appends" one to the other.

                Obvious typo - missing END IF.
                Obvious typo - there is no Exists() command, it's Exist()

                This will always be true and, therefore, every record will be marked:
                exist(t.type-t.id,"your_table","type_ID")
                This just checks to see if there is a record - any record - that has an index that matches the current record's values. Since the current record's index had better match it's own values, this will be true for every record.

                You have to make sure the t.fetch_next() is outside the IF statement so the loop doesn't run endlessly once the IF is corrected such that some records will not match the IF criteria. (If the "IF" statement is false and the t.fetch_next() is inside the IF statement, the t.fetch_next() is never reached and it loops continuously on the current record.)

                ASSUMING these are both character values and the Type field is only one character wide:
                Use the index as Gabe defined it.
                Code:
                t=table.open("your_table")
                t.fetch_first()
                WHILE .not. t.fetch_eof()
                   IF t.type="2" .or. exist( [B]"2"[/B]+t.ID, "your_table", "type_ID")
                      t.change_begin()
                      t.mark()
                      t.change_end(.t.)
                   END IF
                   t.fetch_next()
                END WHILE
                If the Type is a numeric value and the ID is character, then the index should be:
                str(type) + ID

                And the code should be:
                Code:
                t=table.open("your_table")
                t.fetch_first()
                WHILE .not. t.fetch_eof()
                   IF t.type = 2 .or. exist( str(2) + t.id, "your_table", "type_ID" )
                      t.change_begin()
                      t.mark()
                      t.change_end(.t.)
                   END IF
                   t.fetch_next()
                END WHILE
                If both are numeric values, I'd build the index using str() of both fields and change the IF to:
                IF t.type = 2 .or. exist( str(2) + str(t.id), "your_table", "type_ID" )

                If you don't change them to string values, then adding Type 2 plus ID 345 would result in 347 and there is a possibility that another record might have Type 1 plus ID 346 and the result would be the same 347.

                Note also that this "one loop" method only works because you are MARKING the records. If you were deleting records, you would either have to run the loop once to remove the matching Type 1 records and again to remove all the Type 2 records - or - guarantee that all Type 1 records would come before their matching Type 2 records. The second method could be done by setting an index or query by Type before starting the loop.
                Last edited by CALocklin; 05-10-2008, 02:18 AM.

                Comment


                  #9
                  Re: script help

                  Correction:
                  Create an index based on ID filtered to only have Type 2 and let's call this index "ID"

                  Code:
                  t=table.open("your_table")
                  t.fetch_first()
                  while .not. t.fetch_eof()
                  if t.type="type 2".or.exists(t.id,"your_table","ID")
                  t.change_begin()
                  t.mark()
                  t.change_end(.t.)
                  end if
                  t.fetch_next()
                  end while
                  Haven't read Cal's comments yet. Just had an episode of insomnia, thought about this and (and an online contest I am pariticpating in) knew I had to make a minor correction. Will read Cal's comment momentarily.
                  Last edited by G Gabriel; 05-10-2008, 04:11 AM.

                  Comment


                    #10
                    Re: script help

                    I am giving Anis enough credit that he could modify the code based on whether it's character or numeric. My first inqury went un-answered, so I offered a generic code that should do the job.

                    Yes, "end if" is missing and won't take a genius to figure that out or fix it.

                    This just checks to see if there is a record - any record - that has an index that matches the current record's values. Since the current record's index had better match it's own values, this will be true for every record.
                    Not so. The index only has "Type 2". Evidently you are not quite clear on the concept.

                    I didn't read any further...
                    Last edited by G Gabriel; 05-10-2008, 03:59 AM.

                    Comment


                      #11
                      Re: script help

                      duplicate entry.. disregard.

                      Comment


                        #12
                        Re: script help

                        Thanks for all the help.
                        Actually, both fields are numeric, so as Cal mentioned both have to be converted with STR().

                        That type of help is why the message board is worth millions.

                        Thanks again

                        Comment


                          #13
                          Re: script help

                          Originally posted by G Gabriel View Post
                          Not so. The index only has "Type 2".
                          You are quite correct. What's worse is that I saw that comment about the filtered index then forgot about it when setting up my test.

                          As for giving someone credit for being able to fix my code, that's just a difference of opinion. My take on that is that even though Anis might be able to work out those details, there are other readers who might not - so it helps to have accurate code and to provide more info about possible alternatives that may arise so even new users can learn. I've seen people get totally confused by very basic issues so I try to give detailed answers that have been tested. To most of us a missing END IF would be obvious but I wouldn't be shocked to have someone ask why it wasn't used or where it should go. I've seen equally "dumb" questions and probably even asked a few myself when first learning.

                          Comment


                            #14
                            Re: script help

                            That worked perfect.

                            Thanks for every one.

                            Comment

                            Working...
                            X