makeTable(ctx, tablename, columns)
Makes a data import table. Will return an error if the table already exists. A column named
When a table is created a corresponding row is added to the
Parameters
Name | Type | Description |
---|---|---|
ctx | Struct, required | Database details, see above |
tablename | String, required | The name of the table to make. Name will be prepended with |
columns | Array of objects, required | Each item in the array is an object representing a column with the following properties |
columns[n].name | String, required | The name of the column |
columns[n].type | String, required | One of "DATETIME","INTEGER","FLOAT","VARCHAR","UUID","MEMO" |
columns[n].size | Integer, optional | The width of the field. Required when |
columns[n].nullable | Boolean, optional | Defaults to false. Whether or not the field supports null values |
columns[n].primaryKey | Boolean, optional | Whether this column forms part of the table's primary key |
columns[n].index | String, optional | The 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>