Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- RaSQL/B 6.1a for Clipper - <b>n_xmaketbl()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
N_XMAKETBL()
Create table from extended structure DBF

Syntax
N_XMAKETBL(<cTable>, <cFilespec>, <cDBF>)

RDD Option
CREATE FROM or __DBCREATE()

Arguments
<cTable> is ignored and may be a null string. It is used only with RaSQL/X.

<cFilespec> is the name of the Btrieve file to create. If it omits a path 
name then RaSQL creates the Btrieve table in the directory named in N_XPATH, 
if specified; otherwise in the current directory.

<cDBF> is the name of an extended structure DBF.

Remarks
Creates a table from a special extendedstructure DBF.  N_XMAKETBL() is 
similar in concept to the Clipper command CREATE FROM. The special DBF is a 
modified version of the structure used by the CREATE FROM command.

The list below shows the file structure. The file RASQL.DBF included on the 
RaSQL/B diskette also contains this structure.

Structure: RASQL.DBF

   Field          Type Length    Description
     FIELD_NAME     C     20       Field name
     FIELD_TYPE     C      2       Field type
     FIELD_LEN      N      5       Field display length
     FIELD_DEC      N      3       Number of positions after decimal
     FIELD_SLEN     N      5       Internal storage length of field. 
                                   (Optional, but if specified, overrides 
                                   FIELD_LEN)

Remaining fields are index key attributes

     MORE           L     1        .T. = Segmented key (more than one field)
     UNIQUE         L     1        .T. = no duplicates allowed
     NULLS          L     1        .T. = null keys are not indexed
     UPPERCASE      L     1        .T. = key value is case insensitive
     DESCENDING     L     1        .T. = index in descending order
     STATIC         L     1        .T. = key cannot be modified

Creating a table

Define the field definitions in the extendedstructure file

You may use RASQL.DBF itself, copy the structure of RASQL.DBF to a work DBF, 
or create a work DBF with N_XMAKEDBF().

Field names may be up to twenty characters. It will be helpful for future 
programming, however, if you keep field names unique within the first ten 
characters, and if  you use only letters, numbers and underscores '_'.

Specify the data type in FIELD_TYPE. It may be C, N, L, D, M, or any of the 
extended types listed in Appendix ?. 

You may have only one variable length field (M or ML) per record. If 
defined, it must be the last field in the record.

Specify the display length in FIELD_LEN. RaSQL/B will calculate the optimal 
internal storage length. Alternatively, you can specify an internal storage 
length directly in FIELD_SLEN. This is more exact and will override any 
value in FIELD_LEN.

Allowable lengths are based on data type and are listed in Appendix ?.

For a variable length field (type M or ML) specify the maximum length of the 
field. Keep the value as low as realistically possible; doing so will not 
affect disk space, but will use memory more efficiently.

Total record length (excluding variable length field, if present) must be _ 
4096 bytes.

Define the index fields and attributes

Set MORE to True to specify a segmented index  (that is, contains more that 
one field). However, on the last segment,  you must set MORE to False.

Set UNIQUE to True if the index is a unique key for the table. If the index 
is segmented, all segments in the index must have the same setting.

Set UPPERCASE to True if the field is case insensitive. Fields in a 
segmented index can have different settings of UPPERCASE. In addition, if a 
field participates in more than one index, it can have different settings of 
UPPERCASE.

Set DESCENDING to True to index the field in descending order. Fields in a 
segmented index can have different settings of DESCENDING. In addition, if a 
field participates in more than one index, it can have different settings of 
DESCENDING.

Set NULLS to True to omit the key from the index if the  field(s) in the 
index are empty. If the index is segmented, all segments in the index must 
have the same setting. 

At least one index in a table must be left as NULLS = .F.

Set STATIC to True to prevent someone from modifying the key value after 
adding the record. (Exception:  you can change an empty key with the NULL 
attribute to a non-NULL value one time.)  If the key is segmented, all 
segments in the index must have the same setting.

Create the Table with N_XMAKETBL()

As arguments, specify a null string, the name of the  Btrieve file, and the 
name of the extendedstructure file containing the definition. (RaSQL/B 
ignores the first argument, <cTable>; it is needed in RaSQL/X and is left in 
place here to facilitate transition to RaSQL/X.)

Btrieve will not overwrite  an existing file unless you have specified 
N_XSAFETY(.T.).

An Autoincremented field must be defined as a Unique, Static nonsegmented 
index, or it will default to a standard integer type NI.

Example
* Convert CLIENTS.DBF to a Table
USE clients.dbf
COPY STRUCTURE EXTENDED TO temp.dbf
USE rasql.dbf
ZAP
APPEND FROM temp.dbf

* index 1 is on ClientNo, which should be 
* unique.  Index 2 is on 
* UPPER(LastName + FirstName + Initial)
APPEND BLANK

REPLACE FIELD_NAME WITH 'ClientNo', ;
        FIELD_TYPE WITH 'X', ;
        UNIQUE WITH .T.
APPEND BLANK

REPLACE FIELD_NAME WITH 'LastName', ;
        FIELD_TYPE WITH 'X', ;
        UPPERCASE WITH .T., ;
        MORE WITH .T.
APPEND BLANK

REPLACE FIELD_NAME WITH 'FirstName', ;
        FIELD_TYPE WITH 'X', ;
        UPPERCASE WITH .T., ;
        MORE WITH .T.
APPEND BLANK

REPLACE FIELD_NAME WITH 'Initial', ;
        FIELD_TYPE WITH 'X', ;
        UPPERCASE WITH .T.
USE

* Create new table
N_XMAKETBL(''     ; && Null string.
      'client.dat', ; && Resulting DD table
                    ; && name.
      'rasql.dbf')  ; && DOS file name
                    ; && where data is
                    ; && stored.


See Also: Appendix A N_XAMAKENDX() N_XAMAKETBL() N_XMAKENDX() N_XOWNER() N_XSAFETY() N_XSETFLAGS()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson