string NewMovie = "ww";      
          string queryText ;

          queryText = "INSERT INTO movie_info (movie_title ) VALUES('" + NewMovie + "')" ;

MYSQL *conn;





return 0;

What i would like to know is how am i able to do a check to see if such a movie title already exist?

7 Years
Discussion Span
Last Post by Fbody

Perform a select query to look up the movie. If a record is returned, it already exists. Once you know if the record exists, or not, you can then either report an error condition or perform the insert.

Edited by Fbody: Corrected statement ordering


yeah, i did try to use SELECT but the problem i faced is how the error statement would look like.

For example

string NewTitle = "ww";
          string queryText ;

 queryText = "Select * from movie_info WHERE movie_title = '"+ NewTitle +"'";


if ??

that is the part im not sure of. Does the statement return a value of 1 or 0 when it is executed and smting is found?


Check your library's documentation for specific information. It should return some sort of success/fail value.

DISCLAIMER: The information contained below is based on my experience with the mysql library in PHP, YMMV.

In PHP, there are a couple exceptions, but in general mysql_query() returns FALSE on an error and TRUE on a success. With the success value alone, you can not determine if you have an empty result set or not. Even an empty result set is still technically a success. Since it's a library, I suspect it will be the same in C++.

You will have to carry your algorithm through to the next step, which is extracting the rows. If when you try to extract a row, you get an empty result (a FALSE return), you release the query and begin your insert routine. If you successfully extract a row, you return an error to the user and abort the insert.

Edited by Fbody: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.