Provides a java.sql.Date object wrapper that can be used as date type for database operations. It extends same interface than Ax.util.Date, so you an refer to Ax.util.Date for a complete description.
1 Ax.sql.Date
The Ax.sql.Date provides a special java.sql.Date that can be used for database operations in template strings if connection is set to the object.
var current = new Ax.sql.Date(); console.log(current); // Setup the database type for DATE toString() representation current.setConnection(Ax.db); console.log(current);
informix
2022-09-06
MDY(9,6,2022)
1.1 Database date format
Dates can be passed as arguments for arguments used in the prepared statement. But connot be prepared in the columns section of statement and in many other situations.
By default, date toString
returns the Java date
representation so we can not use it as a valid date literal for a SQL statement.
1.1.1 toDateQuery
The Ax.db provides a function to convert a Date (javascript or java) to it's corresponding database date function.
console.log(Ax.db.toDateQuery(new Ax.sql.Date())); console.log(Ax.db.toDateQuery(new Ax.util.Date())); console.log(Ax.db.toDateQuery(new Date()));
informix
MDY(4,12,2021)
MDY(4,12,2021)
MDY(4,12,2021)
1.1.2 toString()
You can create a date passing it a database connection. In that case, the toString
method will return the database date function for the date object.
Let's see some examples (notice you need to use a string template to resolve date variable):
Informix
<script> var current = new Ax.sql.Date(); // Setup the database type for DATE toString() representation current.setConnection(Ax.db); var rs = Ax.db.executeQuery(`SELECT ${current} FROM sysmaster:sysdual`); console.log(rs); console.log(`${current}`); </script>
+----------+
|(constant)|
+----------+
|2019-02-11|
+----------+
MDY(2,11,2019)
Oracle
<script> var current = new Ax.sql.Date(Ax.db); // Setup the database type for DATE toString() representation current.setConnection(Ax.db); var rs = Ax.db.executeQuery(`SELECT ${current} FROM dual`); console.log(rs); console.log(`${current}`); </script>
+----------------------------+
|TO_DATE(20190211,'YYYYMMDD')|
+----------------------------+
|2019-02-11T00:00:00 |
+----------------------------+
TO_DATE(20190211, 'yyyymmdd')
1.2 Date from QBE argument
Dates passed to report from QBE forms and executed in studio report processor are wrapped to Ax.sql.Date and it's connection is set.
In the following example variables DATE1 and DATE2 are of type Ax.sql.Date with connection set. But any javascript date generated by application does not has this property. Also any Ax.sql.Date created requires connection to be set to be transformable to SQL.
<script> return Ax.db.call("test_date", Ax.context.variable.DATE1, Ax.context.variable.DATE2 ); </script>