ApiTableCreate - cDbUpdateFunctionLibrary

Creates a new Table.


Type: Function


Parameters: Handle hTable String sRootName String sDisplayName String sLogicalName Boolean bUseConnectionID Boolean bANSI Boolean bRecnum

Parameter

Description

hTable

A file handle to the table name. Same as the Filelist.cfg slot number.

sRoot

The root name of the table

sDisplay

The display name of the table

sTableName

The table name or logical name of the table

bUseConnectionID

Should a connection ID be used (if SQL driver) for the .int file

bANSI

Should the table be created to contain ANSI data

bRecnum

Should the table use a Recnum field

tAPIColumn[]

Optional. A tAPIColumn struct array with field/column specifications


Syntax


Function ApiTableCreate Integer hTable String sRootName String sDisplayName String sTableName Boolean bUseConnectionID Boolean bANSI Boolean bRecnum tAPIColumn[] APIColumn

Call:

Get ApiTableCreate hTable "MyTable" "MyTable" "MyTable" True True True to bOK



Description

Use it to create a new table. The file handle should be a free file slot from Filelist.cfg. You can use the function NextFreeFilelistSlot to get one of those.

Note: If you want to remove a table use the ApiTableRemove function.


Example 1


Procedure OnUpdate

    Boolean bOK

    Handle hTable

   

    Get NextFreeFilelistSlot to hTable

    Get ApiTableCreate hTable "Sales" "Sales" "Sales" True True True to bOK


End_Procedure


Example 2


// Perhaps a bit more realistic example:    

Object oDbUpdateVersion1.1 is a cDbUpdateVersion

    Set pnVersionNumber to 1.1

       

    // This will create three new tables; MapConfig, MapGroup & MapLayer.

    // MapLayer relates to MapGroup and MapConfig is a system table

    Procedure OnUpdate

        Boolean bOK                                                                

        tAPIColumn[] APIColumn APIEmpty

        Integer iCount

           

        Move 0 to iCount                                  

        // New table: MapConfig First column:

        Move "Longitude"    to APIColumn[iCount].sFieldName

        Move SQL_CHAR       to APIColumn[iCount].iType

        Move 15             to APIColumn[iCount].iLength

        Move 0              to APIColumn[iCount].iPrecision

        Increment iCount

           

        // Second column

        Move "Latitude"     to APIColumn[iCount].sFieldName

        Move SQL_CHAR       to APIColumn[iCount].iType

        Move 15             to APIColumn[iCount].iLength

        Move 0              to APIColumn[iCount].iPrecision

        Increment iCount

           

        // Third column

        Move "ZoomFactor"   to APIColumn[iCount].sFieldName

        Move SQL_INTEGER    to APIColumn[iCount].iType

        Move 10             to APIColumn[iCount].iLength

        Move 0              to APIColumn[iCount].iPrecision

           

        Get ApiTableCreate 3010 "MapConfig" "MapConfig" "MapConfig" True True True APIColumn to bOK

        Get ApiTableChangeAttribute 3010 DF_FILE_IS_SYSTEM_FILE True to bOK


        // Reset variables

        Move APIEmpty to APIColumn

        Move 0        to iCount

         

        // New table: MapGroup - First column

        Move "ID"           to APIColumn[iCount].sFieldName

        Move SQL_INTEGER    to APIColumn[iCount].iType

        Move 10             to APIColumn[iCount].iLength

        Move 0              to APIColumn[iCount].iPrecision

        Move C_tAPIColumn_Identity to APIColumn[iCount].iOptions

        Increment iCount

           

        // Second column

        Move "Group"        to APIColumn[iCount].sFieldName

        Move SQL_CHAR       to APIColumn[iCount].iType

        Move 30             to APIColumn[iCount].iLength

        Move 0              to APIColumn[iCount].iPrecision

           

        Get ApiTableCreate 3011 "MapGroup" "MapGroup" "MapGroup" True True False APIColumn to bOK

        // No need to create an index here as the "ID" column already has been set to a primary key (C_tAPIColumn_Identity)

           

        // Reset variables

        Move APIEmpty to APIColumn

        Move 0        to iCount

           

        // New table: MapLayer - First column

        Move "ID"           to APIColumn[iCount].sFieldName

        Move SQL_INTEGER    to APIColumn[iCount].iType

        Move 10             to APIColumn[iCount].iLength

        Move 0              to APIColumn[iCount].iPrecision

        Move C_tAPIColumn_Identity to APIColumn[iCount].iOptions

        Increment iCount

           

        // Second column

        Move "GroupID"      to APIColumn[iCount].sFieldName

        Move SQL_INTEGER    to APIColumn[iCount].iType

        Move 10             to APIColumn[iCount].iLength

        Move 0              to APIColumn[iCount].iPrecision

        Increment iCount

           

        // Third column

        Move "DisplayLayer" to APIColumn[iCount].sFieldName

        Move SQL_CHAR       to APIColumn[iCount].iType

        Move 30             to APIColumn[iCount].iLength

        Move 0              to APIColumn[iCount].iPrecision

        Increment iCount

           

        // Fourth column

        Move "RealLayer"    to APIColumn[iCount].sFieldName

        Move SQL_CHAR       to APIColumn[iCount].iType

        Move 30             to APIColumn[iCount].iLength

        Move 0              to APIColumn[iCount].iPrecision

        Increment iCount

           

        // Fifth column

        Move "Visible"      to APIColumn[iCount].sFieldName

        Move SQL_TINYINT    to APIColumn[iCount].iType

        Move 3              to APIColumn[iCount].iLength

        Move 0              to APIColumn[iCount].iPrecision

        Increment iCount

           

        // Six column

        Move "Active"       to APIColumn[iCount].sFieldName

        Move SQL_TINYINT    to APIColumn[iCount].iType

        Move 3              to APIColumn[iCount].iLength

        Move 0              to APIColumn[iCount].iPrecision

        Increment iCount

           

        // Create table

        Get ApiTableCreate 3012 "MapLayer" "MapLayer" "MapLayer" True True True APIColumn to bOK

           

        // Create indexes

        // No need to create an index for the "ID" column as it has been set to be the primary key (C_tAPIColumn_Identity)

        Get APIIndexCreateByFieldNames 3012 2 "GROUPID,ID"      to bOK

        Get APIIndexCreateByFieldNames 3012 3 "DisplayLayer,ID" to bOK

        Get APIIndexCreateByFieldNames 3012 4 "RealLayer,ID"    to bOK

        Get APIIndexCreateByFieldNames 3012 5 "Visible,ID"      to bOK

        Get APIIndexCreateByFieldNames 3012 6 "Active,ID"       to bOK

           

        // Relate MapLayer.GroupID -> MapGroup.ID

        Get ApiTableRelate 3012 3011 2 1 to bOK

           

    End_Procedure

 

End_Object