A scripting object representing a data-source column that has now been created via JSTableObject.createNewColumn(...).
It is a JSColumn that has a few extra methods - setters that can modify it; the changes will be applied only by a server.synchronizeWithDB() call.
Constants Summarized
Type
Name
Summary
Properties Summarized
Methods Summarized
Constants Detailed
DATABASE_IDENTITY
Constant used when setting or getting the sequence type of columns.
var table =databaseManager.getTable('db:/example_data/orders')var column =table.getColumn('customerid')switch (column.getSequenceType()){caseJSColumn.NONE:// handle column with no sequencebreak;caseJSColumn.UUID_GENERATOR:// handle uuid generated columnbreak;}
DATABASE_SEQUENCE
Constant used when setting or getting the sequence type of columns.
var table =databaseManager.getTable('db:/example_data/orders')var column =table.getColumn('customerid')switch (column.getSequenceType()){caseJSColumn.NONE:// handle column with no sequencebreak;caseJSColumn.UUID_GENERATOR:// handle uuid generated columnbreak;}
DATETIME
Constant used when setting or getting the type of columns.
var table =databaseManager.getTable('db:/example_data/orders')var column =table.getColumn('customerid')switch (column.getType()){caseJSColumn.TEXT:// handle text columnbreak;caseJSColumn.NUMBER:caseJSColumn.INTEGER:// handle numerical columnbreak;}
NATIVE_COLUMN
Constant used when setting or getting the flags of columns.
This flag identifies columns that are marked as a native type column (for example uniqueidentifier).
var table =databaseManager.getTable('db:/example_data/orders')var column =table.getColumn('customerid')switch (column.getSequenceType()){caseJSColumn.NONE:// handle column with no sequencebreak;caseJSColumn.UUID_GENERATOR:// handle uuid generated columnbreak;}
NUMBER
Constant used when setting or getting the type of columns.
var table =databaseManager.getTable('db:/example_data/orders')var column =table.getColumn('customerid')switch (column.getType()){caseJSColumn.TEXT:// handle text columnbreak;caseJSColumn.NUMBER:caseJSColumn.INTEGER:// handle numerical columnbreak;}
PK_COLUMN
Constant used when setting or getting the row identifier type of columns.
This value identifies columns that are defined as primary key in the database.
var table =databaseManager.getTable('db:/example_data/orders')var column =table.getColumn('customerid')switch (column.getRowIdentifierType()){caseJSColumn.NONE:// handle normal columnbreak;caseJSColumn.PK_COLUMN:// handle database pk columnbreak;caseJSColumn.ROWID_COLUMN:// handle developer defined pk columnbreak;}
ROWID_COLUMN
Constant used when setting or getting the row identifier type of columns.
This value identifies columns that are defined as primary key by the developer (but not in the database).
var table =databaseManager.getTable('db:/example_data/orders')var column =table.getColumn('customerid')switch (column.getSequenceType()){caseJSColumn.NONE:// handle column with no sequencebreak;caseJSColumn.UUID_GENERATOR:// handle uuid generated columnbreak;}
Properties Detailed
allowNull
Get or set the allow-null flag of a new column.
Note that when a column is added to an existing table, allowNull will always be set.
For a primary key column, the allowNull flag will be always off, for other columns the flag is set by default.
var server =plugins.maintenance.getServer("example_data");if (server){var table =server.createNewTable("users");if (table) {var pk =table.createNewColumn("id",JSColumn.MEDIA,16); // can also use (JSColumn.TEXT, 36) for UUIDspk.rowIdentifierType =JSColumn.PK_COLUMN;pk.setFlag(JSColumn.UUID_COLUMN,true)pk.sequenceType =JSColumn.UUID_GENERATORvar c =table.createNewColumn("name",JSColumn.TEXT,100);c.allowNull =falsetable.createNewColumn("age",JSColumn.INTEGER,0);table.createNewColumn("last_login",JSColumn.DATETIME,0);var result =server.synchronizeWithDB(table);if (result) application.output("Table successfully created.");elseapplication.output("Table not created."); }}
rowIdentifierType
Get or set the row identifier type of the column.
The sequence type is one of:
- JSColumn.PK_COLUMN
- JSColumn.ROWID_COLUMN
- JSColumn.NONE
var server =plugins.maintenance.getServer("example_data");if (server){// users has uuid pkvar table =server.createNewTable("users");if (table) {var pk =table.createNewColumn("id",JSColumn.MEDIA,16); // can also use <JSColumn.TEXT, 36> for UUIDs)pk.rowIdentifierType =JSColumn.PK_COLUMN;pk.setFlag(JSColumn.UUID_COLUMN,true)pk.sequenceType =JSColumn.UUID_GENERATORtable.createNewColumn("name",JSColumn.TEXT,100);var result =server.synchronizeWithDB(table);if (result) application.output("Table users successfully created.");elseapplication.output("Table users not created."); }// groups has database sequence pk table =server.createNewTable("groups");if (table) { pk =table.createNewColumn("id",JSColumn.INTEGER,0);pk.rowIdentifierType =JSColumn.PK_COLUMN;pk.sequenceType =JSColumn.DATABASE_SEQUENCEpk.setDatabaseSequenceName('mygroupsequence')table.createNewColumn("name",JSColumn.TEXT,100); result =server.synchronizeWithDB(table);if (result) application.output("Table groups successfully created.");elseapplication.output("Table groups not created."); }}
sequenceType
Get or set the sequence type of the column.
The sequence type is one of:
- JSColumn.NONE
- JSColumn.SERVOY_SEQUENCE
- JSColumn.DATABASE_SEQUENCE
- JSColumn.DATABASE_IDENTITY
- JSColumn.UUID_GENERATOR;
var server =plugins.maintenance.getServer("example_data");if (server){// users has uuid pkvar table =server.createNewTable("users");if (table) {var pk =table.createNewColumn("id",JSColumn.MEDIA,16); // can also use <JSColumn.TEXT, 36> for UUIDs)pk.rowIdentifierType =JSColumn.PK_COLUMN;pk.setFlag(JSColumn.UUID_COLUMN,true)pk.sequenceType =JSColumn.UUID_GENERATORtable.createNewColumn("name",JSColumn.TEXT,100);var result =server.synchronizeWithDB(table);if (result) application.output("Table users successfully created.");elseapplication.output("Table users not created."); }// groups has database sequence pk table =server.createNewTable("groups");if (table) { pk =table.createNewColumn("id",JSColumn.INTEGER,0);pk.rowIdentifierType =JSColumn.PK_COLUMN;pk.sequenceType =JSColumn.DATABASE_SEQUENCEpk.setDatabaseSequenceName('mygroupsequence')table.createNewColumn("name",JSColumn.TEXT,100); result =server.synchronizeWithDB(table);if (result) application.output("Table groups successfully created.");elseapplication.output("Table groups not created."); }}
Methods Detailed
getDataProviderID()
Get the data provider id for this column (which is the same as name if not explicitly defined otherwise).
var table =databaseManager.getTable('db:/example_data/orders')var column =table.getColumn('customername')if (column.getLength() <10){// handle short column}
var table =databaseManager.getTable('db:/example_data/orders')var column =table.getColumn('customerid')var colName =column.getName()
getQualifiedName()
Get the qualified name (including table name) of the column as known by the database.
The name is quoted, if necessary, as defined by the actual database used.
//use with the raw SQL plugin://if the table name contains characters that are illegal in sql, the table name will be quotedvar jsTable =databaseManager.getTable('udm','campaigns')var quotedTableName =jsTable.getQuotedSQLName()var jsColumn =jsTable.getColumn('active')var quotedColumnName =jsColumn.getQuotedSQLName()plugins.rawSQL.executeSQL('udm', quotedTableName, 'select * from ' + quotedTableName + ' where ' + quotedColumnName + ' = ?', [1])
var table =databaseManager.getTable('db:/example_data/orders')var column =table.getColumn('customername')var title =column.getTitle()
getType()
Get the JDBC type of the column.
The type reported by the JDBC driver will be mapped to one of:
- JSColumn.DATETIME
- JSColumn.TEXT
- JSColumn.NUMBER
- JSColumn.INTEGER
- JSColumn.MEDIA
var table =databaseManager.getTable('db:/example_data/orders')var column =table.getColumn('customerid')var typeName =column.getTypeAsString()
hasFlag(flag)
Check a flag of the column.
The flags are a bit pattern consisting of 1 or more of the following bits:
- JSColumn.UUID_COLUMN
- JSColumn.EXCLUDED_COLUMN
- JSColumn.TENANT_COLUMN
- JSColumn.NATIVE_COLUMN
var server =plugins.maintenance.getServer("example_data");if (server){// users has uuid pkvar table =server.createNewTable("users");if (table) {var pk =table.createNewColumn("id",JSColumn.MEDIA,16); // can also use <JSColumn.TEXT, 36> for UUIDs)pk.rowIdentifierType =JSColumn.PK_COLUMN;pk.setFlag(JSColumn.UUID_COLUMN,true)pk.sequenceType =JSColumn.UUID_GENERATORtable.createNewColumn("name",JSColumn.TEXT,100);var result =server.synchronizeWithDB(table);if (result) application.output("Table users successfully created.");elseapplication.output("Table users not created."); }// groups has database sequence pk table =server.createNewTable("groups");if (table) { pk =table.createNewColumn("id",JSColumn.INTEGER,0);pk.rowIdentifierType =JSColumn.PK_COLUMN;pk.sequenceType =JSColumn.DATABASE_SEQUENCEpk.setDatabaseSequenceName('mygroupsequence')table.createNewColumn("name",JSColumn.TEXT,100); result =server.synchronizeWithDB(table);if (result) application.output("Table groups successfully created.");elseapplication.output("Table groups not created."); }}
setFlag(flag, set)
Set or clear a flag of a new column.
The flags are a bit pattern consisting of 1 or more of the following bits:
- JSColumn.UUID_COLUMN;
- JSColumn.EXCLUDED_COLUMN;
Booleanset true for set flag, false for clear flag
Returns: void
Sample
var server =plugins.maintenance.getServer("example_data");if (server){var table =server.createNewTable("users");if (table) {var pk =table.createNewColumn("id",JSColumn.MEDIA,16); // can also use (JSColumn.TEXT, 36) for UUIDspk.rowIdentifierType =JSColumn.PK_COLUMN;pk.setFlag(JSColumn.UUID_COLUMN,true)pk.sequenceType =JSColumn.UUID_GENERATORvar c =table.createNewColumn("name",JSColumn.TEXT,100);c.allowNull =falsetable.createNewColumn("age",JSColumn.INTEGER,0);table.createNewColumn("last_login",JSColumn.DATETIME,0);var result =server.synchronizeWithDB(table);if (result) application.output("Table successfully created.");elseapplication.output("Table not created."); }}