Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 28th, 2013, 03:11 AM
MynE MynE is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 35 MynE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old January 28th, 2013, 03:41 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,358 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 9 h 33 m 51 sec
Reputation Power: 383
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!

Reply With Quote
  #3  
Old January 28th, 2013, 03:54 AM
MynE MynE is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 35 MynE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 32 m 59 sec
Reputation Power: 1
Oh I see thank you so much for your help

Reply With Quote
  #4  
Old January 28th, 2013, 02:40 PM
MynE MynE is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 35 MynE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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!!

Reply With Quote
  #5  
Old January 28th, 2013, 03:26 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,358 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 9 h 33 m 51 sec
Reputation Power: 383
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))

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Insert into sql

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap