Comments (6)
Yes, I came to the same conclusion, the default values for dbHost ja dbPort should be removed from the connect_to_database function definition. Now, if I try to connect to a MySQL database and only give the config file as an argument to the connect keyword, it tries to connect to port 5432 when MySQL only listens to port 3306 by default. It feels a bit silly to have to give the dbPort argument explicitly in the keyword call when all other arguments can be read from the config file. (My MySQL is in localhost so I didn't have to worry about that.)
Also, when I tried to force the connect function to read the config file by reversing the assignment order -> dbPort = int(config.get('default', 'dbPort') or dbPort),
I started getting an error from ConfigParser saying: NoSectionError: No section: 'default'.
I can't understand why this suddenly happens as it has clearly just read at least three arguments from the very same default-section.
Thirdly, I would have greatly appreciated it if there had been an example of the contents of a config file somewhere in the documentation. Now I had to go by trial and error when creating one.
from robotframework-database-library.
As I only have a postgresql setup to test on right now, can you try something for me?
Comment out the dbPort = line below the config parser and add it into the for loop below, something like:
#dbPort = int(dbPort or config.get('default', 'dbPort') or 5432)
db_api_2 = import(dbapiModuleName)
if dbapiModuleName in ["MySQLdb", "pymysql"]:
dbPort = int(dbPort or config.get('default', 'dbPort') or 3306)
#dbPort = dbPort or 3306
logger.debug ('Connecting using : %s.connect(db=%s, user=%s, passwd=%s, host=%s, port=%s) ' % (dbapiModuleName, dbName, dbUsername, dbPassword, dbHost, dbPort))
self._dbconnection = db_api_2.connect (db=dbName, user=dbUsername, passwd=dbPassword, host=dbHost, port=dbPort)
elif dbapiModuleName in ["psycopg2"]:
dbPort = int(dbPort or config.get('default', 'dbPort') or 5432)
#dbPort = dbPort or 5432
logger.debug ('Connecting using : %s.connect(database=%s, user=%s, password=%s, host=%s, port=%s) ' % (dbapiModuleName, dbName, dbUsername, dbPassword, dbHost, dbPort))
self._dbconnection = db_api_2.connect (database=dbName, user=dbUsername, password=dbPassword, host=dbHost, port=dbPort)
I think this will move the logic of defining the port into a better place and ultimately achieve what you are looking for here. If this works for you, I will try and get the release updated.
from robotframework-database-library.
I changed connection_manager.py as you requested by moving the dbPort assignment inside the if-clause. I think it is better where it was, though, because there you only need to read the config file once instead of thrice in all the branches of the if.
It didn't help. Port number is okay if you give it separately to the Connect To Database keyword but from inside the config file it doesn't get read.
I still think the problem is that the dbPort variable already has a value (the default, 5432) when execution reaches the moved assignment:
dbPort = int(dbPort or config.get('default', 'dbPort') or 3306)
In the case of using a config file this translates as:
dbPort = int(5432 or or 3306)
Since 'or' is a short-circuit operator in Python it never even tries to resolve the config.get() call because the first operand is already true. Then it tries to connect to MySQL using PostgeSQL default port which of course results in the target machine actively refusing the connection.
If you remove the default value for dbPort from the function definition this will work provided that the if branches for MySQL and PostgreSQL have assignments:
dbPort = int(dbPort or 3306) and
dbPort = int(dbPort or 5432)
respectively, as a last resort, if the port number is given neither explicitly nor in the config file.
This all holds true for the dbHost argument as well, although you needn't define 'localhost' inside the if as it doesn't vary from database to database as the port number does.
from robotframework-database-library.
Can you please retest with the latest code from master? I believe we have this all working now.
from robotframework-database-library.
Thank you, I believe so, too! At least my problem went away.
I noticed you added a new elif section for pyodbc apimodule. I'm afraid it looks to me like you could only connect to an SQL Server using pyodbc. Or can the SQL Server driver handle other databases, too? I don't know and I haven't tested this. I've always thought that pyodbc was a general purpose apimodule for connecting to many brands of database and even excel files.
from robotframework-database-library.
I will have to look into this more, I am not sure if pyodbc will connect to other databases or not. Glad to hear this issue is resolved and I know if fixed issues for others as well. Thanks for retesting, I am closing now.
from robotframework-database-library.
Related Issues (20)
- Keyword "table must exist" fails with DB's which don't support information_schema
- Improve error messages in assertion keywords
- Recover docs from original Franz-see project
- v.1.30 - connection issue using MS SQL + pyodbc + SQL Driver HOT 1
- [feature] enhance Execute script KW to support more statement blocks HOT 6
- New Oracledb driver - support switching to thick mode and back to thin mode HOT 3
- Extend compare methods with pandas support HOT 2
- Self managed connections HOT 5
- Use Python convention naming
- [New client] Impala client
- [New client] Databricks client
- Handling multiple database connections HOT 5
- Query result list contains pyodbc.Row instead of python tuples HOT 4
- ProgrammingError: Unsupported parameter (Support for dict only): [] HOT 6
- Execute Sql String error with characters % HOT 6
- Parse SQL script files using external lib
- Single "Row Count" keyword with Assertion Engine HOT 1
- Smart wait for "check if exists" / "row count" assertion keywords
- Query params don't work for MS SQL (pymssql) HOT 1
- Call stored procedure does not work with pymssql driver HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from robotframework-database-library.