The Database Metadata class provides a way to access comprehensive information about the database as a whole. It provides the following functions:

1 Objects existence

In some cases you need to detect if a table or function exists in database catalog to perform actions according. You can ask for the presence of database objects by using:

Return Method
boolean existsTable(String tableName)
boolean existsFunction(String functionName)
boolean existsProcedure(String procedureName)

2 Getting metadata

You can obtain database metadata object from database by using:

Return Method
JSDatabaseMetaData getMetaData()
JSDatabaseMetaData getMetaData(boolean refresh)

Database Metadata may be cached across subsequent calls and other processes. If you want to aquire a fresh metadata you should use the refresh option. In that case, a new metadata will be provided. This is critical if you are creating or altering database structures.

Database Metadata has the following functions.

Return Method Description
String[] getTables() Get list of all database tables
String[] getTables(String tableNamePattern, String[] types) Get list of match tableNamePattern tables. Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
Boolean existsTable(String tableName) True if tableName exists and is normal table
String[] getColumnNames(String tableNamePattern) Get all columns of all tables types
String[] getColumnTypes(String tableNamePattern) Get all columns types of all tables types
String[] getColumnsExcludingTypes(String tableNamePattern, String...sqltypes)
String[] getColumnsIncludingTypes(String tableNamePattern, String...sqltypes)
JSResultSet getExportedKeys(String tableNamePattern)
JSResultSet getImportedKeys(String tableNamePattern)
JSResultSet getPrimaryKeys(String tableNamePattern)
String[] getPrimaryKeyColumns(String tableNamePattern)
JSTableMetaData getTableMetaData(String tabname)
JSTableMetaData getTableMetaData(String tabname, boolean refresh)

2.1 Getting tables

You can get the list of tables matching a LIKE condition (NULL or % for ALL) and for a specific table type.

2.1.1 Get tables


console.log(Ax.db.getMetaData().getTables("systables", "SYSTEM TABLES"));

2.1.2 Check table exists

Ax.db.execute('DROP TABLE IF EXISTS test')
Ax.db.execute('CREATE TABLE test(a char(1))');

// true

// System or temporary tables are not exposed to MetaData
// false

// Alternative method getting all table names in MetaData
// true

Ax.db.execute('DROP TABLE test');

2.1.3 Get views

console.log(Ax.db.getMetaData().getTables("%", "VIEW"));

2.1.4 Get synonyms

console.log(Ax.db.getMetaData().getTables("%", "SYNONYM"));

2.1.5 Get system tables

console.log(Ax.db.getMetaData().getTables("%", "SYSTEM TABLE"));

2.2 Getting columns

To get columns for a specific table: