Hopefully I can explain this correctly. I am trying to take a MySQL select statement, get the output into a list, then upload that list back to the MySQL server. - cursor.execute("SELECT stuff FROM place WHERE thing = 3 ORDER BY track_id ASC")
This spits out a tuple of integers ...
((1L,), (2L,), (3L,), (4L,), (5L,), (6L,), (7L,), (8L,), (9L,), (10L,), (11L,))
... with an 'L' following each one.
But I want to update the database with this set as:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
At first I thought I had it, but each converted row of tuples was the same thing even though the actually data pulled had changed. Anyone have any ideas how to do this?
Actually, I figured it out myself... -
for n in range(0,75):
-
cursor.execute("SELECT row FROM table WHERE column = %s ORDER BY column ASC", (n))
-
result = cursor.fetchall()
-
List = list()
-
for t in result:
-
List.append(int(t[0]))
-
List = ",".join(map(str,List))
-
ListUpdate = cursor.execute("UPDATE table SET column = %s WHERE column = %s", (str(List),n))
-
This will take the SELECT statement from MySQL as a tuple, format it into a list without the L or parenthesis, then UPDATE the MySQL with the list.
3 18251
It sounds like you want to convert something from a tuple containing a long integer into an integer? - for t in ((1L,), (2L,), (3L,), (4L,), (5L,), (6L,), (7L,), (8L,), (9L,), (10L,), (11L,)):
-
print int(t[0])
Glenton, thanks for the response. I actually got it to give me the list without the L in it. But that's half the thing. I need to dump those numbers back into a list and insert that list into a MySQL database.
I think that PHP will provide a better solution than Python at this point.
Actually, I figured it out myself... -
for n in range(0,75):
-
cursor.execute("SELECT row FROM table WHERE column = %s ORDER BY column ASC", (n))
-
result = cursor.fetchall()
-
List = list()
-
for t in result:
-
List.append(int(t[0]))
-
List = ",".join(map(str,List))
-
ListUpdate = cursor.execute("UPDATE table SET column = %s WHERE column = %s", (str(List),n))
-
This will take the SELECT statement from MySQL as a tuple, format it into a list without the L or parenthesis, then UPDATE the MySQL with the list.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: hokieghal99 |
last post by:
Hi,
I'd like to get user input from an html form into a mysql select
statement. Here's where I'm stumped:
$result = mysql_query("SELECT * FROM dept WHERE notes LIKE
'%search-string%'",$db);
...
|
by: phpfrizzle |
last post by:
Hi there,
I have a site with products on it.
The site has a mysql backend.
All products belong to certain series (table series).
There can be up to 4 different products (table products)...
|
by: mike-nospam |
last post by:
Trying to write a php script where the user will enter the row number
(index) of a record. Say, for example, user wants record 55:
: select * from MyTable where Index = "55"
where Index is an...
|
by: jossinet |
last post by:
Bonjour,
j'ai une table : matable
dans laquelle j'ai un champs : codepostal
Ce champs code postal est rempli d'enregistrements qui ont des valeurs
de 5 chiffres.
Je souhaite créer un bouton...
|
by: Eric Freeman |
last post by:
Is there any way in Postgres to SELECT a list of table names from inside of
a C program using ECPG?
Something similar to SELECT current_user that will give you all of the
tables in the database...
|
by: VK |
last post by:
I'm looking for autoexpand <select> list onfocus and collapse it back
onselect/onblur (the list is select-one type)
I know it is not possible directly, but I've seen here a hack by
changing...
|
by: vncntj |
last post by:
I'm trying to get the venue in the 'List' column when in contains a
value. But if the venue Is Null then place the event in the 'List'
SELECT
CASE
WHEN event Is Null THEN venue
Else
event...
|
by: Beholder |
last post by:
I hope that someone can help me with the following:
Short background explenation:
I have a shrfepoint page (newform.aspx) in a item list. On this page is
a lookup column that displays a lookup...
|
by: =?Utf-8?B?bWNhdWxpZmZl?= |
last post by:
I have an old application ( pre-VB5) that I need to add a select/option list
to. This is an edit program so the values for the form will be retrieved
from a database. How do I set the value of...
|
by: Andrus |
last post by:
How to create select columns list dynamically in DLinq ?
I want to create something like
Console.WriteLine("Enter list of columns to return, separated by commas:");
string list =...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| | |