Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

api hdb

Ivan Volkov edited this page Jul 30, 2021 · 7 revisions

$.hdb API

This 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.

Reference

  • SAP Help

https://help.sap.com/doc/3de842783af24336b6305a3c0223a369/2.0.03/en-US/$.hdb.html

  • Module

https://github.com/SAP/xsk/tree/main/modules/api/api-xsjs/src/main/resources/xsk/hdb

  • Sample usage:
var db = $.hdb;
var response = require('http/v4/response');

var tableName = "CARS";

try {
    var connection = db.getConnection();

    // Make sure to create the table only once
    connection.executeUpdate("CREATE TABLE " + tableName + " (MAKE varchar(255), MODEL varchar(255))");

    var rows = connection.executeUpdate("INSERT INTO " + tableName +  
                                                      " (MAKE, MODEL) VALUES ('BMW', '325'), ('HONDA', 'ACCORD');");
    response.println("Query OK, " + rows + " rows affected\n");

 var result = connection.executeQuery('SELECT * FROM '+ tableName);
 var iterator = result.getIterator();
 var metadata = result.metadata.columns;
 var columnCount = metadata.length;
 var totalText ="";
 
 while(iterator.next()) {
    var currentRow = iterator.value();
    var text = "\n" + metadata[0].name + ": "+ currentRow[metadata[0].name] + "\n" + metadata[1].name+ ": "+ currentRow[metadata[1].name] + "\n";
    response.println(text);
}


} catch(e) {
    connection.rollback();
    response.println("Transaction was rolled back: " + e.message);
} finally {
       connection.close();
}

response.flush();
response.close();

Coverage

$.db

Method Description Status
getConnection() Returns a connection to the database

$.db.Connection

Method Description Status
close() Closes the connection. ⚠️
commit() Commits the changes. ⚠️
isClosed() Checks if the connection is closed. ⚠️
executeQuery(query, arguments(optional)) Executes a database query. The query string is prepared and the additional arguments are applied as statement parameters, before the statement is executed.
executeUpdate(statement, arguments(optional)) Executes a SQL statement, which changes the database state. SELECT and CALL statements are not allowed here. The query string is prepared and the additional arguments are applied as statement parameters, before the statement is executed.
rollback() Rolls back the changes. ⚠️
setAutoCommit(enable) Changes the auto-commit flag of the connection ⚠️

✅ - Feature implemented and working as supposed.
⚠️ - Feature partially implemented and needs to be finished.
❌ - Feature not implemented yet.

Project

Architecture

Tips & Tricks

Infrastructure

Troubleshooting guide

Clone this wiki locally