Setting Session-Specific Client Information
The client information is a list of session variables (defined in property-value pairs that are case sensitive) that an application can set in the SAP HANA client interface.
The SAP HANA client interface stores the values specified in the M_SESSION_CONTEXT system table. Apart from storing the client information in the appropriate place in the database, the methods described here do not alter the behavior of the connection in any way. The values supplied to these methods are used for internal checks, diagnostics, and debugging purposes only.
When connecting to your database, you can set session variables by using the sessionVariable: connection option prefix. Each session variable must be specified as an independent key-value pair.
For example, in JDBC:
jdbc:sap://ykfl00540545a:30115/?autocommit=false&sessionVariable:APPLICATION=myapp&sessionVariable:APPLICATIONUSER=user1&sessionVariable:myvar=myval&distribution=connection
For example, in ODBC:
DSN=HANADataSource;UID=myUser;PWD=myPassword;sessionVariable:APPLICATION=myapp;sessionVariable:APPLICATIONUSER=user1;sessionVariable:myvar=myval
The following session variables are always set by the client:
|
Variable Name |
Definition |
Default (JDBC) |
Default (other APIs) |
|---|---|---|---|
|
APPLICATION |
Displays the application name. |
System.getProperty(<sun_java_command>) |
The executable name (with .exe suffix removed on Microsoft Windows). |
|
APPLICATIONUSER |
Displays the application user name. |
System.getProperty(<user_name>) |
The operating system user name associated with the application process. |
|
DRIVERVERSION |
Displays the driver version. |
System.getProperty(<driver_version>) |
The operating system driver version associated with the application process. |
The following example displays how to view a variable session with SAP HANA HDBSQL:
./hdbsql -n localhost:30015 -u system -p manager "SELECT * FROM M_SESSION_CONTEXT WHERE KEY='DRIVERVERSION'" HOST,PORT,CONNECTION_ID,KEY,VALUE,SECTION "localhost",30003,301640,"DRIVERVERSION","2.4.9","USER"
ODBC
Use connection attributes to access client information from ODBC:
SQL_SQLDBC_SET_CLIENTINFO_KEY = 11003 SQL_SQLDBC_SET_CLIENTINFO_VALUE = 11004 SQL_SQLDBC_GET_CLIENTINFO_VALUE = 11005
The attributes are defined in <client install directory>/sdk/odbc/incl/sqlsdbodbc.h, and are illustrated in the following example:
// setting key HOMER and value mafimi char key[] = "HOMER"; rc = SQLSetConnectAttr(hdbc, SQL_SQLDBC_SET_CLIENTINFO_KEY, key, SQL_NTS); char value[] = "mafimi"; rc = SQLSetConnectAttr(hdbc, SQL_SQLDBC_SET_CLIENTINFO_VALUE, value, SQL_NTS); // retrieving the value for the currently set SQL_SQLDBC_SET_CLIENTINFO_KEY key // if the buffer is too short: rc is SQL_SUCCESS_WITH_INFO and sqlstate 01004: // String data, right truncated char buf[64]; SQLINTEGER bufLen = 0; rc = SQLGetConnectAttr(hdbc, SQL_SQLDBC_GET_CLIENTINFO_VALUE, buf, sizeof(buf), &bufLen);
JDBC
The JDBC 4.2 API provides the following methods on java.sql.Connection to set or get the client information for a session:
-
setClientInfo
void setClientInfo(String name, String value) throws SQLClientInfoException void setClientInfo(Properties properties) throws SQLClientInfoException -
getClientInfo
String getClientInfo(String name) throws SQLException Properties getClientInfo() throws SQLException
For details on the API, refer to the JDBC specification:
//set client info property
connection.setClientInfo("APPLICATION", "Simpson");
connection.setClientInfo("APPLICATIONVERSION", "0.100");
//unset client info property
connection.setClientInfo("APPLICATION", null);
//get client info property
Properties ci = connection.getClientInfo();
Enumeration e = ci.keys();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String val = (String) ci.get(key);
System.out.println("Key="+key+" Value="+val);
}
Python DB
The Python DB API (hdbcli.dbapi) allows you to set client information during the initial connection.
-
Example
conn = dbapi.connect(address=<host>, port=<port>, user=<user>, password=<password>, sessionvariables={'APPLICATION':'MyPythonProg'})
-
getclientinfo
Gets client information with a key.
conn = dbapi.connect(address=<host>, port=<port>, user=<user>, password=<password>) value = conn.getclientinfo("MYKEY")- If the key for getclientinfo is “key=None”, then all defined key-value pairs are returned.
- The dbapi.Connection.getclientinfo command is similar to the command java.sql.Connection.getClientInfo() that is included in the JDBC API.
-
setclientinfo
Sets client information with a key and a corresponding value.
conn = dbapi.connect(address=<host>, port=<port>, user=<user>, password=<password>) conn.setclientinfo("MYKEY", 1000)- If the key for setclientinfo is “value=None”, then the key is removed from the client-information dictionary.
- The dbapi.Connection.setClientInfo command is similar to the command java.sql.Connection.setClientInfo() that is included in the JDBC API.
-
Example
conn = dbapi.connect(address=<host>, port=<port>, user=<user>, password=<password>) cur = conn.cursor() conn.setclientinfo("SCRIPT", _file_) cur.execute("create column table table_to_check_clientinfo (z int primary key)") ci = conn.getclientinfo("SCRIPT")
Node.js
The Node.js driver's connection class provides the setClientInfo and getClientInfo methods for setting and accessing the client information.
-
For example:
var hana = require('hana.node'); var conn = hana.createConnection(); conn.connect('serverNode=myserver:30015;uid=system;pwd=manager'); conn.setClientInfo('locale', 'en-CA'); var locale = conn.getClientInfo('locale'); conn.close();
Go
Set session variables for the Go driver by using the sessionVariable: connection option prefix. Each session variable must be specified as an independent key-value pair. For example:
hdb://<user>:<password>@<host>:<port>?sessionVariable:<var1>=<val1>&sessionVariable:<var2>=<val2>
In the above example, replace <var1> and <var2> with the name of session variable.