1 Connection

A transaction is a set of operations who share a common objective and are interdependent.

1.1 Connection

Allow to establish a connection to a database.

Copy
<xsql-script>
    <body>
        <connection name='demo_form'>
            <println>
                <select>
                    <columns>
                        count(*)
                    </columns>
                    <from table='systables'/>
                    <where>
                        tabid in (1,2,3,4,5)
                    </where>
                </select>
            </println>
        </connection>
    </body>
</xsql-script>
5
Copy
var dbName = Ax.db.of('demo_form');
var mCount = dbName.executeGet(`
        <select>
            <columns>
                count(*)
            </columns>
            <from table='systables'/>
            <where>
                tabid in (1,2,3,4,5)
            </where>
        </select>`);
console.log(mCount);
5

1.2 getUsers

Using code 'xsql' you can obtain all the users that were defined in the connection database or in the database provided, but using 'server- side script' we can obtain the personal user.

Copy
<xsql-script>
    <body>
        <println>
           <connection.getUsers />
        </println>
    </body>
</xsql-script>
+-----------------+--------+--------+--------+-------+
|username         |usertype|priority|password|defrole|
+-----------------+--------+--------+--------+-------+
|advento          |C       |5       |        |       |
|android          |C       |5       |        |       |
   .               .        .       
   .               .        .
Copy
console.log("User: " + Ax.db.getUser());
/*The user that returns the result will be the user with whom you are connected.*/
User: root

1.3 Begin

Initiates a transaction.

Copy
<xsql-script>
    <body>
        <table name='vehicles_test'>
            <column name='seqno' type='serial' />
            <column name='brand' type='char' size='12' />
            <column name='model' type='char' size='12' />
        </table>
        
        <connection.begin/>
            <insert table='vehicles_test'>
                <column name='seqno'>1</column>
                <column name='brand'>Bentley</column>
                <column name='model'>Modelo 1</column>
            </insert>
            <println>
                
            </println>
            <print.sql>
                <select>
                    <columns>
                        seqno,brand,model   
                    </columns>
                    <from table='vehicles_test'/>
                </select>
            </print.sql>
        <connection.commit/>
        
        <drop table='vehicles_test' />
    </body>
</xsql-script>
+----------+------------+------------+
|seqno     |brand       |model       |
+----------+------------+------------+
|1         |Bentley     |Modelo 1    |
+----------+------------+------------+
Copy
Ax.db.execute(`CREATE TABLE vehicles_test (seqno serial, brand char(12), model char(12))`);
    Ax.db.beginWork();
    Ax.db.insert('vehicles_test',
        {   seqno: 1,
            brand: "Bentley",
            model: "Modelo 1" 
        }
    );
    
    var mTable =   Ax.db.executeQuery(`
            <select>
                <columns>
                    seqno,brand,model   
                </columns>
                <from table='vehicles_test' />
            </select>
        `);
    console.log(mTable);
    Ax.db.commitWork();
    mTable.close();
Ax.db.execute(`drop table vehicles_test`);
+-------------+-------------+-------------+
|vehicles_test|vehicles_test|vehicles_test|
|seqno        |brand        |model        |
|serial       |char(12)     |char(12)     |
+-------------+-------------+-------------+
|1            |Bentley      |Modelo 1     |
+-------------+-------------+-------------+

1.4 Commit

It makes that all the changes made after the previous commit.

Copy
<xsql-script>
    <body>
        <table name='vehicles_test'>
            <column name='seqno' type='serial' />
            <column name='brand' type='char' size='12' />
            <column name='model' type='char' size='12' />
        </table>

        <connection.begin/>
            <insert table='vehicles_test'>
                <column name='seqno'>1</column>
                <column name='brand'>Bentley</column>
                <column name='model'>Modelo 1</column>
            </insert>
            
            <println> First transaction </println>
            <print.sql>
                <select>
                    <columns>
                        seqno, brand, model
                    </columns>
                    <from table='vehicles_test'/>
                </select>
            </print.sql>

            <update table='vehicles_test'>
                <column name='brand'>Bugatti</column>
                <where>
                    seqno = 1
                </where>
            </update>
            
            <println> Second transaction </println>            
            <print.sql>
                <select>
                    <columns>
                        seqno, brand, model   
                    </columns>
                    <from table='vehicles_test'/>
                </select>
            </print.sql>
        <connection.commit/>
        <drop table='vehicles_test' />
    </body>
</xsql-script>
First transaction
+----------+------------+------------+
|seqno     |brand       |model       |
+----------+------------+------------+
|1         |Bentley     |Modelo 1    |
+----------+------------+------------+

Second transaction
+----------+------------+------------+
|seqno     |brand       |model       |
+----------+------------+------------+
|1         |Bugatti     |Modelo 1    |
+----------+------------+------------+
Copy
Ax.db.execute(`CREATE TABLE vehicles_test (seqno serial, brand char(12), model char(12))`);

    Ax.db.beginWork();
    Ax.db.insert('vehicles_test',
        {   seqno: 1,
            brand: "Bentley",
            model: "Modelo 1" 
        }
    );
    console.log('First transaction');
    var mTrans1 = Ax.db.executeQuery(`
        <select>
            <columns>
                seqno, brand, model
            </columns>
            <from table='vehicles_test'/>
        </select>
    `);
    console.log(mTrans1);
    mTrans1.close();
    
    Ax.db.update('vehicles_test',
        {
            brand : "Bugatti"
        },
        {
            seqno : 1
        }
    );
    
    console.log('Second transaction');
    var mTrans2 = Ax.db.executeQuery(`
        <select>
            <columns>
                seqno, brand, model
            </columns>
            <from table='vehicles_test'/>
        </select>
    `);
    console.log(mTrans2);
    mTrans2.close();
    
    Ax.db.commitWork();
Ax.db.execute(`drop table vehicles_test`);
First transaction
+-------------+-------------+-------------+
|vehicles_test|vehicles_test|vehicles_test|
|seqno        |brand        |model        |
|serial       |char(12)     |char(12)     |
+-------------+-------------+-------------+
|1            |Bentley      |Modelo 1     |
+-------------+-------------+-------------+

Second transaction
+-------------+-------------+-------------+
|vehicles_test|vehicles_test|vehicles_test|
|seqno        |brand        |model        |
|serial       |char(12)     |char(12)     |
+-------------+-------------+-------------+
|1            |Bugatti      |Modelo 1     |
+-------------+-------------+-------------+

1.5 Rollback

Ends a failed transaction.

Copy
<xsql-script>
    <body>
        <table name='vehicles_test'>
            <column name='seqno' type='serial' />
            <column name='brand' type='char' size='12' />
            <column name='model' type='char' size='12' />
        </table>
        <insert table='vehicles_test'>
            <column name='seqno'>1</column>
            <column name='brand'>Bentley</column>
            <column name='model'>Modelo 1</column>
        </insert>
        
        <println>Initial table content</println>
        <print.sql>
            <select>
                <columns>
                    seqno, brand, model   
                </columns>
                <from table='vehicles_test'/>
            </select>
        </print.sql>
                    
        <try>
            <body>
                <connection.begin/>
                    <update table='vehicles_test'>
                        <column name='brand'>Nissan</column>
                        <where>
                            seqno = 1
                        </where>
                    </update>
                    
                    <println> Before the exception that will cause 'Rollback'.</println>
                    <print.sql>
                        <select>
                            <columns>
                                seqno, brand, model   
                            </columns>
                            <from table='vehicles_test'/>
                        </select>
                    </print.sql>
                    <insert table='vehicles_tes'>
                        <column name='seqno'>2</column>
                        <column name='brand'>Ferrari</column>
                        <column name='model'>Modelo 9</column>
                    </insert>
                <connection.commit/>
            </body>
            <catch>
                <connection.rollback/>
            </catch>
        </try>
        
        <println>After running 'Rollback' and undoing changes made.</println>
        <print.sql>
            <select>
                <columns>
                    seqno, brand, model
                </columns>
                <from table='vehicles_test'/>
            </select>
        </print.sql>
        <drop table='vehicles_test' />
    </body>
</xsql-script>
Initial table content
+----------+------------+------------+
|seqno     |brand       |model       |
+----------+------------+------------+
|1         |Bentley     |Modelo 1    |
+----------+------------+------------+
Before the exception that will cause 'Rollback'.
+----------+------------+------------+
|seqno     |brand       |model       |
+----------+------------+------------+
|1         |Nissan      |Modelo 1    |
+----------+------------+------------+
After running 'Rollback' and undoing changes made.
+----------+------------+------------+
|seqno     |brand       |model       |
+----------+------------+------------+
|1         |Bentley     |Modelo 1    |
+----------+------------+------------+
Copy
var mRsVehicle;
Ax.db.execute(`CREATE TABLE vehicles_test (seqno serial, brand char(12), model char(12))`);
Ax.db.insert('vehicles_test',
        {   seqno: 1,
            brand: "Bentley",
            model: "Modelo 1" 
        }
    );
    
    console.log('Initial table content');
    mRsVehicle = Ax.db.executeQuery(`
        <select>
            <columns>
                seqno, brand, model   
            </columns>
            <from table='vehicles_test'/>
        </select>
    `);
    console.log(mRsVehicle);
    mRsVehicle.close();
    
try {
    Ax.db.beginWork();
    Ax.db.update('vehicles_test',
        {
            brand : "Nissan"
        },
        {
            seqno : 1
        }
    );
    
    console.log("Before the exception that will cause 'Rollback'.");
    mRsVehicle = Ax.db.executeQuery(`
        <select>
            <columns>
                seqno, brand, model   
            </columns>
            <from table='vehicles_test'/>
        </select>
    `);
    console.log(mRsVehicle);
    mRsVehicle.close();
    
    Ax.db.insert('vehicles_tes',
        {   seqno: 2,
            brand: "Ferrari",
            model: "Modelo 9" 
        }
    );
    Ax.db.commitWork();
}catch(e){
    Ax.db.rollbackWork();
}

console.log("After running 'Rollback' and undoing changes made.");
mRsVehicle = Ax.db.executeQuery(`
    <select>
        <columns>
            seqno, brand, model   
        </columns>
        <from table='vehicles_test'/>
    </select>
`);
console.log(mRsVehicle);
mRsVehicle.close();

Ax.db.execute(`drop table vehicles_test`);
Initial table content
+-------------+-------------+-------------+
|vehicles_test|vehicles_test|vehicles_test|
|seqno        |brand        |model        |
|serial       |char(12)     |char(12)     |
+-------------+-------------+-------------+
|1            |Bentley      |Modelo 1     |
+-------------+-------------+-------------+

Before the exception that will cause 'Rollback'.
+-------------+-------------+-------------+
|vehicles_test|vehicles_test|vehicles_test|
|seqno        |brand        |model        |
|serial       |char(12)     |char(12)     |
+-------------+-------------+-------------+
|1            |Nissan       |Modelo 1     |
+-------------+-------------+-------------+

After running 'Rollback' and undoing changes made.
+-------------+-------------+-------------+
|vehicles_test|vehicles_test|vehicles_test|
|seqno        |brand        |model        |
|serial       |char(12)     |char(12)     |
+-------------+-------------+-------------+
|1            |Bentley      |Modelo 1     |
+-------------+-------------+-------------+

1.6 isOnTransaction

Returns true or false if there is a open transaction.

Copy
<xsql-script>
    <body>
        <println>
            FIRST CALL : <connection.isOnTransaction />
        </println>  
        <table name='test_con'>
            <column name='codigo' type='char' size='12' />
        </table>
    
        <connection.begin/>
        <println>
            SECOND CALL : <connection.isOnTransaction />
        </println> 
    
        <insert table='test_con'>
            <column name='codigo'>A</column>
        </insert>
        <connection.commit/>
        <drop table='test_con' />
    </body>
</xsql-script>
FIRST CALL : false
SECOND CALL : true
Copy
Ax.db.execute(`CREATE TABLE test_con (codigo char(12))`);

Ax.db.beginWork();
console.log("FIRST CALL :" + Ax.db.isOnTransaction());                       

Ax.db.execute(` INSERT INTO test_con (codigo) values(10)`);
Ax.db.commitWork();

console.log("SECOND CALL :" + Ax.db.isOnTransaction());
FIRST CALL :true
SECOND CALL :false

1.7 isReadOnly

Returns true if the connection is read only.

Copy
<xsql-script>
    <body>
        <println>The current conection is read only: <connection.isReadOnly /></println>
    </body>
</xsql-script>
The current conection is read only: false
Copy
console.log("The current conection is read only: " + Ax.db.isReadOnly());
The current conection is read only: false

1.8 Supports Transactions

Returns true or false indicating if the database supports transactions.

Copy
<xsql-script>
  <body>
        <if>
            <expr><connection.supportsTransactions /></expr>
            <then>
                <println>The database supports transactions</println>  
            </then>
        </if>
  </body>
</xsql-script>
The database supports transactions.
Copy
if (Ax.db.supportsTransactions()) {
    console.log("The database supports transactions.");
} else{
    console.log("The database doesn't support transactions.");
}
The database supports transactions.

1.9 getColumns

Recover a description of columns of the availables tables in the corresponding catalog.

Copy
<xsql-script>
    <body>
        <println>
            <connection.metadata.getColumns>
                <null />
                <null />
                <string>systables</string>
                <string>%</string>
            </connection.metadata.getColumns>
        </println>
    </body>
</xsql-script>
+---------+-----------+----------+---------------+---------+----------------------------+-----------+-------------+--------------+--------------+--------+-------+----------+-------------+----------------+-----------------+----------------+-----------+-------------+------------+-----------+----------------+----------------+
|table_cat|table_schem|table_name|column_name    |data_type|type_name                   |column_size|buffer_length|decimal_digits|num_prec_radix|nullable|remarks|column_def|sql_data_type|sql_datetime_sub|char_octet_length|ordinal_position|is_nullable|scope_catalog|scope_schema|scope_table|source_data_type|is_autoincrement|
+---------+-----------+----------+---------------+---------+----------------------------+-----------+-------------+--------------+--------------+--------+-------+----------+-------------+----------------+-----------------+----------------+-----------+-------------+------------+-----------+----------------+----------------+
|dev_iges |informix   |systables |tabname        |12       |varchar                     |128        |0            |0             |0             |1       |       |          |13           |0               |128              |1               |YES        |             |            |           |                |NO              |
|dev_iges |informix   |systables |owner          |1        |char                        |32         |0            |0             |0             |1       |       |          |0            |0               |32               |2               |YES        |             |            |           |                |NO              |
|dev_iges |informix   |systables |partnum        |4        |integer                     |10         |0            |0             |10            |1       |       |          |2            |0               |0                |3               |YES        |             |            |           |                |NO              |
Copy
console.log(Ax.db.getMetaData().getColumns("systables"));
+----------+-----------+----------+---------------+---------+----------------------------+-----------+-------------+--------------+--------------+--------+-------+----------+-------------+----------------+-----------------+----------------+-----------+-------------+------------+-----------+----------------+----------------+
|table_cat |table_schem|table_name|column_name    |data_type|type_name                   |column_size|buffer_length|decimal_digits|num_prec_radix|nullable|remarks|column_def|sql_data_type|sql_datetime_sub|char_octet_length|ordinal_position|is_nullable|scope_catalog|scope_schema|scope_table|source_data_type|is_autoincrement|
|varchar(0)|varchar(0) |varchar(0)|varchar(0)     |smallint |varchar(0)                  |int        |smallint     |int           |int           |int     |char(0)|varchar(0)|int          |int             |int              |int             |char(0)    |varchar(0)   |varchar(0)  |varchar(0) |smallint        |char(0)         |
+----------+-----------+----------+---------------+---------+----------------------------+-----------+-------------+--------------+--------------+--------+-------+----------+-------------+----------------+-----------------+----------------+-----------+-------------+------------+-----------+----------------+----------------+
|demo_form |informix   |systables |tabname        |12       |varchar                     |128        |0            |0             |0             |1       |       |          |13           |0               |128              |1               |YES        |             |            |           |                |NO              |
|demo_form |informix   |systables |owner          |1        |char                        |32         |0            |0             |0             |1       |       |          |0            |0               |32               |2               |YES        |             |            |           |                |NO              |
|demo_form |informix   |systables |partnum        |4        |integer                     |10         |0            |0             |10            |1       |       |          |2            |0               |0                |3               |YES        |             |            |           |                |NO              |

1.10 getPrimaryKeys

Returns a vtable with the primary keys of the table.

Copy
<xsql-script>
    <body>
        <println>
            <connection.metadata.getPrimaryKeys>
                <null />
                <null />
                <string>capuntes</string>
            </connection.metadata.getPrimaryKeys>
        </println>
    </body>
</xsql-script>
+---------+-----------+----------+-----------+-------+----------+
|table_cat|table_schem|table_name|column_name|key_seq|pk_name   |
+---------+-----------+----------+-----------+-------+----------+
|dev_icon |informix   |capuntes  |apteid     |1      |p_capuntes|
+---------+-----------+----------+-----------+-------+----------+
Copy
console.log(Ax.db.getMetaData().getPrimaryKeys("capuntes"));
+----------+-----------+----------+-----------+--------+----------+
|table_cat |table_schem|table_name|column_name|key_seq |pk_name   |
|varchar(0)|varchar(0) |varchar(0)|varchar(0) |smallint|varchar(0)|
+----------+-----------+----------+-----------+--------+----------+
|dev_icon  |informix   |capuntes  |apteid     |1       |p_capuntes|
+----------+-----------+----------+-----------+--------+----------+

1.11 getImportedKeys

Returns a description of the columns of primary key that are referenced by foreign key columns in a table.

Copy
<xsql-script>
	<body>
		<println>
			<connection.metadata.getImportedKeys>
				<null />
				<null />
				<string>cprj_periods</string>
			</connection.metadata.getImportedKeys>
		</println>
	</body>
