DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   MySQL (http://www.daniweb.com/forums/forum126.html)
-   -   sql "insert into" question (http://www.daniweb.com/forums/thread115740.html)

linux0id Mar 26th, 2008 4:09 am
sql "insert into" question
 
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!

RoryGren Mar 26th, 2008 7:38 am
Re: sql "insert into" question
 
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.

RoryGren Mar 26th, 2008 7:41 am
Re: sql "insert into" question
 
Maybe I missed the picture ...

You want to insert into table albums ...

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

Maybe?

linux0id Mar 26th, 2008 1:08 pm
Re: sql "insert into" question
 
UPDATE is what I think I need. I will try it out tonight and see what happens. Thanks

linux0id Mar 27th, 2008 10:36 am
Re: sql "insert into" question
 
yep, the UPDATE statement was it. Thanks a lot!


All times are GMT -4. The time now is 4:10 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC