Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7b232e5
Fix: Update connection_manager.py
herrek1 Dec 12, 2024
eb6767a
Connection examples for different DB modules - fix #229
amochin Jan 28, 2025
2acc05d
JDBC connection tests
amochin Jan 28, 2025
74d96f0
SQLite tests - use new connection keyword instead of deprecated one
amochin Jan 28, 2025
3dfc10e
Merge pull request #230 from herrek1/patch-1
amochin Jan 28, 2025
e49bfb5
Bump version to 2.0.5
amochin Jan 28, 2025
4ed0a83
Merge remote 'dev' into local one
amochin Jan 28, 2025
85e1a6a
Fix tests - error message from Oracle might be slightly different
amochin Jan 28, 2025
3c6b388
Fix tests with ODBC MySQL driver
amochin Feb 2, 2025
fc131d3
Import parameter 'warn_on_connection_overwrite'
amochin Feb 2, 2025
ed40103
Default value for Import parameter 'warn_on_connection_overwrite'
amochin Feb 3, 2025
025ac22
Use len() to determine row count when using JayDeBeApi (#154)
jellemdekker Feb 3, 2025
6f92ad9
Rollback in case of errors only
amochin Feb 3, 2025
012ae63
Support set autocmmit for jaydebeapi
amochin Feb 3, 2025
7b8a3bc
Add tests for Jaydebeapi
amochin Feb 4, 2025
c4e1872
Allow different 'omit trailing semicolon' behavior pro connection
amochin Feb 4, 2025
9a8389b
New keyword 'Set Omit Trailing Semicolon'
amochin Feb 4, 2025
19012b9
omit_trailing_semicolon - better argument naming
amochin Feb 4, 2025
527b94a
Update the docs
amochin Feb 4, 2025
b42452d
Docs on ibm_db incompatibility - use ibm_db_dbi
amochin Feb 4, 2025
12d7d6d
Throw an error when trying to set autocommit for ibm_db as it's not s…
amochin Feb 4, 2025
2e49f9f
Bump version to 2.1.0
amochin Feb 4, 2025
de11778
Set "omit trailing semicolon" in tests for oracle via jaydebeapi
amochin Feb 4, 2025
594caff
docs - extend examples for JDBC
amochin Feb 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions .github/workflows/common_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:

# options for pyodbc only
DB_CHARSET: utf8mb4
DB_DRIVER: "{MySQL ODBC 8.0 ANSI Driver}"
DB_DRIVER: "{MySQL ODBC 9.2 ANSI Driver}"

jobs:
tests:
Expand Down Expand Up @@ -81,6 +81,11 @@ jobs:
- 3306:3306

steps:

- name: Install unixodbc
if: matrix.py_db_module == 'pyodbc'
run: sudo apt-get update && sudo apt-get install -y unixodbc

- name: Install ODBC driver for PostgreSQL
if: matrix.py_db_module == 'pyodbc'
run: |
Expand All @@ -97,22 +102,15 @@ jobs:
if: matrix.py_db_module == 'pyodbc'
run: |
cd "$RUNNER_TEMP"
echo "*** download driver zip file"
curl --silent --show-error --write-out "$CURL_OUTPUT_FORMAT" -O "https://www.mirrorservice.org/sites/ftp.mysql.com/Downloads/Connector-ODBC/8.0/${MYSQL_DRIVER}.tar.gz"
ls -l "${MYSQL_DRIVER}.tar.gz"
tar -xz -f "${MYSQL_DRIVER}.tar.gz"
echo "*** copy driver file to /usr/lib"
sudo cp -v "${MYSQL_DRIVER}/lib/libmyodbc8a.so" /usr/lib/x86_64-linux-gnu/odbc/
sudo chmod a+r /usr/lib/x86_64-linux-gnu/odbc/libmyodbc8a.so
echo "*** create odbcinst.ini entry"
echo '[MySQL ODBC 8.0 ANSI Driver]' > mysql_odbcinst.ini
echo 'Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc8a.so' >> mysql_odbcinst.ini
echo 'UsageCount = 1' >> mysql_odbcinst.ini
echo 'Threading = 2' >> mysql_odbcinst.ini
sudo odbcinst -i -d -f mysql_odbcinst.ini
echo "*** download driver"
curl --silent --show-error --write-out "$CURL_OUTPUT_FORMAT" -O -L "https://dev.mysql.com/get/Downloads/Connector-ODBC/9.2/${MYSQL_DRIVER}"
ls -l "${MYSQL_DRIVER}"
echo "*** install the driver"
sudo dpkg -i "./${MYSQL_DRIVER}"
sudo apt-get install -f
env:
CURL_OUTPUT_FORMAT: '%{http_code} %{filename_effective} %{size_download} %{time_total}\n'
MYSQL_DRIVER: mysql-connector-odbc-8.0.22-linux-glibc2.12-x86-64bit
CURL_OUTPUT_FORMAT: '%{http_code} %{filename_effective} %{size_download} %{time_total}\n'
MYSQL_DRIVER: mysql-connector-odbc_9.2.0-1ubuntu24.04_amd64.deb

- name: Check ODBC setup
if: matrix.py_db_module == 'pyodbc'
Expand Down Expand Up @@ -149,7 +147,7 @@ jobs:

run: |
pip install ${{ matrix.pip_install }}

- name: Tests for ${{ matrix.job_name }}
working-directory: ./test
run: >-
Expand All @@ -173,7 +171,7 @@ jobs:

- name: Upload Robot Logs
if: ${{ always() }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: log-files
name: log-files-${{ matrix.job_name }}
path: ./test/results/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ report.html
venv
.runNumber
.DS_Store
test/resources/ojdbc17.jar
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"Teradata",
"MySQL_pymysql",
"MySQL_pyodbc",
"Oracle_JDBC",
"MSSQL",
"Excel",
"Excel_RW",
Expand Down
214 changes: 210 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,198 @@ Switching Default Alias
Execute Sql String drop table XYZ
```

# Connection examples for different DB modules
<details>
<summary>Oracle (oracle_db)</summary>

```RobotFramework
# Thin mode is used by default
Connect To Database
... oracledb
... db_name=db
... db_user=db_user
... db_password=pass
... db_host=127.0.0.1
... db_port=1521

# Thick mode with default location of the Oracle Instant Client
Connect To Database
... oracledb
... db_name=db
... db_user=db_user
... db_password=pass
... db_host=127.0.0.1
... db_port=1521
... oracle_driver_mode=thick

# Thick mode with custom location of the Oracle Instant Client
Connect To Database
... oracledb
... db_name=db
... db_user=db_user
... db_password=pass
... db_host=127.0.0.1
... db_port=1521
... oracle_driver_mode=thick,lib_dir=C:/instant_client_23_5
```
</details>

<details>
<summary> PostgreSQL (psycopg2) </summary>

```RobotFramework
Connect To Database
... psycopg2
... db_name=db
... db_user=db_user
... db_password=pass
... db_host=127.0.0.1
... db_port=5432
```
</details>

<details>
<summary>Microsoft SQL Server (pymssql)</summary>

```RobotFramework
# UTF-8 charset is used by default
Connect To Database
... pymssql
... db_name=db
... db_user=db_user
... db_password=pass
... db_host=127.0.0.1
... db_port=1433

# Specifying a custom charset
Connect To Database
... pymssql
... db_name=db
... db_user=db_user
... db_password=pass
... db_host=127.0.0.1
... db_port=1433
... db_charset=cp1252
```
</details>

<details>
<summary>MySQL (pymysql)</summary>

```RobotFramework
# UTF-8 charset is used by default
Connect To Database
... pymysql
... db_name=db
... db_user=db_user
... db_password=pass
... db_host=127.0.0.1
... db_port=3306

# Specifying a custom charset
Connect To Database
... pymysql
... db_name=db
... db_user=db_user
... db_password=pass
... db_host=127.0.0.1
... db_port=3306
... db_charset=cp1252
```
</details>

<details>
<summary>IBM DB2 (ibm_db_dbi)</summary>

```RobotFramework
Connect To Database
... ibm_db_dbi
... db_name=db
... db_user=db_user
... db_password=pass
... db_host=127.0.0.1
... db_port=50000
```
</details>

<details>
<summary>MySQL via ODBC (pyodbc)</summary>

```RobotFramework
# ODBC driver name is required
# ODBC driver itself has to be installed
Connect To Database
... pyodbc
... db_name=db
... db_user=db_user
... db_password=pass
... db_host=127.0.0.1
... db_port=3306
... odbc_driver={MySQL ODBC 9.2 ANSI Driver}

# Specifying a custom charset if needed
Connect To Database
... pyodbc
... db_name=db
... db_user=db_user
... db_password=pass
... db_host=127.0.0.1
... db_port=3306
... odbc_driver={MySQL ODBC 9.2 ANSI Driver}
... db_charset=latin1
```
</details>

<details>
<summary>Oracle via JDBC (jaydebeapi)</summary>

```RobotFramework
# Username and password must be set as a dictionary
VAR &{CREDENTIALS} user=db_user password=pass

# JAR file with Oracle JDBC driver is required
# Jaydebeapi is not "natively" supported by the Database Library,
# so using the custom parameters
Connect To Database
... jaydebeapi
... jclassname=oracle.jdbc.driver.OracleDriver
... url=jdbc:oracle:thin:@127.0.0.1:1521/db
... driver_args=${CREDENTIALS}
... jars=C:/ojdbc17.jar

# Set if getting error 'Could not commit/rollback with auto-commit enabled'
Set Auto Commit False

# Set for automatically removing trailing ';' (might be helpful for Oracle)
Set Omit Trailing Semicolon True
```
</details>

<details>
<summary>SQLite (sqlite3)</summary>

```RobotFramework
# Using custom parameters required
Connect To Database
... sqlite3
... database=./my_database.db
... isolation_level=${None}
```
</details>

<details>
<summary>Teradata (teradata)</summary>

```RobotFramework
Connect To Database
... teradata
... db_name=db
... db_user=db_user
... db_password=pass
... db_host=127.0.0.1
... db_port=1025
```
</details>

# Using configuration file
The `Connect To Database` keyword allows providing the connection parameters in two ways:
Expand Down Expand Up @@ -182,7 +373,7 @@ The retry mechanism is disabled by default - ``retry_timeout`` is set to ``0``.
${sql}= Catenate SELECT first_name FROM person
Check Row Count ${sql} == 2 retry_timeout=10 seconds
Check Query Result ${sql} contains Allan retry_timeout=5s retry_pause=1s
````
```

# Logging query results
Keywords, that fetch results of a SQL query, print the result rows as a table in RF log.
Expand All @@ -204,7 +395,7 @@ Library DatabaseLibrary log_query_results_head=10

# Logging of query results is enabled (default), log head limit is disabled (log all rows).
Library DatabaseLibrary log_query_results_head=0
````
```

# Commit behavior
While creating a database connection, the library doesn't explicitly set the _autocommit_ behavior -
Expand All @@ -223,7 +414,22 @@ It's also possible to explicitly set the _autocommit_ behavior on the Python DB
using the `Set Auto Commit` keyword.
This has no impact on the automatic commit/rollback behavior in library keywords (described above).

# Omitting trailing semicolon behavior
Some databases (e.g. Oracle) throw an exception, if you leave a semicolon (;) at the SQL string end.
However, there are exceptional cases, when you need it even for Oracle - e.g. at the end of a PL/SQL block.

The library can handle it for you and remove the semicolon at the end of the SQL string.
By default, it's decided based on the current database module in use:
- For `oracle_db` and `cx_Oracle`, the trailing semicolon is removed
- For other modules, the trailing semicolon is left as it is

You can also set this behavior explicitly:
- Using the `Set Omit Trailing Semicolon` keyword
- Using the `omit_trailing_semicolon` parameter in the `Execute SQL String` keyword.

# Database modules compatibility
> Looking for [Connection examples for different DB modules](#connection-examples-for-different-db-modules)?

The library is basically compatible with any [Python Database API Specification 2.0](https://peps.python.org/pep-0249/) module.

However, the actual implementation in existing Python modules is sometimes quite different, which requires custom handling in the library.
Expand All @@ -247,8 +453,8 @@ Therefore there are some modules, which are "natively" supported in the library
### Teradata
- [teradata](https://github.com/teradata/PyTd)
### IBM DB2
- [ibm_db](https://github.com/ibmdb/python-ibmdb)
- [ibm_db_dbi](https://github.com/ibmdb/python-ibmdb)
- The Python package to be installed is [ibm_db](https://github.com/ibmdb/python-ibmdb). It includes two modules - `ibm_db` and `ibm_db_dbi`.
- *Using `ibm_db_dbi` is highly recommended* as only this module is Python DB API 2.0 compatible. See [official docs](https://www.ibm.com/docs/en/db2/12.1?topic=applications-python-sqlalchemy-django-framework).
### ODBC
- [pyodbc](https://github.com/mkleehammer/pyodbc)
- [pypyodbc](https://github.com/pypyodbc/pypyodbc)
Expand Down
4 changes: 2 additions & 2 deletions doc/index.html

Large diffs are not rendered by default.

Loading