Create Cursor
This command lets you create a temporary table. Cursors created this way are read-write (like those created for views, but unlike those created by SELECT-SQL without the READWRITE clause). Cursors are not part of a database, but can have several features normally found only in database-contained tables.
Usage |
CREATE CURSOR Alias ( Fieldname1 Fieldtype1 [( nSize1 [ , nDecimals1 ] ) [ NULL | NOT NULL ] [ CHECK lFieldRule1 [ ERROR cRuleText1 ] ] [ DEFAULT eDefault1 ] [ UNIQUE ] [ NOCPTRANS ] ] [ , Fieldname2 ... ] ) | FROM ARRAY aFieldArray |
Parameter |
Value |
Meaning |
Alias |
Name |
The alias to assign to the newly created cursor. This is not a file name and does not have to be unique across users. |
Fieldnamex |
Name |
The name of the xth field in the cursor. |
Fieldtypex |
Single letter |
The letter denoting the type of the xth field in the cursor. See Help for a list. |
nSizex |
Numeric |
The size of the xth field. |
nDecimalsx |
Numeric |
The number of decimal places in the xth field. |
lFieldRulex |
Logical |
The field-level rule for the xth field. |
cRuleTextx |
Character |
The error message to use when the field-level rule for the xth field is violated. |
eDefaultx |
Expression |
An expression that evaluates to the default value for the xth field. |
aFieldArray |
Array |
An array containing definition information for the cursor. |
In VFP 3.0 and 3.0b, when you use the UNIQUE clause to create a compound index (CDX) for a cursor, closing the cursor doesn't clean up the CDX. Instead, the CDX file is left behind in the directory specified for temporary files. You can identify it there by its all-digit name followed by a CDX extension. This bug is fixed in later versions. |
Beware of the number of fields in the cursor you are trying to create. CREATE CURSOR FROM ARRAY crashes Visual FoxPro 3.x with an Invalid Page Fault if there are more than 316 rows (that is, fields to be created), and generates the error "Function argument value, type or count is invalid" for 313 to 315 fields listed. Weirdly enough, it can create up to 312 fields. VFP 5.0 crashes with an Invalid Page Fault at 256 fields. VFP 6 finally gets it right with either "Array dimensions are invalid" for 5-column arrays or "Too many columns" for 5+ column arrays if the array contains 256 or more rows. VFP 7 just returns "Array dimensions are invalid." The bottom line is that no version of FoxPro supports any more than 255 fields. We wouldn't count on creating these nonstandard cursors. |
If any of the fields supports NULL, you are limited to 254 columns because of the hidden "_NullFlags" column (see "Nulls" in "DBF, FPT, CDX, DBC—Hike!") |
Example |
CREATE CURSOR Temp (CharFld C(10) UNIQUE, ; NumFld N(3) CHECK NumFld>25, ; DateFld D DEFAULT DATE()) * Create a cursor identical to the Customer table. USE Customer =AFIELDS(aFieldList) CREATE CURSOR NewCust FROM ARRAY aFieldList |
See Also |
AFields(), Create, Create Table, CursorGetProp(), Index, Select-SQL, Use |