Robotframwork database Test (i)--pymysql and PYODBC

Source: Internet
Author: User
Tags mysql odbc driver

This section only summarizes the MySQL database using Pymysql and Pyodbc links.

2 can be linked to MySQL data, for additional deletion check. However, using the PYODBC operation database, the Chinese support is better. Pymysql need to deal with the code. So all 2 of them say, their choice ha.

1. Install the databaselibrary,pyodbc,pymysql.

Pip Install Robotframework-databaselibrary

Pip Install Pymysql

Pip Install Pyodbc

The above is the command installation, in addition to the command installation, you can also download the installation package for installation. CD to the installation package directory, Python setup.py install.

2. Install and configure MySQL Connector.

1) to use PYODBC to connect MySQL, also need a tool, is MySQL Connector, address: http://www.mysql.com/downloads/connector/odbc/

Note: Be sure to download the version that matches your Python and Pyodbc

To view the Python version:

cmd command: Enter Python to see if it is 32-bit, be sure to install the 32-bit MySQL connector.

No, when Robotframework executes PYODBC linked database, the return error

Error: (' IM002 ', ' [IM002] [Microsoft][odbc \xc7\xfd\xb6\xaf\xb3\xcc\xd0\xf2\xb9\xdc\xc0\xed\xc6\xf7] \xce\xb4\xb7\xa2 \xcf\xd6\xca\xfd\xbe\xdd\xd4\xb4\xc3\xfb\xb3\xc6\xb2\xa2\xc7\xd2\xce\xb4\xd6\xb8\xb6\xa8\xc4\xac\xc8\xcf\xc7\ Xfd\xb6\xaf\xb3\xcc\xd0\xf2 (0) (SQLDriverConnect) ')

2) After the installation is complete, configure the MySQL data source.

Action: Open Control Panel-Admin tool-odbc data Source, click "Add"

After the choice of configuration, do not know, can Baidu, Baidu has specific ODBC configuration instructions.

Note: If the 32-bit MySQL connecter is installed.

Open Control Panel-Admin tool-odbc data Source, click "Add", will not see the installed MySQL ODBC driver.

It's not not installed, it's a different place. Configure the data source: Run C:\Windows\SysWOW64\odbcad32.exe to find the driver in the data source and configure it.

( WOW64 What do you mean? WOW64 (windows-on-windows-64bit), a subsystem above WINDOWS64, the WINDOWS64 bit is compatible with 32 bits, so there is a 32-bit subsystem. )

3. Connect the data and make inquiries

1) Pymysql

Operation Result:

interface. test1
20161108 14:58:54.888:info: @{receiverstate} = [('?? ',) | ('?? ',) | ('??? ',) | ('??? ',) | ('???????? ',) | ('?? ',) | ('?? ',) | ('??? ',) | ('??? ',) | ('???????? ',) | ('?? ',) | ('?? ',) | ('??? ',) | ('??? ',) | (‘????????‘,) ]
20161108 14:58:54.890:info: ('?? ',)
20161108 14:58:54.890:info: ('?? ',)
20161108 14:58:54.890:info: ('??? ',)
20161108 14:58:54.890:info: ('??? ',)

20161108 14:58:54.893:info:??

Look at the results and find a bunch of??? These are the Chinese transcoding problem, you can write a transcoding method can also be set.

2) Pyodbc

Operation Result:

interface. test2
20161108 14:58:54.902:info: @{receiverstate} = [(U ' \u4e0a\u6d77 ',) | (U ' \u5317\u4eac ',) | (U ' \u5c71\u897f\u7701 ',) | (U ' \u5409\u6797\u7701 ',) | (U ' \u65b0\u7586\u7ef4\u543e\u5c14\u81ea\u6cbb\u533a ',) | (U ' \u4e0a\u6d77 ',) | (U ' \u5317\u4eac ', ...
20161108 14:58:54.902:info: (U ' \u4e0a\u6d77 ',)
20161108 14:58:54.902:info: (U ' \U5317\U4EAC ',)
20161108 14:58:54.902:info: (U ' \u5c71\u897f\u7701 ',)
20161108 14:58:54.902:info: (U ' \u5409\u6797\u7701 ',)
20161108 14:58:54.918:info: Shanghai

It is not clear from the example that PYODBC support for Chinese is better.

Of course, the powerful little friends can write their own method, it will be more powerful ha.

Robotframwork database Test (i)--pymysql and PYODBC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.