You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Database Library** is a [Robot Framework](https://robotframework.org/) library that provides keywords for interacting with databases.
6
+
[**Database Library**](https://github.com/MarketSquare/Robotframework-Database-Library) is a [Robot Framework](https://robotframework.org/) library that provides keywords for interacting with databases.
7
7
It offers keywords to e.g.
8
8
- connect to a database
9
9
- execute SQL queries
10
10
- fetch results from the database
11
11
- assert table contents and result sets
12
12
13
-
For specifics, please refer to the library's [Keyword documentation](https://marketsquare.github.io/Robotframework-Database-Library/#library-documentation-top).
13
+
For specifics, please refer to the library's [Keyword documentation](https://marketsquare.github.io/Robotframework-Database-Library/).
14
14
15
15
## Installation
16
16
@@ -20,171 +20,80 @@ For specifics, please refer to the library's [Keyword documentation](https://mar
20
20
pip install robotframework-databaselibrary
21
21
```
22
22
23
-
To connect to a database, you also need to install a Python Module adhearing to the [Python Database API Specification v2.0](https://www.python.org/dev/peps/pep-0249/).
24
-
You can find a list of supported database modules [here](https://wiki.python.org/moin/DatabaseInterfaces).
25
-
26
-
Examples are:
27
-
-[psycopg2](https://pypi.org/project/psycopg2/) for PostgreSQL
28
-
-[cx_Oracle](https://pypi.org/project/cx-Oracle/) for Oracle
29
-
-[pymysql](https://pypi.org/project/PyMySQL/) for MySQL
30
-
-[pyodbc](https://pypi.org/project/pyodbc/) for Microsoft SQL Server
31
-
32
23
## Examples
33
24
34
25
Check out the [tests](https://github.com/MarketSquare/Robotframework-Database-Library/tree/master/test) folder in the repository for examples.
35
26
36
-
Example for a PostgreSQL database:
27
+
### Basic Usage Example
37
28
38
29
```robotframework
39
30
*** Settings ***
40
-
Suite Setup Connect To Database psycopg2 ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort}
41
-
Suite TeardownDisconnect From Database
42
-
Library DatabaseLibrary
43
-
Library OperatingSystem
44
-
Library Collections
45
-
46
-
*** Variables ***
47
-
${DBHost} localhost
48
-
${DBName} travis_ci_test
49
-
${DBPass} ""
50
-
${DBPort} 5432
51
-
${DBUser} postgres
31
+
Library DatabaseLibrary
32
+
Test SetupConnect To My Oracle DB
33
+
34
+
*** Keywords ***
35
+
Connect To My Oracle DB
36
+
Connect To Database
37
+
... oracledb
38
+
...db_name=db
39
+
...db_user=my_user
40
+
...db_password=my_pass
41
+
...db_host=127.0.0.1
42
+
...db_port=1521
52
43
53
44
*** Test Cases ***
54
-
Create person table
55
-
${output} = Execute SQL String CREATE TABLE person (id integer unique,first_name varchar,last_name varchar);
Check If Exists In Database SELECT id FROM person WHERE first_name = 'Franz Allan';
72
-
73
-
Check If Not Exists In DB - Joe
74
-
Check If Not Exists In Database SELECT id FROM person WHERE first_name = 'Joe';
75
-
76
-
Table Must Exist - person
77
-
Table Must Exist person
78
-
79
-
Verify Row Count is 0
80
-
Row Count is 0 SELECT * FROM person WHERE first_name = 'NotHere';
81
-
82
-
Verify Row Count is Equal to X
83
-
Row Count is Equal to X SELECT id FROM person; 2
84
-
85
-
Verify Row Count is Less Than X
86
-
Row Count is Less Than X SELECT id FROM person; 3
87
-
88
-
Verify Row Count is Greater Than X
89
-
Row Count is Greater Than X SELECT * FROM person; 1
90
-
91
-
Retrieve Row Count
92
-
${output} = Row Count SELECT id FROM person;
93
-
Log ${output}
94
-
Should Be Equal As Strings ${output} 2
95
-
96
-
Retrieve records from person table
97
-
${output} = Execute SQL String SELECT * FROM person;
98
-
Log ${output}
99
-
Should Be Equal As Strings ${output} None
100
-
101
-
Verify person Description
102
-
[Tags] db smoke
103
-
Comment Query db for table column descriptions
104
-
@{queryResults} = Description SELECT * FROM person LIMIT 1;
105
-
Log Many @{queryResults}
106
-
${output} = Set Variable ${queryResults[0]}
107
-
Should Be Equal As Strings ${output} Column(name='id', type_code=23, display_size=None, internal_size=4, precision=None, scale=None, null_ok=None)
108
-
${output} = Set Variable ${queryResults[1]}
109
-
Should Be Equal As Strings ${output} Column(name='first_name', type_code=1043, display_size=None, internal_size=-1, precision=None, scale=None, null_ok=None)
110
-
${output} = Set Variable ${queryResults[2]}
111
-
Should Be Equal As Strings ${output} Column(name='last_name', type_code=1043, display_size=None, internal_size=-1, precision=None, scale=None, null_ok=None)
112
-
${NumColumns} = Get Length ${queryResults}
113
-
Should Be Equal As Integers ${NumColumns} 3
114
-
115
-
Verify foobar Description
116
-
[Tags] db smoke
117
-
Comment Query db for table column descriptions
118
-
@{queryResults} = Description SELECT * FROM foobar LIMIT 1;
119
-
Log Many @{queryResults}
120
-
${output} = Set Variable ${queryResults[0]}
121
-
Should Be Equal As Strings ${output} Column(name='id', type_code=23, display_size=None, internal_size=4, precision=None, scale=None, null_ok=None)
122
-
${output} = Set Variable ${queryResults[1]}
123
-
Should Be Equal As Strings ${output} Column(name='firstname', type_code=1043, display_size=None, internal_size=-1, precision=None, scale=None, null_ok=None)
124
-
${NumColumns} = Get Length ${queryResults}
125
-
Should Be Equal As Integers ${NumColumns} 2
126
-
127
-
Verify Query - Row Count person table
128
-
${output} = Query SELECT COUNT(*) FROM person;
129
-
Log ${output}
130
-
${val}= Get from list ${output} 0
131
-
${val}= Convert to list ${val}
132
-
${val}= Get from list ${val} 0
133
-
Should be equal as Integers ${val} 2
134
-
135
-
Verify Query - Row Count foobar table
136
-
${output} = Query SELECT COUNT(*) FROM foobar;
137
-
Log ${output}
138
-
${val}= Get from list ${output} 0
139
-
${val}= Convert to list ${val}
140
-
${val}= Get from list ${val} 0
141
-
Should be equal as Integers ${val} 0
142
-
143
-
Verify Query - Get results as a list of dictionaries
144
-
[Tags] db smoke
145
-
${output} = Query SELECT * FROM person; \ True
146
-
Log ${output}
147
-
Should Be Equal As Strings &{output[0]}[first_name] Franz Allan
148
-
Should Be Equal As Strings &{output[1]}[first_name] Jerry
149
-
150
-
Verify Execute SQL String - Row Count person table
151
-
${output} = Execute SQL String SELECT COUNT(*) FROM person;
- Both thick and thin client modes are supported - you can select one using the `oracle_driver_mode` parameter.
79
+
- 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.
- 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`.
94
+
-*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).
0 commit comments