MapInfo Pro

Expand all | Collapse all

Getting wrong results for column values of query

  • 1.  Getting wrong results for column values of query

    Posted 12-14-2018 06:34
      |   view attached
    Hi there,

    last week on customer site i experienced a really odd behaviour of MiPro when trying to get the column value of a query, and it's really easy to reproduce:

    - Open a fresh MiPro (today i used 17.02 last week it was 17.01)
    - Open whatever table you like (attached you find 6 records from an OSM-Table) and display it in a map window
    - select one Record however you like, and browse this selection, so you get Browse-Window showing Query1
    - Open a mapbasic window and query a colunnvalue, here it would be: print Query1.osm_id
    The current column value gets printed in the message window - so far so good.

    Ik8FrCEaSU2EXTqKQtNJ_Query_test_1.png
    - Now open a browse window of the complete original table and select one different record, - you get a new SELECTION
    - Now issue the same command in the mapbasic window: print Query1.osm_id
    ---> since Query1 didn't change, the result should be the same as before
    BUT: The result is rather astonishing: a completely different value gets printed, it neither the original and not the new selected column value

    2uYj2IBR6qG6iobuzkeg_Query_test_2.png
    I cannot find any logical explanation of this behaviour, - did i anything wrong?

    Cheers
    Stefan

    Attachment(s)

    zip
    Query_Test.zip   1K 1 version


  • 2.  RE: Getting wrong results for column values of query

    Pitney Bowes
    Posted 12-14-2018 08:25
    Always use Fetch statement to set the table's cursor position. Most of the time it goes unnoticed because table cursor position often goes unchanged, but there are multiple events that can cause it to change so it is no longer current.  If you had called Fetch first from Query1, then printed the the result, it would have been consistent.
    Cheers.

    ------------------------------
    Bill Wemple
    Knowledge Community Shared Account
    Shelton CT
    ------------------------------



  • 3.  RE: Getting wrong results for column values of query

    Posted 12-14-2018 10:23
    Bill,

    thanks for your fast Reply.

    You'r right: when issuing a "Fetch First" before doing the second print Query1.osm_id, the correct value is displayed.
    BUT:
    - The Table Query1 in this example has only one record, whereelse should the cursor point to?
    - i didn't move the tables cursor position after the first print statment, so why should it leave it's Position?
    - the value that gets returned by the second print statment in this example is not present in the Query1 table, to return this value when   querying that table doesn't make sense at all
    So either should there be an error message like: undefined cursor position, or the cursor of that table should stay put and always return the same value.

    I tried the same Scenario with a fetch first before the first Access to the table Query1, - and the result is the same, so only if i issue that fetch first Statement twice to access the same, one and only record i get the desired result.
    Try to imagine that Scenario in a mapbasic program where you position your table Cursor once, then do some stuff with other tables or queries, and then need to Access other column values of the same record of the first table, - i wouldn't think about positioning the Cursor again, and most probably search forever for the reason why that program returns wonderland values instead of an error message.

    Yes, you can circumvent this with consequently issuing Fetch Statements before each query to column values, but from my Point of view this is still not an optimal behaviour.

    Stefan



  • 4.  RE: Getting wrong results for column values of query

    Pitney Bowes
    Posted 01-08-2019 10:55
    Stefan,
    Bill's comments are correct but perhaps what is not clear is that for each base table, there is ALWAYS a current record and its values are what are accessed when you reference a column to get its data.

    Let's say I have a table with 3 single line query (query1, query2, query3) .
    Now you go to the mapbasic window and put in your print statement (Print queryx.col )
    What happens when you do this is that whatever data is in the internal fetch buffer for that base table is returned.
    This could be the value from query 1, 2 or 3 Or it could be any record from the basetable. For example, if that table was in a map with labels on or a theme (something that forces us to read the attribute data), then the last record read in that map draw will be returned. Of course, any fetches you do in the mapbasic window, even on a different query table, affect that as well.
    There is absolutely no way to determine what data might be returned without a fetch.
    There​fore, the answer is that one must always provide a fetch before accessing data.
    Note that in a compiled mapbasic program, each program internally remembers what record it last used for each table.  This ensures that no fetches by other programs or MapInfo interactively (Including your print statements) change the values your program retrieves as long as you have done the appropriate fetches.

    I hope this helps.  This behavior has been there "forever".

    ------------------------------
    Eric Blasenheim
    Spectrum Spatial Technical Product Manager
    Troy, NY
    ------------------------------