Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Error checking

Error checking

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpquestionmysql
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gregarion
    wrote on last edited by
    #1

    Hey guys i am facing a problem in my sql statement. I am trying to check if there is such a value in the database.

    Code:

      string NewMovie = "ww";
    
      string queryText ;
    

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

      conn=mysql\_init(NULL);
    
     mysql\_real\_connect(conn,host,username,password,database,0,NULL,0);
    

    mysql_query(conn,queryText.c_str());

       ????
    
      mysql\_close(conn);
    
       
    
      return 0;
    

    The problem i am facing is how do i check if the value is found. I read up and found that a query will return a value of TRUE if the query is a success and a FAIL if there is an error. How do i call these values and then based the check on it?

    CPalliniC 1 Reply Last reply
    0
    • G gregarion

      Hey guys i am facing a problem in my sql statement. I am trying to check if there is such a value in the database.

      Code:

        string NewMovie = "ww";
      
        string queryText ;
      

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

        conn=mysql\_init(NULL);
      
       mysql\_real\_connect(conn,host,username,password,database,0,NULL,0);
      

      mysql_query(conn,queryText.c_str());

         ????
      
        mysql\_close(conn);
      
         
      
        return 0;
      

      The problem i am facing is how do i check if the value is found. I read up and found that a query will return a value of TRUE if the query is a success and a FAIL if there is an error. How do i call these values and then based the check on it?

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      I guess you'll get 0 (i.e. success) either if the record is found and if it is NOT found, because, technically, the query succeeded. Why don't you query instead for the record count (using the COUNT SQL function)? :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      G 1 Reply Last reply
      0
      • CPalliniC CPallini

        I guess you'll get 0 (i.e. success) either if the record is found and if it is NOT found, because, technically, the query succeeded. Why don't you query instead for the record count (using the COUNT SQL function)? :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        G Offline
        G Offline
        gregarion
        wrote on last edited by
        #3

        Yeap i tried smting like this...

        string NewTitle = "ww";
              string queryText ;
        

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

        if (mysql_query(conn,queryText.c_str()) )

        {

        }

        but im not too sure how to get the values out? like if it reads 1 table? how can i call it out?

        CPalliniC 1 Reply Last reply
        0
        • G gregarion

          Yeap i tried smting like this...

          string NewTitle = "ww";
                string queryText ;
          

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

          if (mysql_query(conn,queryText.c_str()) )

          {

          }

          but im not too sure how to get the values out? like if it reads 1 table? how can i call it out?

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          The query is OK. Now you've to fetch the data (actually the single value). An example here [^] (check out the "Retrieving data from the database" section). :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups