Database Library
Database Library is a Robot Framework library that provides keywords for interacting with databases.
It offers keywords to e.g.
- connect to a database
- execute SQL queries
- fetch results from the database
- assert table contents and result sets
For specifics, please refer to the library's Keyword documentation.
Installation
Install from PyPI
pip install robotframework-databaselibrary
Examples
Check out the tests folder in the repository for examples.
Basic Usage Example
*** Settings ***
Library DatabaseLibrary
Test Setup Connect To My Oracle DB
*** Keywords ***
Connect To My Oracle DB
Connect To Database
... oracledb
... db_name=db
... db_user=my_user
... db_password=my_pass
... db_host=127.0.0.1
... db_port=1521
*** Test Cases ***
Get All Names
${Rows}= Query select FIRST_NAME, LAST_NAME from person
Should Be Equal ${Rows}[0][0] Franz Allan
Should Be Equal ${Rows}[0][1] See
Should Be Equal ${Rows}[1][0] Jerry
Should Be Equal ${Rows}[1][1] Schneider
Person Table Contains Expected Records
${sql}= Catenate select LAST_NAME from person
Check Query Result ${sql} contains See
Check Query Result ${sql} equals Schneider row=1
Wait Until Table Gets New Record
${sql}= Catenate select LAST_NAME from person
Check Row Count ${sql} > 2 retry_timeout=5s
Person Table Contains No Joe
${sql}= Catenate SELECT id FROM person
... WHERE FIRST_NAME= 'Joe'
Check Row Count ${sql} == 0
Database modules compatibility
The library is basically compatible with any Python Database API Specification 2.0 module.
However, the actual implementation in existing Python modules is sometimes quite different, which requires custom handling in the library. Therefore there are some modules, which are "natively" supported in the library - and others, which may work and may not.
Python modules currently "natively" supported
Oracle
- oracledb
- Both thick and thin client modes are supported - you can select one using the
oracle_driver_mode
parameter. - However, due to current limitations of the oracledb module, it's not possible to switch between thick and thin modes during a test execution session - even in different suites.
- Both thick and thin client modes are supported - you can select one using the
- cx_Oracle
MySQL
PostgreSQL
MS SQL Server
SQLite
Teradata
IBM DB2
- The Python package to be installed is ibm_db. It includes two modules -
ibm_db
andibm_db_dbi
. - Using
ibm_db_dbi
is highly recommended as only this module is Python DB API 2.0 compatible. See official docs.
ODBC
Kingbase
- ksycopg2