The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Insert into sql
Discuss Insert into sql in the Python Programming forum on Dev Shed. Insert into sql Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 28th, 2013, 03:11 AM
|
|
Contributing User
|
|
Join Date: Nov 2012
Posts: 35
Time spent in forums: 6 h 32 m 59 sec
Reputation Power: 1
|
|
|
Insert into sql
Hi guys i'm having problems with sql. Supposed that I have 3 arguments like this: a = 'abc', b = 'bca', c ='cba' and when I used the sql command
Code:
con.execute('INSERT INTO Facebook (Description, ByPersonName, Date) VALUES (%s, %s, %s)', a, b, c)
it said TypeError: execute() takes exactly 3 arguments (5 given) I tried with executemany and changed %s to ?, it's still keep saying like this.
Can somebody help me find out the solution of this problem pleasee >o<
Thank you
|

January 28th, 2013, 03:41 AM
|
 |
Contributing User
|
|
|
|
one or both of these should workd:
Code:
con.execute('INSERT INTO Facebook (Description, ByPersonName, Date) VALUES (%s, %s, %s)', (a, b, c) )
con.execute('INSERT INTO Facebook (Description, ByPersonName, Date) VALUES (%s, %s, %s)'%(a, b, c) )
__________________
[code] Code tags[/code] are essential for python code!
|

January 28th, 2013, 03:54 AM
|
|
Contributing User
|
|
Join Date: Nov 2012
Posts: 35
Time spent in forums: 6 h 32 m 59 sec
Reputation Power: 1
|
|
Oh I see thank you so much for your help 
|

January 28th, 2013, 02:40 PM
|
|
Contributing User
|
|
Join Date: Nov 2012
Posts: 35
Time spent in forums: 6 h 32 m 59 sec
Reputation Power: 1
|
|
Hi, may I ask you more. Supposed I have a data like this :
kk = ('a', 'b', 'c')
jj = ('myne', 'myne', 'myne')
dd = ('2013-01-28', '2013-01-28', '2013-01-28')
When I tried to use executemany
Code:
con.executemany("INSERT INTO Facebook (Description, ByPersonName, Date) VALUES (%s, %s, %s)", (kk , jj, dd))
the results I get is
Line 1: Description = a, ByPersonName = b, Date = c
Line 2: Description = myne, ByPersonName = myne,Date = myne
Line 3: Description = 2013-01-28, ByPersonName = 2013-01-28,Date = 2013-01-28
The data doesn't get into column properly, if you know this problem please tell me, Thank you!! 
|

January 28th, 2013, 03:26 PM
|
 |
Contributing User
|
|
|
|
Again, without actually knowing what I'm doing, you need transposition. zip transposes.
Code:
con.executemany("INSERT INTO Facebook (Description, ByPersonName, Date) VALUES (%s, %s, %s)", zip(kk , jj, dd))
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|