Once the client software is installed, locate the file hdbcli-x-y-z.tar.gz. The next step is to install the Python hdbcli package. This can be done easily using the Python utility program pip. Execute the following command in a terminal.
pip install /path/to/hdbcli-x-y-z.tar.gz
After the process completes, the Python hdbcli package will be installed. Listing 1 below shows a simple script that tests the database connection.
from hdbcli import dbapi connection = dbapi.connect("SERVER_HOST", PORT_NUMBER, "USERNAME", "PASSWORD") print(connection.isconnected())
Replace the connect arguments to reflect your own systems credentials. The SERVER_HOST can be an IP address or a host name.
The script will print True when a successful connection is made.
SQL statements are executed on a Cursor object. Listing 2 below shows a simple SQL statement that returns the current date.
... cursor = connection.cursor() cursor.execute("SELECT NOW() FROM DUMMY") row = cursor.fetchone() print(row)
Notice on line 2, the cursor() method is used to return a Cursor object. This object is then used to execute SQL statements.
The execute() method returns a Boolean value indicating if the statement executed successfully. The Cursor object exposes several methods to return data. The fetchone() method is used to return a single row while fetchall() returns multiple rows.