Toggle menu

makeTable

makeTable(ctx, tablename, columns)

Makes a data import table. Will return an error if the table already exists. A column named DI_version is automatically created in every table.

When a table is created a corresponding row is added to the DI_META_tables_v1 table. This table records the names and latest version of each data import table. The version number increases each time (non-appended) data is imported into a table.

Parameters

NameTypeDescription
ctxStruct, requiredDatabase details, see above
tablenameString, requiredThe name of the table to make. Name will be prepended with DI_. The name _META is reserved
columnsArray of objects, requiredEach item in the array is an object representing a column with the following properties
columns[n].nameString, requiredThe name of the column
columns[n].typeString, requiredOne of "DATETIME","INTEGER","FLOAT","VARCHAR","UUID","MEMO"
columns[n].sizeInteger, optionalThe width of the field. Required when type:"VARCHAR"
columns[n].nullableBoolean, optionalDefaults to false. Whether or not the field supports null values
columns[n].primaryKeyBoolean, optionalWhether this column forms part of the table's primary key
columns[n].indexString, optionalThe name of an index this column appears in

Returns

Boolean. True if the table was created successfully.

Example

<cfset ds=APPLICATION.datasource>
<cfset dt=APPLICATION.databasetype>
<cfset tablename="timstable">
<!--- get a data importer --->
<cfmodule template="/icm/admin/dataimport/importer_v1.cfm" name="di" datasource=#ds# databasetype=#dt#>
<!--- the columns --->
<cfset tableColumns=[
    {"name":"FirstName", "type":"VARCHAR", "size":60},
    {"name":"LastName", "type":"VARCHAR", "size":60},
    {"name":"Address", "type":"VARCHAR", "size":240},
    {"name":"City", "type":"VARCHAR", "size":60},
    {"name":"County", "type":"VARCHAR", "size":60},
    {"name":"PostCode", "type":"VARCHAR", "size":12}
]>
<!--- create the table --->
<cfset maketable = di.makeTable(ctx=#di#, tablename=#tablename#, columns=#tableColumns#)>
<cfoutput>Done. Result:[#maketable#]</cfoutput><cfflush>

Last modified on September 30, 2022

Share this page

Facebook icon Twitter icon email icon

Print

print icon