4
votes
2answers
1k views

Python MySQLdb converters isn't working

I'm trying to run an ETL script using python and MySQLdb but I'm stuck with the results from my initial extract query. The types returned are all Long and Decimal when I want Int and Float. I've ...
2
votes
2answers
4k views

Python MySQL Fetch Array

I would like to fetch an array in MySQL. Can someone please tell me how to use Python using MySQLdb to do so? For example, this is what I would like to do in Python: <?php ...
2
votes
1answer
772 views

mysqldb cursor.close() throws ProgrammingError: (2014, “commands out of sync…”) when executing sql read from file

As part of a larger debugging effort, I've run into the following bug using mysqldb: File "x.py" line x, in method cursor.close() File "y.py" line 100, in close while self.nextset(): pass ...
1
vote
2answers
113 views

What is the use of “”“…”“” in python instead of “…” or '…', especially in MySQLdb cursor.execute

is there a difference if i use """..""" in the sql of cusror.execute. Even if there is any slight difference please tell
1
vote
2answers
124 views

How can one optimize this MySQL count algorithm?

I have 2 tables; one is users and the other records user actions. I want to count the number of actions per user and record this in the users table. There are ~100k user and the following code takes 6 ...
1
vote
1answer
2k views

Django db.connection.cursor.fetchone() returns emty result, when raw SQL doesn't

I have method in a cusom QuerySet that performs raw SQL query to database. class QuerySet(models.query.QuerySet): def get_short(self, language_code='en'): """Returns shortest name for ...
1
vote
1answer
746 views

sql dump file.. load to mysql

Ok first, please assume that this is the first time I will be writing a single alphabet of code in SQL.. so please please please... it would be very kind if you can explain me each step. :) I am using ...
1
vote
1answer
28 views

MySQLdb: correct SQL request to group response data

I have two simple tables: authors and articles. You can find it here. So when I execute MySQLdb query: import MySQLdb def test_code(): db = MySQLdb.connect(mysql_host, mysql_user, mysql_pass, ...
1
vote
1answer
38 views

Efficient way to update MySql table by expanding fields

I want to expand my tweets (Twitter) database. This database contains an id INT, created_at DATETIME, and json TEXT fields. I want to update my database as follows. I want to add 2 extra columns ...
1
vote
2answers
33 views

Not able to get latest rows when re-rerunning same query at regular interval

I am using Python MySQLdb module. I am querying a table every 1 seconds. New rows are being added to this table all the time. The code is as follows; def main(): connectMySqlDb_tagem() ...
1
vote
2answers
131 views

Python MySQLdb Programming Error: 1064 when inserting data

I have this list info=[[u' Rasta.eon 2 - 1 Rasta.Xd ', u'Razer CS:GO Tournament 2', u'26-02-2014'], [u' XPC 1 - 2 WP.GG ', u'Roccat DotA 2 Tournament', u'26-02-2014']] conn= ...
1
vote
1answer
188 views

Updating a SQL table with Python 2.7?

I am using Python 2.7 to extract information from webpages (with BeautifulSoup), sort that information and insert it into a SQL table (with MySQLdb). That is quite simple, and I was able to find great ...
1
vote
1answer
48 views

Error when inserting row to table with MySQLdb

What is wrong below? import MySQLdb as mysql import datetime db = mysql.connect("localhost","root","passworld","employees" ) cursor = db.cursor() sql = "INSERT INTO employee(id, firstname, surname, ...
1
vote
1answer
52 views

Bulk insert into MySQL on duplicate

I have a question in MySQL and Python MySQLdb library: Suppose I'd like to insert a bulk in to the DB. When I'm inserting, there are possibly a duplicated among the records in the bulk, or a record ...
1
vote
2answers
74 views

SQL datatbase not accepting UTF -8 Characters [duplicate]

I have a python program wherein I access a url and extract data. I then input this data into a mysql table. The mysql table has columns pid ,position,club, points,s,availability, rating,name . I have ...
1
vote
2answers
104 views

Two connections/cursors in mysqldb - commands out of sync error

I'm using mysqldb in part of a script to copy information from one database to another. A snippet of the code I have is as follows: connection1 = mysqldb.connect('localhost', 'root', 'password', ...
1
vote
1answer
134 views

Passing variables (table name,data) into python mysqld query

I am trying to pass the name of the table and information to be inserted into the table as parameters. The query I have come up with is below: sql = """INSERT INTO `%s` (title,link,description) ...
1
vote
1answer
121 views

Unicode charactered filename SELECT SQL parameter issue

I have a webapp/webservice method created in django, which stores unicode character filenames on a DB-table. I am doing it by this method on the views.py script: SubmissionContents(id=subid, ...
0
votes
1answer
22 views

How to change DEFAULT CURRENT_TIMESTAMP format

Currently i am using the following code to create a table in mysql. CREATE TABLE example(id INT, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP); so whenever i insert data into this table i get the value of ...
0
votes
1answer
130 views

How to use other table field in SQL Where clause

I have a scenario were i need to select the rows from one table provided the the condition satisfies in other table. Sorry if i am confusing.... I am using MySQL as database with python 2.6 to ...
0
votes
2answers
502 views

Insert datetime.datetime object in MySQL

I'm trying to insert my datettime object into MySQL >>> t datetime.datetime(2013, 5, 21, 19, 33, 36, tzinfo=tzutc()) >>> cursor.execute('INSERT INTO tweets(created_at) VALUES ...
0
votes
4answers
45 views

MySQL Exact phrase match

I'm using python and the mysqldb module to search a database for a user input. I have tested the python and established a connection to the server and database. It's the SQL code giving me trouble. My ...
0
votes
1answer
18 views

Executing MySQL Queries in Python not work properly

I have problem with queries in python script. In phpmyadmin the same queries works properly, but in script, second query not work. (No errors, no Insert) my code: from sys import argv import ...
0
votes
1answer
54 views

MySQL and Python is generating a duplicate entry error I cannot resolve

I'm new to MySQL but have a solid foundation in Python. After researching this extensively over the last 2 days including reading many stackoverflow questions and answers, I still haven't been able to ...
0
votes
1answer
51 views

Django raw query returns no rows, when SQL does

I am about to smash my head against the wall. Consider the following piece of code: def get_cardnumbers_from_timestamp(request, since_time=0): if request.method == 'GET': if ...
0
votes
1answer
138 views

Execute over 1000 insert statements in 1 string

I thought this one would be simple, but for whatever reason the data isn't in the table when the script is done. I am generating a string of over 1000 queries, currently 1131, and they are separated ...
0
votes
1answer
35 views

SQL: update A where B is max for each unique combo of C and D, where D is element of joined table

Since this is complicated I'll give an example of what I'm trying to attempt: In the first table, User Data, I have user's and their saved game files (savefile's). Each user can be associated with ...
0
votes
1answer
71 views

Python MySQL Update taking 10-12 seconds to update about 1000 records

I have something along the lines of: while True: variables are set - Each loop the variables are different. sql = sql statement with above variables send sql to MySQL server I am able ...
0
votes
4answers
1k views

check if row exist in the table before adding it in SQL

i'm building a twitter grabber application using Python , Tweepy and MySQLdb modules it will be fetching millions of tweets so performance is an issue i want to check if the tweet_id exists before ...
0
votes
1answer
388 views

Mysqldb INSERT INTO syntax error in Python

I have an excel file which I am trying to put into mysql. There are 32 fields which I want to extract using the python plugin xlrd and put into mysql. The data is laid out like so: My methodology ...
0
votes
0answers
11 views

Python MySQLdb insert query not working [duplicate]

I am writing a python script that is supposed to insert a list of names from an array (where they are stored as strings) into a table. When I run the dbInsert() method it runs perfectly, however ...
0
votes
1answer
39 views

Getting “Can't connect to MySQL server on '203.171.xx.xx' (13) ” when trying to connect to remote sqlserver with python in cgi

When tried to connect to mysql database through python MySQLdb getting following err: File "/var/www/cgi-bin/add_user.py", line 39, in &lt;module&gt; addEntry(prop.text.strip()) File ...
0
votes
1answer
67 views

how print count table sql in python

im trying to print count table in python, im write this code: count = cur.execute("SELECT COUNT(*) FROM %s;" str(table)) print count all print results is 1, (think 1 = true), how i can print the ...
0
votes
1answer
57 views

cursor.execute adding delimiters to my sql query

I'm struggling with this code : addXml = '<bar><foo>thingy</foo></bar>' sql = 'INSERT INTO table(col1,col2) VALUES(%s,%s);' try: cursor = cnx.cursor() ...
0
votes
2answers
103 views

Compare two databases and find common value in a row

I have two databases (infact two database dump ... db1.sql and db2.sql) both database have only 1 table in each. in each table there are few columns (not equal number nor type) but 1 or 2 columns ...
0
votes
1answer
152 views

Django1.6, will transaction works for raw SQL?

Examples from offical document from django.db import connection def my_custom_sql(self): cursor = connection.cursor() cursor.execute("UPDATE bar SET foo = 1 WHERE baz = %s", [self.baz]) ...
0
votes
0answers
165 views

Python MySQLdb execute table variable (Scrapy)

First things first. I am runing my Scrapy scripts(version: 0.16.2) on Python 2.7.2+. The problem that I have is with pipe files and SQL syntax that I generate using MySQLdb library. Here is code that ...
0
votes
0answers
33 views

Trying to get a error for a function

I made a login UI to connect python with sql, using MySQLdb as the module for it. The UI work fine it pops up and does it thing the login data are stored in a class for that session. BUT if you put ...
0
votes
1answer
158 views

change CLIENT_FOUND_ROWS flag in django for mysql-python (MySQLdb)?

I have a problem with MySQL 5.5 INSERT ... ON DUPLICATE KEY UPDATE rows effected mismatch cursor.rowcount in a normal Django project According to doc: For INSERT ... ON DUPLICATE KEY UPDATE ...
0
votes
1answer
348 views

Python MySQLdb escape char: query works in MySQL but not in python MySQLdb

I'm trying to hand off data from Pandas (imported from a CSV) to a MySQL database via Python's MySQLdb library. I'm having trouble when literal backslashes come into play. I escape the single ...
0
votes
1answer
67 views

What do I use for HOST to connect to a remote server with mysqldb python?

Things to note in advance: I am using wampserver 2.2 Ive forwarded port 80 I added a rule to my firewall to accept traffic through port 3306 I have added "Allow from all" in directory of "A file i ...
0
votes
1answer
72 views

Grouping SQL queries

Sometimes an application requires quite a few SQL queries before it can do anything useful. I was wondering if there is a way to send those as a batch to the database, to avoid the overhead of going ...
0
votes
2answers
47 views

Syntax error using INSERT INTO statement with MySQL-Python

I'm trying to populate a table in a MySQL database with the values for each row coming from a text file, using this SQL syntax: INSERT INTO Table SET fieldname1 = "value1", fieldname2 = "value2", ...
-1
votes
2answers
160 views

Sql query for distinct user id on the basis of highest column value

Please help me to write a Django query and MySql query, I have a Table molesdetails like this: +---+ +--------+ +----------+ +----------+ |id | |user_id | | ref | | set | +---+ ...
-1
votes
1answer
13 views

How to use MYSQL indexes in python 2.7 MySQLdb

indie = '''CREATE FULLTEXT yay ON panda (Question, Answer);''' cursor.execute(indie) I already have a connection to the server, database and table and it all works, but for some reason it won't ...