Skip to content

Commit a35e21b

Browse files
authored
Merge pull request #234 from MarketSquare/dev
v 2.1.0
2 parents 6021ed3 + 594caff commit a35e21b

26 files changed

+633
-132
lines changed

.github/workflows/common_tests.yml

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ env:
1111

1212
# options for pyodbc only
1313
DB_CHARSET: utf8mb4
14-
DB_DRIVER: "{MySQL ODBC 8.0 ANSI Driver}"
14+
DB_DRIVER: "{MySQL ODBC 9.2 ANSI Driver}"
1515

1616
jobs:
1717
tests:
@@ -81,6 +81,11 @@ jobs:
8181
- 3306:3306
8282

8383
steps:
84+
85+
- name: Install unixodbc
86+
if: matrix.py_db_module == 'pyodbc'
87+
run: sudo apt-get update && sudo apt-get install -y unixodbc
88+
8489
- name: Install ODBC driver for PostgreSQL
8590
if: matrix.py_db_module == 'pyodbc'
8691
run: |
@@ -97,22 +102,15 @@ jobs:
97102
if: matrix.py_db_module == 'pyodbc'
98103
run: |
99104
cd "$RUNNER_TEMP"
100-
echo "*** download driver zip file"
101-
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"
102-
ls -l "${MYSQL_DRIVER}.tar.gz"
103-
tar -xz -f "${MYSQL_DRIVER}.tar.gz"
104-
echo "*** copy driver file to /usr/lib"
105-
sudo cp -v "${MYSQL_DRIVER}/lib/libmyodbc8a.so" /usr/lib/x86_64-linux-gnu/odbc/
106-
sudo chmod a+r /usr/lib/x86_64-linux-gnu/odbc/libmyodbc8a.so
107-
echo "*** create odbcinst.ini entry"
108-
echo '[MySQL ODBC 8.0 ANSI Driver]' > mysql_odbcinst.ini
109-
echo 'Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc8a.so' >> mysql_odbcinst.ini
110-
echo 'UsageCount = 1' >> mysql_odbcinst.ini
111-
echo 'Threading = 2' >> mysql_odbcinst.ini
112-
sudo odbcinst -i -d -f mysql_odbcinst.ini
105+
echo "*** download driver"
106+
curl --silent --show-error --write-out "$CURL_OUTPUT_FORMAT" -O -L "https://dev.mysql.com/get/Downloads/Connector-ODBC/9.2/${MYSQL_DRIVER}"
107+
ls -l "${MYSQL_DRIVER}"
108+
echo "*** install the driver"
109+
sudo dpkg -i "./${MYSQL_DRIVER}"
110+
sudo apt-get install -f
113111
env:
114-
CURL_OUTPUT_FORMAT: '%{http_code} %{filename_effective} %{size_download} %{time_total}\n'
115-
MYSQL_DRIVER: mysql-connector-odbc-8.0.22-linux-glibc2.12-x86-64bit
112+
CURL_OUTPUT_FORMAT: '%{http_code} %{filename_effective} %{size_download} %{time_total}\n'
113+
MYSQL_DRIVER: mysql-connector-odbc_9.2.0-1ubuntu24.04_amd64.deb
116114

117115
- name: Check ODBC setup
118116
if: matrix.py_db_module == 'pyodbc'
@@ -149,7 +147,7 @@ jobs:
149147

150148
run: |
151149
pip install ${{ matrix.pip_install }}
152-
150+
153151
- name: Tests for ${{ matrix.job_name }}
154152
working-directory: ./test
155153
run: >-
@@ -173,7 +171,7 @@ jobs:
173171
174172
- name: Upload Robot Logs
175173
if: ${{ always() }}
176-
uses: actions/upload-artifact@v3
174+
uses: actions/upload-artifact@v4
177175
with:
178-
name: log-files
176+
name: log-files-${{ matrix.job_name }}
179177
path: ./test/results/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ report.html
1313
venv
1414
.runNumber
1515
.DS_Store
16+
test/resources/ojdbc17.jar

