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

Copy
<script>
    console.log(Ax.db.getMetaData().getTables("%"));
    
    console.log(Ax.db.getMetaData().getTables("systables", "SYSTEM TABLES"));
</script>

2.1.2 Check table exists

Copy
<script>

    Ax.db.execute('CREATE TABLE IF NOT EXISTS test(a char(1))');
    
    console.log(Ax.db.getMetaData().existsTable("test"));
    // true
    
    console.log(Ax.db.getMetaData().existsTable("systables"));
    // false
</script>

2.1.3 Get views

Copy
<script>
    console.log(Ax.db.getMetaData().getTables("%", "VIEW"));
</script>

2.1.4 Get synonyms

Copy
<script>
    console.log(Ax.db.getMetaData().getTables("%", "SYNONYM"));
</script>

2.1.5 Get system tables

Copy
<script>
    console.log(Ax.db.getMetaData().getTables("%", "SYSTEM TABLE"));
</script>

2.2 Getting columns

To get columns for a specific table:

Copy
<script>
    console.log(Ax.db.getMetaData().getColumns("tableName"));
</script>