Wiki Home

Add Column Problem


Namespace: Wiki
It seems that a cursor with a field name longer than 10 characters is resistant to change
with 'Alter table add column'. I'm in Fox 8. Joe Kuhn
* second alter table produces error 1115 "Invalid operation for the cursor."
* help on the error says "An attempt was made to use the PACK command on a cursor."  Huh?

Create Cursor csrTst (field1 i)
Alter Table csrTst add column field2 i
USE in csrTst

Create Cursor csrTst (field_name_longer_than_10 i)
Alter Table csrTst add column field2 i

The same thing happens in VFP7. I think it has to do with the fact that CREATE CURSOR produces a free table rather than a table in a database; so field names are limited to 10 chars.

If you: Create Cursor csrTst (field_name_longer_than_10 i)
and then: modify structure to add field2, VFP truncates the name of the first field from
"field_name_longer_than_10" to "field_name"
--- Kevin Goh
It's a normal behavior, but it can be done with SELECT-SQL querys:
SELECT *,$0 as MyYieldField FROM csrTst ;
  INTO CURSOR csrTst READWRITE

Just a workarround when you want to add a Memo Field:
CREATE CURSOR Dummie (LongMemoField M)
APPEND BLANK  IN "Dummie"

SELECT * FROM csrTst, Dummie ;
      INTO CURSOR csrTst READWRITE


Spanish article about it:
--- Truco: Agregar Columnas a Cursores VFP ---
http://www.portalfox.com/article.php?sid=992

Esparta Palma

---
From the VFP help file - It is there in VFP7/8/9, don't know about earlier versions:

ALTER TABLE might not produce consistent results when used with Visual FoxPro cursors created by the CREATE CURSOR command. In particular, you can create a Visual FoxPro cursor with features, such as long field names, that are normally available only with tables that are part of a database container. ALTER TABLE saves a temporary copy of the cursor, so the rules that apply to free tables also apply, and any features requiring database support are lost or changed in an unpredictable manner. Therefore, you should generally avoid using ALTER TABLE with Visual FoxPro cursors unless you have tested and understood the outcome.

-- Igor Korolyov

In these days of electronic ONLY documentation, this item deserves to be included under the CREATE CURSOR - SQL topic too. And in both cases they should be labelled as "WARNING" and not included as just another "Remark"! But credit is deserved for at least having it noted somewhere.-- Jim Nelson
Category VFP Commands Category Code Samples
( Topic last updated: 2005.07.05 09:11:11 AM )