Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2003
    Location
    Bucharest
    Posts
    11

    Unanswered: SELECT in FoxPro

    Hi,

    I have only a quick questions...

    If I make a select on a table into a cursor x and after that I make an another select on the cursor x, the third select on the cursor x is based on the original cursor x or on the already selected things?

    I read, that after a select is made, the cursor remains open only for reading. so can it be modified again and again?

    thanks...

  2. #2
    Join Date
    Nov 2003
    Posts
    8

    Re: SELECT in FoxPro

    The SELECT is based on whatever is in the FROM clause. So

    SELECT * FROM mytable INTO mycursor

    then

    SELECT * FROM mycursor INTO mycursor2

    would take data from mycursor whereas

    SELECT * FROM mytable INTO mycursor2

    would take it from mytable.

  3. #3
    Join Date
    Dec 2003
    Posts
    104
    AlanB is right in that the records in cursor2 are selected from cursor1. But, since the records in cursor1 are from the original table, so are the records in cursor2. Why not refine the query and do it in one pass?

    Also, you said "I read, that after a select is made, the cursor remains open only for reading. so can it be modified again and again?"
    There is a READWRITE clause in VFP 7, if that's what you are using, that enables you to create the cursor as writeable:
    Code:
    SELECT * FROM MyTable ;
       WHERE .... ;
       INTO CURSOR SomeCursor ;
       READWRITE
    But if you are using earlier versions of VFP, you can do something like:
    Code:
    SELECT * FROM MyTable ;
       WHERE .... ;
       INTO CURSOR SomeCursor 
    
    SELECT 0
    USE DBF('SomeCursor') AGAIN ALIAS NewAlias
    NewAlias will be read/write but beware: Any changes you make to the cursor NewAlias will be reflected in SomeCursor and the underlying table MyTable.
    Last edited by DSummZZZ; 01-06-04 at 11:55.
    DSummZZZ

    Even more Fox stuff at
    www.davesummers.net/foxprolinks.htm

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest
    Posts
    11
    I meant the following syntax:


    SELECT * FROM mytable INTO mycursor

    SELECT * FROM mycursor INTO mycursor

    SELECT * FROM mycursor INTO mycursor


    I make some operations on them.
    Question is: takes select in the third row the modified data form the second row, or it takes the "original" data form the first row?

  5. #5
    Join Date
    Dec 2003
    Posts
    104
    Here's what happens.
    SELECT * FROM MyTable INTO CURSOR mycursor

    A temp table gets created in your SORTWORK directory. That temp table will have a unique name determined by VFP and will have an alias of 'Query' while the query runs.
    Upon completion, that temp table will now have an alias of 'MyCursor'.
    It gets populated with the records corresponding to the criteria, which in this case is all of them. If there is a small number of records, it will be a subset of records from the original table buffered in memory, but with a file handle open on the drive. A large subset will be periodically written to disk.

    SELECT * from mycursor INTO CURSOR mycursor
    Another temp table is created on disk in the SORTWORK directory to hold the new set of records, with another unique name created by VFP.
    Again, at the time the query runs, the new cursor will have an alias of 'Query'. As soon as the query has finished, the original temp table with an alias of 'MyCursor' will be closed, and the new temp table will remain open with the ALIAS of 'MyCursor'.

    If you want, run the following lines of code:
    Code:
    SELECT * FROM MyTable INTO CURSOR mycursor
    ?Dbf('mycursor')
    SELECT * from mycursor INTO CURSOR mycursor
    ?Dbf('mycursor')
    SELECT * from mycursor INTO CURSOR mycursor
    ?Dbf('mycursor')
    SELECT * from mycursor INTO CURSOR mycursor
    ?Dbf('mycursor')
    .
    .
    .
    DSummZZZ

    Even more Fox stuff at
    www.davesummers.net/foxprolinks.htm

  6. #6
    Join Date
    Dec 2003
    Location
    Bucharest
    Posts
    11
    Thanx for the detailed answer...
    I understand now...

    And thanx for the termometer("R") reply too

Posting Permissions

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