</xsql-script>
+-----------+-------------+------------+-------------+-----------+-------------+------------+-------------+-------+-----------+-----------+---------------+----------+-------------+
|pktable_cat|pktable_schem|pktable_name|pkcolumn_name|fktable_cat|fktable_schem|fktable_name|fkcolumn_name|key_seq|update_rule|delete_rule|fk_name        |pk_name   |deferrability|
+-----------+-------------+------------+-------------+-----------+-------------+------------+-------------+-------+-----------+-----------+---------------+----------+-------------+
|dev_icon   |informix     |cejercic    |empcode      |dev_icon   |informix     |cprj_periods|cper_empcode |1      |1          |1          |f_cprj_periods2|p_cejercic|7            |
|dev_icon   |informix     |cejercic    |numero       |dev_icon   |informix     |cprj_periods|cper_year    |2      |1          |1          |f_cprj_periods2|p_cejercic|7            |
|dev_icon   |informix     |cempresa    |empcode      |dev_icon   |informix     |cprj_periods|cper_empcode |1      |1          |1          |f_cprj_periods1|p_cempresa|7            |
+-----------+-------------+------------+-------------+-----------+-------------+------------+-------------+-------+-----------+-----------+---------------+----------+-------------+
Copy
console.log(Ax.db.getMetaData().getImportedKeys("cprj_periods"));
+-----------+-------------+------------+-------------+-----------+-------------+------------+-------------+-------+-----------+-----------+---------------+----------+-------------+
|pktable_cat|pktable_schem|pktable_name|pkcolumn_name|fktable_cat|fktable_schem|fktable_name|fkcolumn_name|key_seq|update_rule|delete_rule|fk_name        |pk_name   |deferrability|
|char(0)    |char(0)      |char(0)     |char(0)      |char(0)    |char(0)      |char(0)     |char(0)      |integer|integer    |integer    |char(0)        |char(0)   |integer      |
+-----------+-------------+------------+-------------+-----------+-------------+------------+-------------+-------+-----------+-----------+---------------+----------+-------------+
|dev_icon   |informix     |cejercic    |empcode      |dev_icon   |informix     |cprj_periods|cper_empcode |1      |1          |1          |f_cprj_periods2|p_cejercic|7            |
|dev_icon   |informix     |cejercic    |numero       |dev_icon   |informix     |cprj_periods|cper_year    |2      |1          |1          |f_cprj_periods2|p_cejercic|7            |
|dev_icon   |informix     |cempresa    |empcode      |dev_icon   |informix     |cprj_periods|cper_empcode |1      |1          |1          |f_cprj_periods1|p_cempresa|7            |
+-----------+-------------+------------+-------------+-----------+-------------+------------+-------------+-------+-----------+-----------+---------------+----------+-------------+

1.12 getExportedKeys

Returns a description of the foreign key columns that reference to the primary key columns of the given table.

Copy
<xsql-script>
    <body>
        <println>
            <connection.metadata.getExportedKeys>
                <null />
                <null />
                <string>cprj_periods</string>
            </connection.metadata.getExportedKeys>
        </println>
    </body>
</xsql-script>
+-----------+-------------+------------+-------------+-----------+-------------+-----------------+-------------+-------+-----------+-----------+--------------------+--------------+-------------+
|pktable_cat|pktable_schem|pktable_name|pkcolumn_name|fktable_cat|fktable_schem|fktable_name     |fkcolumn_name|key_seq|update_rule|delete_rule|fk_name             |pk_name       |deferrability|
+-----------+-------------+------------+-------------+-----------+-------------+-----------------+-------------+-------+-----------+-----------+--------------------+--------------+-------------+
|dev_icon   |informix     |cprj_periods|cper_empcode |dev_icon   |informix     |cprj_periods_user|cprj_empcode |1      |1          |1          |f_cprj_periods_user1|p_cprj_periods|7            |
|dev_icon   |informix     |cprj_periods|cper_year    |dev_icon   |informix     |cprj_periods_user|cprj_year    |2      |1          |1          |f_cprj_periods_user1|p_cprj_periods|7            |
|dev_icon   |informix     |cprj_periods|cper_month   |dev_icon   |informix     |cprj_periods_user|cprj_month   |3      |1          |1          |f_cprj_periods_user1|p_cprj_periods|7            |
+-----------+-------------+------------+-------------+-----------+-------------+-----------------+-------------+-------+-----------+-----------+--------------------+--------------+-------------+
Copy
console.log(Ax.db.getMetaData().getExportedKeys("cprj_periods"));
+-----------+-------------+------------+-------------+-----------+-------------+-----------------+-------------+--------+-----------+-----------+--------------------+--------------+-------------+
|pktable_cat|pktable_schem|pktable_name|pkcolumn_name|fktable_cat|fktable_schem|fktable_name     |fkcolumn_name|key_seq |update_rule|delete_rule|fk_name             |pk_name       |deferrability|
|varchar(0) |varchar(0)   |varchar(0)  |varchar(0)   |varchar(0) |varchar(0)   |varchar(0)       |varchar(0)   |smallint|smallint   |smallint   |varchar(0)          |varchar(0)    |smallint     |
+-----------+-------------+------------+-------------+-----------+-------------+-----------------+-------------+--------+-----------+-----------+--------------------+--------------+-------------+
|dev_icon   |informix     |cprj_periods|cper_empcode |dev_icon   |informix     |cprj_periods_user|cprj_empcode |1       |1          |1          |f_cprj_periods_user1|p_cprj_periods|7            |
|dev_icon   |informix     |cprj_periods|cper_year    |dev_icon   |informix     |cprj_periods_user|cprj_year    |2       |1          |1          |f_cprj_periods_user1|p_cprj_periods|7            |
|dev_icon   |informix     |cprj_periods|cper_month   |dev_icon   |informix     |cprj_periods_user|cprj_month   |3       |1          |1          |f_cprj_periods_user1|p_cprj_periods|7            |
+-----------+-------------+------------+-------------+-----------+-------------+-----------------+-------------+--------+-----------+-----------+--------------------+--------------+-------------+

1.13 getIndexInfo

Returns a description of the index and statistics of the given table.

Copy
<xsql-script>
    <body>
        <println>
            <connection.metadata.getIndexInfo>
                <null />
                <null />
                <string>systables</string>
                <false />
                <false />
            </connection.metadata.getIndexInfo>
        </println>
    </body>
</xsql-script>
+---------+-----------+----------+----------+---------------+----------+----+----------------+-----------+-----------+-----------+-----+----------------+
|table_cat|table_schem|table_name|non_unique|index_qualifier|index_name|type|ordinal_position|column_name|asc_or_desc|cardinality|pages|filter_condition|
+---------+-----------+----------+----------+---------------+----------+----+----------------+-----------+-----------+-----------+-----+----------------+
|dev_iges |informix   |systables |0         |informix       |tabid     |3   |1               |tabid      |           |0          |0    |                |
|dev_iges |informix   |systables |0         |informix       |tabname   |3   |1               |tabname    |           |0          |0    |                |
|dev_iges |informix   |systables |0         |informix       |tabname   |3   |2               |owner      |           |0          |0    |                |
+---------+-----------+----------+----------+---------------+----------+----+----------------+-----------+-----------+-----------+-----+----------------+
Copy
console.log(Ax.db.getMetaData().getIndexInfo("systables"));
+----------+-----------+----------+----------+---------------+----------+----------+----------------+-----------+-----------+-----------+----------+----------------+
|table_cat |table_schem|table_name|non_unique|index_qualifier|index_name|type      |ordinal_position|column_name|asc_or_desc|cardinality|pages     |filter_condition|
|varchar(0)|varchar(0) |varchar(0)|varchar(0)|varchar(0)     |varchar(0)|varchar(0)|varchar(0)      |varchar(0) |varchar(0) |varchar(0) |varchar(0)|varchar(0)      |
+----------+-----------+----------+----------+---------------+----------+----------+----------------+-----------+-----------+-----------+----------+----------------+
|dev_icon  |informix   |systables |0         |informix       |tabid     |3         |1               |tabid      |           |0          |0         |                |
|dev_icon  |informix   |systables |0         |informix       |tabname   |3         |1               |tabname    |           |0          |0         |                |
|dev_icon  |informix   |systables |0         |informix       |tabname   |3         |2               |owner      |           |0          |0         |                |
+----------+-----------+----------+----------+---------------+----------+----------+----------------+-----------+-----------+-----------+----------+----------------+

1.14 getCheckConstraints

Returns a vtable with the restrictions of the table. Returns three columns: the first for the name of the check, the second for the original text and the third indicating if it is enabled.

Copy
<xsql-script>
    <body>
        <nativesql>
            CREATE TABLE vehicles_test (
            seqno serial, 
            brand char(12), 
            model char(12),
            CHECK (
                (model IS NOT NULL)
                )
            CONSTRAINT c_vehicles_test1,
            CHECK (
                (brand IS NOT NULL)
                )
            CONSTRAINT c_vehicles_test2
            );
        </nativesql>

        <set name='check_constraint'>
                <connection.metadata.getCheckConstraints table='vehicles_test'></connection.metadata.getCheckConstraints>
        </set>

        <println>
            <check_constraint/>
        </println>
        
        <nativesql>
            ALTER TABLE vehicles_test DROP CONSTRAINT c_vehicles_test1;
            ALTER TABLE vehicles_test DROP CONSTRAINT c_vehicles_test2;
        </nativesql>

        <drop table='vehicles_test' />
    </body>
</xsql-script>
+----------------+--------------------+------+
|name            |text                |enable|
+----------------+--------------------+------+
|c_vehicles_test1|(model IS NOT NULL )|true  |
|c_vehicles_test2|(brand IS NOT NULL )|true  |
+----------------+--------------------+------+
Copy
Ax.db.execute(`CREATE TABLE vehicles_test (
    seqno serial, 
    brand char(12), 
    model char(12),
    CHECK (
    (model IS NOT NULL)
    )
    CONSTRAINT c_vehicles_test1,
    CHECK (
    (brand IS NOT NULL)
    )
     CONSTRAINT c_vehicles_test2
    )`);

console.log(Ax.db.getMetaData().getTableMetaData("vehicles_test").getCheckConstraints());

Ax.db.execute(`ALTER TABLE vehicles_test DROP CONSTRAINT c_vehicles_test1`);
Ax.db.execute(`ALTER TABLE vehicles_test DROP CONSTRAINT c_vehicles_test2`);
Ax.db.execute(`drop table vehicles_test`);
+----------------+--------------------+-------+
|name            |text                |enabled|
|char(0)         |char(0)             |boolean|
+----------------+--------------------+-------+
|c_vehicles_test1|(model IS NOT NULL )|true   |
|c_vehicles_test2|(brand IS NOT NULL )|true   |
+----------------+--------------------+-------+

1.15 getUniqueConstraints

Returns a list of unique restrictions of a specified table.

Copy
<xsql-script>
    <body>
        <table name='vehicles_test'>
            <column name='seqno' type='serial' />
            <column name='brand' type='char' size='12' />
            <column name='model' type='char' size='12' />
            <unique name='u_vehicles_test1' columns='brand' />

        </table>

        <!-- 2 records were added to check that the unique constraint exists -->
        <insert table='vehicles_test'>
            <column name='seqno'>1</column>
            <column name='brand'>Bentley</column>
            <column name='model'>Modelo 1</column>
        </insert>
        <insert table='vehicles_test'>
            <column name='seqno'>2</column>
            <column name='brand'>Bentley</column>
            <column name='model'>Modelo 9</column>
        </insert>

        <println>
           <connection.metadata.getUniqueConstraints table='vehicles_test'/>
        </println>

        <drop table='vehicles_test' />
        <!-- Example: Dev_icon -->
        <println>
           <connection.metadata.getUniqueConstraints table='carr_contrath'/>
        </println>
    </body>
</xsql-script>
+----+
|name|
+----+

+----------------+
|name            |
+----------------+
|u_carr_contrath1|
+----------------+
Copy
Ax.db.execute(`CREATE TABLE vehicles_test (seqno serial, brand char(12), model char(12))`);

Ax.db.execute(`CREATE UNIQUE INDEX u_vehicles_test1 ON vehicles_test(brand);`);
Ax.db.execute(`ALTER TABLE vehicles_test
               ADD CONSTRAINT  UNIQUE (brand)
               CONSTRAINT u_vehicles_test1`);

//2 records were added to check that the unique constraint exists
Ax.db.insert('vehicles_test',
    {   seqno: 1,
        brand: "Bentley",
        model: "Modelo 1" 
    }
);
Ax.db.insert('vehicles_test',
    {   seqno: 2,
        brand: "Bentley",
        model: "Modelo 9" 
    }
);



console.log(Ax.db.getMetaData().getTableMetaData("vehicles_test").getUniqueConstraints());

Ax.db.execute(`ALTER TABLE vehicles_test DROP CONSTRAINT u_vehicles_test1`);
Ax.db.execute(`DROP INDEX u_vehicles_test1;`);
Ax.db.execute(`drop table vehicles_test`);

//Ejemplo : Dev_icon
console.log(Ax.db.getMetaData().getTableMetaData("carr_contrath").getUniqueConstraints());
[]
[u_carr_contrath1]

1.16 Get Temporary Tables

With 'xsql' code we can return the existing temporary tables but in 'server- side script' exists a similar method that obtains a temporary table per query.

Copy
<xsql-script>
    <body>
        <table name='test_01'>
            <column name='seqno' type='serial' />
            <column name='c1'    type='char' size='1' />
        </table>

        <insert table='test_01'>
            <column name='seqno'>0</column>
            <column name='c1'>A</column>
        </insert>

        <select intotemp="@tmp1">
            <columns>
                *
            </columns>
            <from table='test_01' />
        </select>     
        <println>
           <connection.getTemporaryTables/>
        </println>    

         <drop table='test_01' />  
    </body>
</xsql-script>
[tmp1_14047]
Copy
Ax.db.execute(`CREATE TABLE IF NOT EXISTS test_01(
                seqno serial,
                c1 char(1))`);
Ax.db.execute(`INSERT INTO test_01(seqno,c1) values(0,"A")`);
Ax.db.execute(`
        <select intotemp="@tmp1">
            <columns>
                *
            </columns>
            <from table='test_01' />
        </select>
`);                
console.log(Ax.db.getTempTableName("@tmp1"));

Ax.db.execute(`DROP TABLE test_01`);
tmp1_14098

1.17 getDriverName

Obtain the name of the JDBC driver.

Copy
<xsql-script>
    <body>
        <println>
            <connection.metadata.getDriverName />
        </println>
    </body>
</xsql-script>
Informix JDBC Driver for Informix Dynamic Server
Copy
console.log(Ax.db.getDriver());
INFORMIX

1.18 getEngineTypeName

Returns the name of the database engine.

Copy
<xsql-script>
   <body>
       <!-- Executed in a informix DB -->
       <println>The current engine name is: <connection.getEngineTypeName /></println>
   </body>
</xsql-script>
The current engine name is: informix
Copy
console.log("The current engine name is: " + Ax.db.getDriver());
The current engine name is: INFORMIX

1.19 Get DBMS

Returns the catalog of the connection database.

Copy
<xsql-script>
    <body>          
        <println>
            Dbms: <connection.getCatalog />
        </println>
    </body>
</xsql-script>
Dbms: dev_icon
Copy
console.log("Dbms :" + getDbms());
Dbms: dev_icon

1.20 Copy schematic and information

Allows to copie the structure and data from one table to another, even between differents databases.

This functionality is used to copie data between differents databases. If you try to copy in the same database you can use the function table.copy. If the table do not exist in the database, it is created with the information of the obtained metadata using the JDBC driver. That is why it is necessary to review the physical model in case the table does not exist in destination because sometimes it could be a difference in types of fields or default values that should be corrected previously.

Copy
<xsql-script>
    <body>
        <connection name='demo_form'>
            <table name='vehicles_test'>
                <column name='seqno' type='serial' />
                <column name='brand' type='char' size='12' />
                <column name='model' type='char' size='12' />
            </table>
            <insert table='vehicles_test'>
                <column name='seqno'>1</column>
                <column name='brand'>Bentley</column>
                <column name='model'>Modelo 1</column>
            </insert>
            <insert table='vehicles_test'>
                <column name='seqno'>2</column>
                <column name='brand'>Ferrari</column>
                <column name='model'>Modelo 9</column>
            </insert>
        </connection>

        <set name='time_start'><system.currentTimeMillis /></set>
        <connection.schema.copy src='demo_form' dst='dev_iges' tables='vehicles_test'  />
        <set name='time_end'><system.currentTimeMillis /></set>
        <println>The database copy process takes: <sub><time_end/><time_start/></sub> ms.</println>
        
        <println>Source table</println>
        <connection name='demo_form'>
             <print.sql>
                <select>
                    <columns>
                        *
                    </columns>
                    <from table='vehicles_test'/>
                </select>
            </print.sql>
            <drop table='vehicles_test' />
        </connection>
        
        <println>Destination table</println>
        <connection name='dev_iges'>
            <print.sql>
                <select>
                    <columns>
                        *
                    </columns>
                    <from table='vehicles_test'/>
                </select>
            </print.sql>
            <drop table='vehicles_test' />
        </connection>
    </body>
</xsql-script>
The database copy process takes: 230 ms.
Source table
+----------+------------+------------+
|seqno     |brand       |model       |
+----------+------------+------------+
|1         |Bentley     |Modelo 1    |
|2         |Ferrari     |Modelo 9    |
+----------+------------+------------+
Destination table
+----------+------------+------------+
|seqno     |brand       |model       |
+----------+------------+------------+
|1         |Bentley     |Modelo 1    |
|2         |Ferrari     |Modelo 9    |
+----------+------------+------------+
Copy
var dborig = Ax.db.of("demo_form");
var dbdest = Ax.db.of("dev_iges");

dborig.execute(`DROP TABLE IF EXISTS vehicles_test`);
dborig.execute(`CREATE TABLE vehicles_test (seqno serial, brand char(12), model char(12))`);

var rows = [
    {   seqno: 1,
        brand: "Bentley",
        model: "Modelo 1" 
    },
    {   seqno: 2,
        brand: "Ferrari",
        model: "Modelo 9" 
    }
]
dborig.insert('vehicles_test', rows);

dbdest.execute(`DROP TABLE IF EXISTS vehicles_test`);
dbdest.execute(`CREATE TABLE vehicles_test (seqno serial, brand char(12), model char(12))`);


// Transfer of information
var event1 = dborig.copy(dbdest, 'vehicles_test', config => {
    config.setCopyType("MERGE");
});

console.log('Source table');
var mRsTable1 = dborig.executeQuery(`SELECT * FROM vehicles_test`);
console.log(mRsTable1);
mRsTable1.close();

console.log('Destination table');
var mRsTable2 = dbdest.executeQuery(`SELECT * FROM vehicles_test`);
console.log(mRsTable2);
mRsTable2.close();

//Drop tables
dborig.execute(`DROP TABLE vehicles_test`);
dbdest.execute(`DROP TABLE vehicles_test`);
Source table
+-------------+-------------+-------------+
|vehicles_test|vehicles_test|vehicles_test|
|seqno        |brand        |model        |
|serial       |char(12)     |char(12)     |
+-------------+-------------+-------------+
|1            |Bentley      |Modelo 1     |
|2            |Ferrari      |Modelo 9     |
+-------------+-------------+-------------+

Destination table
+-------------+-------------+-------------+
|vehicles_test|vehicles_test|vehicles_test|
|seqno        |brand        |model        |
|serial       |char(12)     |char(12)     |
+-------------+-------------+-------------+
|1            |Bentley      |Modelo 1     |
|2            |Ferrari      |Modelo 9     |
+-------------+-------------+-------------+