The JSColumn is a scripting object that represents a column in a data source, accessible through root objects like datasources and databaseManager. It provides methods for retrieving and managing metadata, properties, and flags associated with the column.
The object allows developers to interact with column-specific attributes such as data provider IDs, SQL names, types, lengths, and sequence configurations. It supports checking column flags, including primary key (PK_COLUMN), UUID, or tenant-specific columns, and retrieving the column’s row identifier type. Additionally, it provides access to design-time configurations like default formats, foreign key references, titles, and descriptions.
By enabling advanced operations such as quoting SQL identifiers and retrieving raw JDBC types, JSColumn ensures integration with the underlying database schema while maintaining scripting simplicity within the Servoy environment.
var table = databaseManager.getTable('db:/example_data/orders')
var column = table.getColumn('customerid')
switch (column.getSequenceType())
{
case JSColumn.NONE:
// handle column with no sequence
break;
case JSColumn.UUID_GENERATOR:
// handle uuid generated column
break;
}
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())
{
case JSColumn.NONE:
// handle column with no sequence
break;
case JSColumn.UUID_GENERATOR:
// handle uuid generated column
break;
}
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())
{
case JSColumn.TEXT:
// handle text column
break;
case JSColumn.NUMBER:
case JSColumn.INTEGER:
// handle numerical column
break;
}
EXCLUDED_COLUMN
Constant used when setting or getting the flags of columns.
This flag identifies columns that are skipped in the sql.
var table = databaseManager.getTable('db:/example_data/orders')
var column = table.getColumn('customerid')
switch (column.getType())
{
case JSColumn.TEXT:
// handle text column
break;
case JSColumn.NUMBER:
case JSColumn.INTEGER:
// handle numerical column
break;
}
MEDIA
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())
{
case JSColumn.TEXT:
// handle text column
break;
case JSColumn.NUMBER:
case JSColumn.INTEGER:
// handle numerical column
break;
}
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())
{
case JSColumn.NONE:
// handle column with no sequence
break;
case JSColumn.UUID_GENERATOR:
// handle uuid generated column
break;
}
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())
{
case JSColumn.TEXT:
// handle text column
break;
case JSColumn.NUMBER:
case JSColumn.INTEGER:
// handle numerical column
break;
}
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())
{
case JSColumn.NONE:
// handle normal column
break;
case JSColumn.PK_COLUMN:
// handle database pk column
break;
case JSColumn.ROWID_COLUMN:
// handle developer defined pk column
break;
}
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.getType())
{
case JSColumn.TEXT:
// handle text column
break;
case JSColumn.NUMBER:
case JSColumn.INTEGER:
// handle numerical column
break;
}
UUID_COLUMN
Constant used when setting or getting the flags of columns.
This flag identifies columns whose values are treated as UUID.
var table = databaseManager.getTable('db:/example_data/orders')
var column = table.getColumn('customerid')
switch (column.getSequenceType())
{
case JSColumn.NONE:
// handle column with no sequence
break;
case JSColumn.UUID_GENERATOR:
// handle uuid generated column
break;
}
var table = databaseManager.getTable('db:/example_data/orders')
var column = table.getColumn('customerid')
if (!column.getAllowNull())
{
// column cannot be null
}
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('customerid')
var dataProviderId = column.getDataProviderID()
var table = databaseManager.getTable('db:/example_data/orders')
var column = table.getColumn('customerid')
var foreignType = column.getForeignType()
if (foreignType != null)
{
var fkTable = databaseManager.getTable('example_data', foreignType)
}
getLength()
Get the length of the column as reported by the JDBC driver.
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.
var table = databaseManager.getTable('db:/example_data/orders')
var column = table.getColumn('customerid')
var qualifiedSqlName = column.getQualifiedName()
getQuotedSQLName()
Returns a quoted version of the column name, 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 quoted
var 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 scale = column.getScale()
getSequenceType()
Get 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 table = databaseManager.getTable('db:/example_data/orders')
var column = table.getColumn('customerid')
switch (column.getSequenceType())
{
case JSColumn.NONE:
// handle column with no sequence
break;
case JSColumn.UUID_GENERATOR:
// handle uuid generated column
break;
}
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')
switch (column.getType())
{
case JSColumn.TEXT:
// handle text column
break;
case JSColumn.NUMBER:
case JSColumn.INTEGER:
// handle numerical column
break;
}
getTypeAsString()
Get the name JDBC type of the column.
The same mapping as defined in JSColumn.getType() is applied.
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