.vscode/launch.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"Teradata",
9494
"MySQL_pymysql",
9595
"MySQL_pyodbc",
96+
"Oracle_JDBC",
9697
"MSSQL",
9798
"Excel",
9899
"Excel_RW",

README.md

Lines changed: 210 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,198 @@ Switching Default Alias
9999
Execute Sql String drop table XYZ
100100
```
101101

102+
# Connection examples for different DB modules
103+
<details>
104+
<summary>Oracle (oracle_db)</summary>
102105

106+
```RobotFramework
107+
# Thin mode is used by default
108+
Connect To Database
109+
... oracledb
110+
... db_name=db
111+
... db_user=db_user
112+
... db_password=pass
113+
... db_host=127.0.0.1
114+
... db_port=1521
115+
116+
# Thick mode with default location of the Oracle Instant Client
117+
Connect To Database
118+
... oracledb
119+
... db_name=db
120+
... db_user=db_user
121+
... db_password=pass
122+
... db_host=127.0.0.1
123+
... db_port=1521
124+
... oracle_driver_mode=thick
125+
126+
# Thick mode with custom location of the Oracle Instant Client
127+
Connect To Database
128+
... oracledb
129+
... db_name=db
130+
... db_user=db_user
131+
... db_password=pass
132+
... db_host=127.0.0.1
133+
... db_port=1521
134+
... oracle_driver_mode=thick,lib_dir=C:/instant_client_23_5
135+
```
136+
</details>
137+
138+
<details>
139+
<summary> PostgreSQL (psycopg2) </summary>
140+
141+
```RobotFramework
142+
Connect To Database
143+
... psycopg2
144+
... db_name=db
145+
... db_user=db_user
146+
... db_password=pass
147+
... db_host=127.0.0.1
148+
... db_port=5432
149+
```
150+
</details>
151+
152+
<details>
153+
<summary>Microsoft SQL Server (pymssql)</summary>
154+
155+
```RobotFramework
156+
# UTF-8 charset is used by default
157+
Connect To Database
158+
... pymssql
159+
... db_name=db
160+
... db_user=db_user
161+
... db_password=pass
162+
... db_host=127.0.0.1
163+
... db_port=1433
164+
165+
# Specifying a custom charset
166+
Connect To Database
167+
... pymssql
168+
... db_name=db
169+
... db_user=db_user
170+
... db_password=pass
171+
... db_host=127.0.0.1
172+
... db_port=1433
173+
... db_charset=cp1252
174+
```
175+
</details>
176+
177+
<details>
178+
<summary>MySQL (pymysql)</summary>
179+
180+
```RobotFramework
181+
# UTF-8 charset is used by default
182+
Connect To Database
183+
... pymysql
184+
... db_name=db
185+
... db_user=db_user
186+
... db_password=pass
187+
... db_host=127.0.0.1
188+
... db_port=3306
189+
190+
# Specifying a custom charset
191+
Connect To Database
192+
... pymysql
193+
... db_name=db
194+
... db_user=db_user
195+
... db_password=pass
196+
... db_host=127.0.0.1
197+
... db_port=3306
198+
... db_charset=cp1252
199+
```
200+
</details>
201+
202+
<details>
203+
<summary>IBM DB2 (ibm_db_dbi)</summary>
204+
205+
```RobotFramework
206+
Connect To Database
207+
... ibm_db_dbi
208+
... db_name=db
209+
... db_user=db_user
210+
... db_password=pass
211+
... db_host=127.0.0.1
212+
... db_port=50000
213+
```
214+
</details>
215+
216+
<details>
217+
<summary>MySQL via ODBC (pyodbc)</summary>
218+
219+
```RobotFramework
220+
# ODBC driver name is required
221+
# ODBC driver itself has to be installed
222+
Connect To Database
223+
... pyodbc
224+
... db_name=db
225+
... db_user=db_user
226+
... db_password=pass
227+
... db_host=127.0.0.1
228+
... db_port=3306
229+
... odbc_driver={MySQL ODBC 9.2 ANSI Driver}
230+
231+
# Specifying a custom charset if needed
232+
Connect To Database
233+
... pyodbc
234+
... db_name=db
235+
... db_user=db_user
236+
... db_password=pass
237+
... db_host=127.0.0.1
238+
... db_port=3306
239+
... odbc_driver={MySQL ODBC 9.2 ANSI Driver}
240+
... db_charset=latin1
241+
```
242+
</details>
243+
244+
<details>
245+
<summary>Oracle via JDBC (jaydebeapi)</summary>
246+
247+
```RobotFramework
248+
# Username and password must be set as a dictionary
249+
VAR &{CREDENTIALS} user=db_user password=pass
250+
251+
# JAR file with Oracle JDBC driver is required
252+
# Jaydebeapi is not "natively" supported by the Database Library,
253+
# so using the custom parameters
254+
Connect To Database
255+
... jaydebeapi
256+
... jclassname=oracle.jdbc.driver.OracleDriver
257+
... url=jdbc:oracle:thin:@127.0.0.1:1521/db
258+
... driver_args=${CREDENTIALS}
259+
... jars=C:/ojdbc17.jar
260+
261+
# Set if getting error 'Could not commit/rollback with auto-commit enabled'
262+
Set Auto Commit False
263+
264+
# Set for automatically removing trailing ';' (might be helpful for Oracle)
265+
Set Omit Trailing Semicolon True
266+
```
267+
</details>
268+
269+
<details>
270+
<summary>SQLite (sqlite3)</summary>
271+
272+
```RobotFramework
273+
# Using custom parameters required
274+
Connect To Database
275+
... sqlite3
276+
... database=./my_database.db
277+
... isolation_level=${None}
278+
```
279+
</details>
280+
281+
<details>
282+
<summary>Teradata (teradata)</summary>
283+
284+
```RobotFramework
285+
Connect To Database
286+
... teradata
287+
... db_name=db
288+
... db_user=db_user
289+
... db_password=pass
290+
... db_host=127.0.0.1
291+
... db_port=1025
292+
```
293+
</details>
103294

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

187378
# Logging query results
188379
Keywords, that fetch results of a SQL query, print the result rows as a table in RF log.
@@ -204,7 +395,7 @@ Library DatabaseLibrary log_query_results_head=10
204395
205396
# Logging of query results is enabled (default), log head limit is disabled (log all rows).
206397
Library DatabaseLibrary log_query_results_head=0
207-
````
398+
```
208399

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

417+
# Omitting trailing semicolon behavior
418+
Some databases (e.g. Oracle) throw an exception, if you leave a semicolon (;) at the SQL string end.
419+
However, there are exceptional cases, when you need it even for Oracle - e.g. at the end of a PL/SQL block.
420+
421+
The library can handle it for you and remove the semicolon at the end of the SQL string.
422+
By default, it's decided based on the current database module in use:
423+
- For `oracle_db` and `cx_Oracle`, the trailing semicolon is removed
424+
- For other modules, the trailing semicolon is left as it is
425+
426+
You can also set this behavior explicitly:
427+
- Using the `Set Omit Trailing Semicolon` keyword
428+
- Using the `omit_trailing_semicolon` parameter in the `Execute SQL String` keyword.
429+
226430
# Database modules compatibility
431+
> Looking for [Connection examples for different DB modules](#connection-examples-for-different-db-modules)?
432+
227433
The library is basically compatible with any [Python Database API Specification 2.0](https://peps.python.org/pep-0249/) module.
228434

229435
However, the actual implementation in existing Python modules is sometimes quite different, which requires custom handling in the library.
@@ -247,8 +453,8 @@ Therefore there are some modules, which are "natively" supported in the library
247453
### Teradata
248454
- [teradata](https://github.com/teradata/PyTd)
249455
### IBM DB2
250-
- [ibm_db](https://github.com/ibmdb/python-ibmdb)
251-
- [ibm_db_dbi](https://github.com/ibmdb/python-ibmdb)
456+
- 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`.
457+
- *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).
252458
### ODBC
253459
- [pyodbc](https://github.com/mkleehammer/pyodbc)
254460
- [pypyodbc](https://github.com/pypyodbc/pypyodbc)

doc/index.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)