Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Altering a CUSOR's structure
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00062738
Message ID:
00063068
Vues:
62
>>>>>>So far as I'm aware you can't other than getting the name of the temporary table with DBF() then USEing the table again in another area. If you have dependent forms, grid controls, etc on that cursor though you may well end up with inconsistencies between buffered data and data actually stored.
>>>>>>
>>>>>>If you know that you want a particular structure in a cursor then modify the SQL that creates it in the first place. You can create place holders for any of the standard field types in SQL.
>>>>>>
>>>>>>i.e. Select *, 0.00 as NewNumber, Space(10) newindex, date() as newdate from fred into cursor jim
>>>>>>
>>>>>>
>>>>>>>Does anyone know how to alter a cursor after it is created with CREATE CURSOR?
>>>>>>>I have found ALTER TABLE, but no ALTER CURSOR.
>>>>>>> Thanks.
>>>>>I have tried to get the DBF() but, there is no guarantee that the the DBF() of a cursor exists as a file. I also got a 'Table in Use' error when attempting to ALTER TABLE the USEd AGAIN version.
>>>>>I was playing with the idea of altering the structure of a cursor based on run-time information. I guess I'll just have to use CREATE/ALTER TABLE and handle clean up myself or forget about it.
>>>>> Thank you for the response.
>>>>
>>>>A cursor is temporary and disappears as soon as it is closed. To alter any table structure you have to have exclusive use. So, if you have SET EXCLUSIVE ON before you issue the command to create it, you would have exclusive access to the cursor. The ALTER TABLE will work. AFter you create the cursor you can return the EXCLUSIVE setting back to the way it was -- store the original value using SET("EXCLUSIVE"). Since you are using a cursor, there is no reason not to have exclusive access to it, even in multi-user environment. Just the use the DBF() function to get its actual name.
>>>
>>>Interesting approach. I still don't see how to guarantee that the TMP file returned by DBF() exists. Isn't it possible to get back a file name for the TMP file that VFP will create when the cursor becomes too large to fit in memory? If I could guarantee that the cursor would have a disk presence, then your approach would solve my problem.
>>
>>Any cursor created with CREATE CURSOR (if SET EXCLUSIVE is ON before created) can be modified with MODIFY STRUCTURE or ALTER TABLE. You do not need to know the actual tempfile name, just use the alias you used in the CREATE CURSOR FILENAME command. I created a cursor that existed in memory only (no .tmp existed on disk) and am still able to alter its structure on the fly. If the cursor is too big to fit in memory it will show up on disk. Regardless of cursor size or location, you can still alter the structure as long as it was created with exclusive on. The odd behaviour is that a cursor created by a SELECT-SQL (regardless of SET EXCLUSIVE) is read-only.
>
>Neat!
>This answers my question. As to the odd behavior of SELECT-SQL cursors, I've been using USE DBF("Query") AGAIN to get around that one for years. I agree, odd. Thanks.

ps. I did a little checking of my own. SET EXCLUSIVE does not seem to matter. I issued SET EXCLUSIVE OFF, CREATE CURSOR, ALTER TABLE ADD COLUMN, ALTER TABLE DROP COLUMN and had no problems. Apparently cursors from CREATE CURSOR are always USEd EXCLUSIVEly. This should simplify things a bit.
Ned

Reality is.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform