$.hdb
$.hdb namespace provides means for seamless HANA database access. It is intended to be a replacement for the older $.db
namespace. The fundamental goal of the new interface is to ensure simplicity, convenience, completeness, and
performance.
Overview
Sample Usage
var db = $.hdb;
let connection = null;
try {
connection = db.getConnection();
try {
connection.executeUpdate("DROP TABLE CARS");
} catch (e) {
// Do nothing
}
connection.executeUpdate("CREATE TABLE CARS (MAKE varchar(255), MODEL varchar(255))");
let rows = connection.executeUpdate("INSERT INTO CARS (MAKE, MODEL) VALUES ('BMW', '325')");
rows += connection.executeUpdate("INSERT INTO CARS (MAKE, MODEL) VALUES ('HONDA', 'ACCORD')");
let totalText = `Query OK, ${rows} rows affected\n\n`;
let result = connection.executeQuery("SELECT * FROM CARS");
let iterator = result.getIterator();
let metadata = result.metadata.columns;
while(iterator.next()) {
var currentRow = iterator.value();
totalText += `${metadata[0].name}: ${currentRow[metadata[0].name]}, ${metadata[1].name}: ${currentRow[metadata[1].name]}\n`;
}
$.response.setBody(totalText );
} catch(e) {
connection.rollback();
$.response.setBody("Transaction was rolled back: " + e.message);
} finally {
if (connection) {
connection.close();
}
}
Functions
| Function |
Description |
Returns |
| getConnection() |
Returns a connection to the database. |
$.hdb.Connection |
Properties
| Name |
Description |
Type |
Default |
| isolation.READ_COMITTED |
- |
number |
2 |
| isolation.REPEATABLE_READ |
- |
number |
4 |
| isolation.SERIALIZABLE |
- |
number |
8 |
| types.TINYINT |
- |
number |
1 |
| types.SMALLINT |
- |
number |
2 |
| types.INTEGER |
- |
number |
3 |
| types.BIGINT |
- |
number |
4 |
| types.DECIMAL |
- |
number |
5 |
| types.REAL |
- |
number |
6 |
| types.DOUBLE |
- |
number |
7 |
| types.CHAR |
- |
number |
8 |
| types.VARCHAR |
- |
number |
9 |
| types.NCHAR |
- |
number |
10 |
| types.NVARCHAR |
- |
number |
11 |
| types.BINARY |
- |
number |
12 |
| types.VARBINARY |
- |
number |
13 |
| types.DATE |
- |
number |
14 |
| types.TIME |
- |
number |
15 |
| types.TIMESTAMP |
- |
number |
16 |
| types.CLOB |
- |
number |
25 |
| types.NCLOB |
- |
number |
26 |
| types.BLOB |
- |
number |
27 |
| types.SMALLDECIMAL |
- |
number |
47 |
| types.TEXT |
- |
number |
51 |
| types.SHORTTEXT |
- |
number |
52 |
| types.ALPHANUM |
- |
number |
55 |
| types.SECONDDATE |
- |
number |
62 |
| types.ST_GEOMETRY |
- |
number |
74 |
| types.ST_POINT |
- |
number |
75 |
Note
- isolation - constants that represent the isolation levels for a transaction.
- types - set of constants of the database column types.
types.ST_GEOMETRY - consider using SQL's ST_asGeoJSON() on ST_GEOMETRY columns for easy consumption.
types.ST_POINT - consider using SQL's ST_asGeoJSON() on ST_POINT columns for easy consumption
Classes
$.hdb.Connection
Functions
| Function |
Description |
Returns |
| close() |
Closes the connection. |
- |
| commit() |
Commits the changes. |
- |
| isClosed() |
Checks if the connection is closed. |
boolean |
| executeQuery(query, args) |
Executes a database query. |
$.hdb.ResultSet |
| executeUpdate(statement, args) |
Executes a SQL statement, which changes the database state. |
$.hdb.ResultSet |
| rollback() |
Rolls back the changes. |
- |
| setAutoCommit(enable) |
Changes the auto-commit flag of the connection. |
- |
$.hdb.ResultSet
Functions
| Function |
Description |
Returns |
| getIterator() |
Returns an iterator over this result set. |
$.hdb.ResultSetIterator |
Properties
| Name |
Description |
Type |
| lenght |
The number of rows in the $.hdb.ResultSet object |
number |
| metadata |
Returns the ResultSetMetaData from $.hdb.ResultSet object. |
$.hdb.ResultSetMetaData |
$.hdb.ResultSetIterator
Functions
| Method |
Description |
Type |
| next() |
Checks if the result set has more rows and sets the value of the iterator to the next row if it exists. |
boolean |
| value() |
Returns the current row that the iterator's value is set to, should always be called after a call to next(). |
row of a $.hdb.ResultSet |
Properties
| Name |
Description |
Type |
| column |
Returns an array of column metadata objects, each of which represents the metadata for a particular column. |
array of $.hdb.ColumnMetadata |
Properties
| Name |
Description |
Type |
| catalogName |
Returns the column's catalog name. |
string |
| displaySize |
Returns the column's display size. |
number |
| isNullable |
Returns true if the column is nullable and false otherwise. |
number |
| label |
Returns the column's label. |
string |
| precision |
Returns the column's name. |
string |
| scale |
Returns the column's scale. |
string |
| tableName |
Returns the name of the table to which the column belongs. |
string |
| type |
Returns the column's type. |
string |
| typeName |
Returns the column's type name. |
$.hdb.types |