User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 391,821 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,625 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 536 | Replies: 4 | Solved
Reply
Join Date: Jul 2007
Posts: 37
Reputation: linux0id is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
linux0id's Avatar
linux0id linux0id is offline Offline
Light Poster

sql "insert into" question

  #1  
Mar 26th, 2008
Hello everyone!
I am writing a music database, and I need to insert into album table the path to its cover. However, not every album has a cover in its directory, so I've made an algorithm that only gets the albumID that has a cover. My question is - how can I insert value into one column in a row with a specific ID (or name)? I have tried this -
"insert into albums (cover_path) values ('%s') WHERE albumID=%d"
but it sais that theres an error at WHERE. How can I do this? I am using sqlite3 and C++. Thanks!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: South Africa
Posts: 59
Reputation: RoryGren is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
RoryGren's Avatar
RoryGren RoryGren is offline Offline
Junior Poster in Training

Re: sql "insert into" question

  #2  
Mar 26th, 2008
It sounds like you need to UPDATE rather than insert. Insert is used when the row doesn't exist at all. Update is used when you want to change the value of one or more columns in an existing row.

UPDATE albums 
SET cover_path = Your_Path
WHERE albumID = Your_Album_Id

Hope that helps.
Reply With Quote  
Join Date: Oct 2007
Location: South Africa
Posts: 59
Reputation: RoryGren is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
RoryGren's Avatar
RoryGren RoryGren is offline Offline
Junior Poster in Training

Re: sql "insert into" question

  #3  
Mar 26th, 2008
Maybe I missed the picture ...

You want to insert into table albums ...

insert into albums (albumID, cover_path) values ('%s', %d)

Maybe?
Reply With Quote  
Join Date: Jul 2007
Posts: 37
Reputation: linux0id is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
linux0id's Avatar
linux0id linux0id is offline Offline
Light Poster

Re: sql "insert into" question

  #4  
Mar 26th, 2008
UPDATE is what I think I need. I will try it out tonight and see what happens. Thanks
Reply With Quote  
Join Date: Jul 2007
Posts: 37
Reputation: linux0id is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
linux0id's Avatar
linux0id linux0id is offline Offline
Light Poster

Re: sql "insert into" question

  #5  
Mar 27th, 2008
yep, the UPDATE statement was it. Thanks a lot!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MySQL Marketplace
Thread Tools Display Modes

Other Threads in the MySQL Forum

All times are GMT -4. The time now is 5:45 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC