Alpha Video Training
Results 1 to 12 of 12

Thread: <tb>.query_create()

  1. #1
    "Certified" Alphaholic G Gabriel's Avatar
    Real Name
    G. Gabriel
    Join Date
    Oct 2004
    Posts
    7,204

    Default <tb>.query_create()

    Just noticed this for the first time and it makes no sense:
    This a bread & butter script:
    open a table with table.open()
    run a query using .query_create()
    got to first record, using .fetch_first()

    If the query is empty, i.e. no records in the query, fetch_first() goes to the first record in the table !

    That's not good. It shouldn't.

    Why?

    What happened if you run a QBF and the query is empty? it does not go to the first record, does it?

    The reason I didn't notice this before is because I always count the number of records in the query and if it is zero, move on to something else, otherwise continue to work on the table. This time I forgot to add this line to count the records and saw this untoward outcome.

    Bug?
    I think so.

    Word of caution:
    Always count the number of records in the query before going any further.

    Caveat:
    Someone please test in v9. The above is based on v8.

  2. #2
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,310

    Default Re: <tb>.query_create()

    G., I'll check it in v 9.

    In the meantime, what behavior do you think would be "correct" in this situation?

    Later...

    It seems to run the same way in vers 9. However, it seems to me that this is reasonable behavior. The record pointer in the newly opened table is not moved when the query is empty. The call to fetch the first record doesn't do anything since the record pointer is on the first record when the table opens.

    Makes sense to me.

    Code:
    t = table.open("customer")
    
    ?t.LASTNAME
    = "Graham              "
    
    query.options = "NT"
    query.order = "Lastname"
    query.filter = "Lastname = 'Abraham'"
    
    qry = t.query_create()
    
    ?qry.records_get()
    = 0
    
    ?t.LASTNAME
    = "Graham              "
    
    t.fetch_first()
    ?t.LASTNAME
    = "Graham              "
    
    qry.drop()
    
    t.close()
    This sequence should not be compared to the QBF results since the table is already open in QBF, with record pointer positioned by the user, not necessarily on the first record in the table. table.open() opens a new instance of the table, not the instance supporting the current form.

    -- tom
    Last edited by Tom Cone Jr; 09-21-2008 at 06:24 PM.

  3. #3
    "Certified" Alphaholic G Gabriel's Avatar
    Real Name
    G. Gabriel
    Join Date
    Oct 2004
    Posts
    7,204

    Default Re: <tb>.query_create()

    Quote Originally Posted by Tom Cone Jr View Post
    table.open() opens a new instance of the table, not the instance supporting the current form.
    That's my point.

    table.open() opens a new instant of the table (independant of the currently open one).

    If the query is empty, then the newly opened instance is empty.
    Why does it then go to the first record?
    I expect to get a message: no records in this query.

    Thanks for checking.
    Last edited by G Gabriel; 09-21-2008 at 06:46 PM.

  4. #4
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,310

    Default Re: <tb>.query_create()

    I disagree but don't want to be disagreeable. To me this is a problem that occurs sometimes between the keyboard and my chair. The tbl.fetch_first() statement doesn't know or care that I've run a query. The opened instance of the table is not empty, the query failed. If Alpha treated broken or failed queries as you wish, the table would immediately be placed in ENTER mode, since your idea would cause Alpha to think there are no records in the table. Not good.

  5. #5
    "Certified" Alphaholic G Gabriel's Avatar
    Real Name
    G. Gabriel
    Join Date
    Oct 2004
    Posts
    7,204

    Default Re: <tb>.query_create()

    The tbl.fetch_first() statement doesn't know or care that I've run a query.
    The opened instance of the table is not empty,
    What you are saying would be true if fetch_first() is fetching whatever table that happens to be open. Not so. It fetchs where the pointer is and the pointer is at the new instance.

    It is not fetch_first()
    It's tbl.fetch_first()

    The pointer is at tbl i.e. at the newly opened instance of the table, NOT the currently opened one.
    It should care where the pointer is and it does, but in the end it misbehaves by going to the first record of the table since the new instance does not have a first record, it has no records at all.

    OK.. let me make my point simpler and more clear:
    Run the same script from your Code tab without any opened instances of the table.

    Now what happens?
    You still get the first record! even though the query is empty and no other instances of the table is open.
    How so?
    Last edited by G Gabriel; 09-21-2008 at 07:28 PM.

  6. #6
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,310

    Default Re: <tb>.query_create()

    Nope. Your logic makes sense only if the failed query is actually treated as having been run successfully leaving an "empty" instance of the table. Where you see a successful query and a failed fetch, I see a failed query and a successful fetch. You say tomato I say tomato. -- tom

  7. #7
    "Certified" Alphaholic G Gabriel's Avatar
    Real Name
    G. Gabriel
    Join Date
    Oct 2004
    Posts
    7,204

    Default Re: <tb>.query_create()

    Your logic makes sense only if the failed query is actually treated as having been run successfully leaving an "empty" instance of the table
    Of course it does, evident by counting the number of the records in the query and getting zero. It ran and produced zero records. It does not "fail". If by "fail" you mean it never ran, I think we will never come to an agreement on this as it will be a chicken-egg scenario. How does it know that there are zero records meeting the filter if it never ran?
    I will leave it there as I exhausted every possible logic I have.
    Incidentally, it's not hard to find out if it does or does not run (fail), debug the script.
    Last edited by G Gabriel; 09-21-2008 at 07:59 PM.

  8. #8
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,310

    Default Re: <tb>.query_create()

    I'm ready to quit, too. Of course the query ran, but it "failed" to find any matching records. That's the whole point, right? Bye. -- tom

  9. #9
    "Certified" Alphaholic G Gabriel's Avatar
    Real Name
    G. Gabriel
    Join Date
    Oct 2004
    Posts
    7,204

    Default Re: <tb>.query_create()

    OK..back where we started.
    The script opened a new instance of the table.
    The query ran.
    It "failed", i.e. found zero records. 'let's leave these symantics for now.

    The new instance of the table, after the query ran, has zero records, yet the pointer goes to the first record!
    How?

    To further illustrate my point:
    Run the script from the code tab without any instances of the table being open.
    Close the code tab.
    Open the table.
    When you open the table, it should open empty with no records whatsover.
    Again, how did the pointer go to the first record when the table is empty?

    I am sorry, it's a bug. Will report it as such.
    Last edited by G Gabriel; 09-21-2008 at 08:53 PM.

  10. #10
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,310

    Default Re: <tb>.query_create()

    Ok. Let us know what you find out. -- tom

  11. #11
    "Certified" Alphaholic DaveM's Avatar
    Real Name
    Dave Mason
    Join Date
    Jul 2000
    Location
    Hudson, FL
    Posts
    6,026

    Default Re: <tb>.query_create()

    Gabe,

    I hope they don't fix it because we would then have another alpha box showing up when there are no records.

    I will have to rewrite a few of my queries. All the rest already count.

    But no, the one record should not show up if it does not belong.

    .
    Dave Mason
    dave@aldausa.com
    Skype is dave.mason46

  12. #12
    "Certified" Alphaholic G Gabriel's Avatar
    Real Name
    G. Gabriel
    Join Date
    Oct 2004
    Posts
    7,204

    Default Re: <tb>.query_create()

    Dave:
    Not exactly.
    It's more like if you attempt to use an array's subelement and the array is empty, alpha gives you an error message.
    Here if you are not paying attention, you could use values from the wrong record, the first record of the un-filtered table when in reality you souldn't be able to use any values since the query is empty.
    It should behave the same way an array does.
    Don't see why you would have to re-write your scripts. I am suggesting that alpha gives you that message when you are writing the code, not when the code is run.
    Last edited by G Gabriel; 09-21-2008 at 09:45 PM.

Similar Threads

  1. Having problem with query_create()
    By lemow in forum Alpha Five Version 7
    Replies: 30
    Last Post: 05-12-2006, 12:58 PM
  2. Problem using query_create()
    By Stephen Allard in forum Alpha Five Version 5
    Replies: 7
    Last Post: 11-21-2005, 12:25 AM
  3. tbl.query_create()
    By Duane Pederson in forum Alpha Five Version 5
    Replies: 6
    Last Post: 04-18-2004, 09:52 AM
  4. query_create issue
    By scottly in forum Alpha Five Version 5
    Replies: 7
    Last Post: 01-18-2004, 04:25 AM
  5. Query_Create and a Report from a Set
    By John De Jong, Jr. in forum Alpha Five Version 4
    Replies: 5
    Last Post: 01-30-2001, 06:51 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •