mysql-python

python - mysql query not working

拈花ヽ惹草 提交于 2019-12-25 17:00:14
问题 I am trying to load data into a MySQL table with the following Python script: conn = connect_db() cursor = conn.cursor() cursor.execute( "LOAD DATA LOCAL INFILE " + jobsummaryfile + " INTO TABLE daily_job_summary " + "FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' (@col1, @col2, @col3, @col4) " + "set jobname=@col1, queue=@col2, maphours=@col3, reducehours=@col4, date=" + date + ", pipeline=" + pipeline_name + ", grid=" + grid ) I am getting the following error: _mysql_exceptions

SQL statement fails through mysqldb.query in Python

安稳与你 提交于 2019-12-25 16:44:54
问题 I am trying to pass a query through my script, but i get a SQL error. Running the same sql statement in Heidisql works fine. My question is: - What am I doing wrong? error message _mysql.connection.query(self, query) _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Gabrielsen)' at line 1") Python script where Database is the correct connection to database F=

Listing table results to HTML with Flask

点点圈 提交于 2019-12-25 16:09:39
问题 I am struggling with passing my SELECT all statement results to my view. I am using flask and MySQLdb. What is the proper syntax to display all my results from my table to my HTML page? I would love to pass a list through, but was unable to figure the syntax out for that. HTML call {{ session.qid }} just to test, and nothing displayed. Here's the python code I have so far: @app.route('/view_answered/', methods=['GET','POST']) def view_answered(): error = '' try: if request.method == 'POST': c

Python-Warning: Truncated incorrect DOUBLE value

大憨熊 提交于 2019-12-25 05:28:35
问题 I am trying to fetch "bar_ids" from "foo" table using mysql-python. To this end, I got the following error and I am receiving only few bar_ids. How do I get this correctly without warning error? My table is shown below: create table foo (foo_id int, bar_id int, foo_name varchar(255)) My query & Error: foo_ids = 16600, 16602, 16607, 16609, 16611, 16613 Warning: Data truncated for column 'bar_id' at row 1 cursor.execute("""select bar_id from foo where foo_id in (%s)""", (foo_ids,)) Warning:

Python MySQLdb cursor.execute() insert with varying number of values

霸气de小男生 提交于 2019-12-25 04:47:12
问题 Similar questions have been asked, but all of them - for example This One deals only with specified number of values. for example, I tried to do this the following way: def insert_values(table, columns, values, database): """ columns - a string representing tuple with corresponding columns values - a tuple containing values """ query=database.cursor() query.execute("INSERT INTO `{}` {} VALUES{}".format(table,columns,str(values))) But that's no good - although the insert initially seemed fine

MySQL returned datatype and python outputs different type for different functions

你。 提交于 2019-12-25 02:20:29
问题 I am having plenty of problems with the MySQL returns and entering it into a Qt table with python. I use data = cursor.fetchall() for data in data: for i in range(len(data)): sqlTableWidget.setItem(index,i,QtGui.QTableWidgetItem(data[i])) index = index +1 Originally I would put str() around the return, and that worked for everything except when i had unicode problems with foreign language and on the datetime. So now I dont put str() and the foreign language inserts to the table. However,

Why isn't MySQLdb installation working on my 64bit Mac

陌路散爱 提交于 2019-12-25 00:33:35
问题 >>> import MySQLdb Traceback (most recent call last): File "<stdin>", line 1, in <module> File "build/bdist.macosx-10.6-intel/egg/MySQLdb/__init__.py", line 19, in <module> File "build/bdist.macosx-10.6-intel/egg/_mysql.py", line 7, in <module> File "build/bdist.macosx-10.6-intel/egg/_mysql.py", line 6, in __bootstrap__ ImportError: dlopen(/Users/samwu/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so, 2): no suitable image found. Did find: /Users/samwu/.python-eggs

Difficulty connecting python3 to a mariadb - take2

自作多情 提交于 2019-12-25 00:04:17
问题 I asked a previous question with the same title but none of the suggestions worked. I thought a supplementary question with a distillation of all the avenues tried would make for a clearer question than trying to shoehorn it into the original post (but maintain all the feedback from the original: Difficulty connecting Python3 to a MariaDB - take 1) - please let me know (politely) if there's an alternative preferred approach I have Python2.7 and python3 installed on an OpenSuse (Leap 15.1) and

UPDATE statement error - MySQLdb/Python

二次信任 提交于 2019-12-24 17:19:17
问题 I'm testing an UPDATE statement on an existing record in my test table. It looks like this: term = 'example-column' termInserted = term + '_inserted' mostRecentRecord = 6 nResult = 777 bResultsInserted = 77 #print(termInserted) cur.execute("UPDATE `term_results` SET `%s` = %s, `%s` = %s WHERE `results_id` = %s", (term, nResult, termInserted, bResultsInserted, mostRecentRecord)) connectToDb.commit() When I run this code I get the following error: Error 1054: Unknown column ''example-column''

MySQLdb error local variable referenced before assignment (different than usual)

北慕城南 提交于 2019-12-24 16:35:17
问题 I am attempting to add some data to MySQL database via a loop that iterates through the API that returns a JSON file. I am using Python and MySQLdb module. For some reason I am getting the infamous UnboundLocalError. I looked at the other scenarios when this problem occurred and that have already been answered on StackOverflow but nothing resonated with me and I couldn't apply it directly to this problem. Here's my code: def request(API_KEY, URL, ch_no): url = URL + ch_no + '/request' request