Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for connection attributes #6

Closed
wants to merge 2 commits into from
Closed

Conversation

dveeden
Copy link

@dveeden dveeden commented May 9, 2015

This makes it possible to send connection attributes.

By default _client_name and _client_version will be send.

Custom attributes can be used with the connattrs dict.

Maybe set 'program_name' to sys.argv[0] by default? and maybe also set '_pid' just like libmysql?
I didn't add anything to the testsuite.
I didn't test with cext.

$ cat test.py 
#!/usr/bin/env python
import sys
import mysql.connector

conn = mysql.connector.connect(host='127.0.0.1',user='msandbox',password='msandbox',port=5707)
cur = conn.cursor()
cur.execute('SELECT * FROM performance_schema.session_connect_attrs')
for res in cur:
    print(res)
cur.close()
conn.close()

conn = mysql.connector.connect(host='127.0.0.1',user='msandbox',password='msandbox',port=5707, connattrs={'foo': 'bar', 'program_name': sys.argv[0]})
cur = conn.cursor()
cur.execute('SELECT * FROM performance_schema.session_connect_attrs')
for res in cur:
    print(res)
cur.close()
conn.close()
$ ./test.py 
(63, bytearray(b'_client_version'), bytearray(b'2.1.1a1'), 0)
(63, bytearray(b'_client_name'), bytearray(b'MySQL Connector/Python'), 1)
(64, bytearray(b'_client_version'), bytearray(b'2.1.1a1'), 0)
(64, bytearray(b'program_name'), bytearray(b'./test.py'), 1)
(64, bytearray(b'foo'), bytearray(b'bar'), 2)
(64, bytearray(b'_client_name'), bytearray(b'MySQL Connector/Python'), 3)

@dveeden
Copy link
Author

dveeden commented May 9, 2015

I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Please confirm this code is submitted under the terms of the OCA (Oracle's Contribution Agreement) you have previously signed by cutting and pasting the following text as a comment:
"I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it."
Thanks

@dveeden
Copy link
Author

dveeden commented May 9, 2015

I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Your code has been assigned to an internal queue. Please follow
bug http://bugs.mysql.com/bug.php?id=77003 for updates.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants