mysql-connector-python

MySql cursors.execute() with only one parameter: Why is a string sliced into a list?

我只是一个虾纸丫 提交于 2019-12-18 07:46:08
问题 Status Quo: I have a working database with tables and can query, insert, update, etc. Also the cursor is connected to the right database. The table: Problem: When it comes to querying data from a table I run into trouble: query = 'SELECT Last_Request_Time FROM Products WHERE idProduct = %s' idProduct = '106' cursor.execute(query, (idProduct)) While debugging I have a look at the cursor.execute() function: params = str: 106 will be passed to: stmt = operation % self._process_params(params)

I get NotImplementedError when trying to do a prepared statement with mysql python connector

徘徊边缘 提交于 2019-12-14 03:45:03
问题 I want to use prepared statements to insert data into a MySQL DB (version 5.7) using python, but I keep getting a NotImplementedError. I'm following the documentation here: https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursorprepared.html Using Python 2.7 and version 8.0.11 of mysql-connector-python library: pip show mysql-connector-python --- Metadata-Version: 2.1 Name: mysql-connector-python Version: 8.0.11 Summary: MySQL driver written in Python Home-page: http:/

Python mysql.connector InternalError: Unread result found when close cursor

烈酒焚心 提交于 2019-12-12 17:35:20
问题 I want to read part of result from cursor and then close it without reading all result. cursor.close() raises InternalError: Unread result found. Is it possible to close cursor without iterating through all result or using buffer option ? Update: My query get about 3000 records, I aim to getting first several records which fit some conditions. After iterating through part of result, I get what I want. Then I want to just abandon unread result. I don't use buffer option which, as I know, will

MySQL Connector/Python InterfaceError: “Failed parsing EOF packet”

为君一笑 提交于 2019-12-11 17:26:11
问题 As far as I can tell, I have installed the MySQL Connector/Python (v1.2.3) module without a problem. This is on CentOS 5.4 using Python 2.7.7 (Anaconda distribution, although the same happens on a vanilla installation). I'm able to import it and initialize a connection with a MySQL server (v4.1.20). This server is accessed over the LAN, not locally. The is_connected() method asserts that I'm properly connected >>> import mysql.connector >>> cnx = mysql.connector.connect(<MySQL database

AttributeError:__exit__ on python 3.4

我们两清 提交于 2019-12-11 13:27:35
问题 Original Code: import sys import os import latexmake import mysql.connector conn = mysql.connector.connect(user='root',password='oilwell',host='localhost',database='sqlpush1') with conn: mycursor = conn.cursor() mycursor=execute("SELECT DATE,oil,gas,oilprice,gasprice,totrev FROM results WHERE DATE BETWEEN '2011-01-01' AND '2027-12-01'") rows = mycursor.fetchall() a.write("\\documentclass{standalone}\\usepackage{booktabs}\n\n\\usepackage{siunitx}\r \n\ \r\n\\begin{document}\r\n\\begin{tabular}

Unable to use None (NULL) values in python mysql.connector in prepared INSERT statement

非 Y 不嫁゛ 提交于 2019-12-07 02:13:25
问题 When trying to use prepared cursor and insert NULL values the mysql.connector reports an error: mysql.Error: 1210 (HY000): Incorrect arguments to mysqld_stmt_execute Here is a code that shows this exactly. from __future__ import print_function import mysql.connector def execsql(cursor, sqlstmt): try: cursor.execute(sqlstmt) except mysql.connector.Error as e: print("mysql.Error: %s" % e) print(cursor._executed, '\n') def execsqlwithparams(cursor, sqlstmt, params): try: cursor.execute(sqlstmt,

Why unexpected keyword 'multi' in Python's MySQLdb module?

喜夏-厌秋 提交于 2019-12-06 11:56:11
问题 I am trying to delete a record in database using MySQLdb module. In https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-execute.html, I found multi=True for executing multiple queries in execution but it generates error. Can someone help me knowing that what I am missing? query = "DELETE FROM Service_Machine WHERE Id=(SELECT Id FROM Machines WHERE Id="+id+");" \ "DELETE FROM Machine_Usage WHERE Id=(SELECT Id FROM Machines WHERE Id="+id+");" \ "DELETE FROM Machines

python mysql.connector DictCursor?

天涯浪子 提交于 2019-12-05 10:26:20
问题 In Python mysqldb I could declare a cursor as a dictionary cursor like this: cursor = db.cursor(MySQLdb.cursors.DictCursor) This would enable me to reference columns in the cursor loop by name like this: for row in cursor: # Using the cursor as iterator city = row["city"] state = row["state"] Is it possible to create a dictionary cursor using this MySQL connector? http://dev.mysql.com/doc/connector-python/en/connector-python-example-cursor-select.html Their example only returns a tuple. I

Unable to use None (NULL) values in python mysql.connector in prepared INSERT statement

时光总嘲笑我的痴心妄想 提交于 2019-12-05 07:49:36
When trying to use prepared cursor and insert NULL values the mysql.connector reports an error: mysql.Error: 1210 (HY000): Incorrect arguments to mysqld_stmt_execute Here is a code that shows this exactly. from __future__ import print_function import mysql.connector def execsql(cursor, sqlstmt): try: cursor.execute(sqlstmt) except mysql.connector.Error as e: print("mysql.Error: %s" % e) print(cursor._executed, '\n') def execsqlwithparams(cursor, sqlstmt, params): try: cursor.execute(sqlstmt, params) except mysql.connector.Error as e: print("mysql.Error: %s" % e) print(cursor._executed, "params

python mysql.connector DictCursor?

非 Y 不嫁゛ 提交于 2019-12-03 22:53:54
In Python mysqldb I could declare a cursor as a dictionary cursor like this: cursor = db.cursor(MySQLdb.cursors.DictCursor) This would enable me to reference columns in the cursor loop by name like this: for row in cursor: # Using the cursor as iterator city = row["city"] state = row["state"] Is it possible to create a dictionary cursor using this MySQL connector? http://dev.mysql.com/doc/connector-python/en/connector-python-example-cursor-select.html Their example only returns a tuple. I imagine the creators of MySQL would eventually do this for us? J1MF0X According to this article it is