@@ -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
105296The ` 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
183374Check Row Count ${sql} == 2 retry_timeout=10 seconds
184375Check Query Result ${sql} contains Allan retry_timeout=5s retry_pause=1s
185- ````
376+ ```
186377
187378# Logging query results
188379Keywords, 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).
206397Library DatabaseLibrary log_query_results_head=0
207- ````
398+ ```
208399
209400# Commit behavior
210401While 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
223414using the ` Set Auto Commit ` keyword.
224415This 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+
227433The library is basically compatible with any [ Python Database API Specification 2.0] ( https://peps.python.org/pep-0249/ ) module.
228434
229435However, 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 )
0 commit comments