0

Im trying to call my str date variable in this function:

int main(int argc, char **argv)
{ 
  int status = 0;   
  char query[300], data[15], hora[10];
  strDataHora(data, hora);
  printf("Date: %s\n", data);
  MYSQL *con = mysql_init(NULL);  

  if (con == NULL)
  {
      fprintf(stderr, "mysql_init() failed\n");
      exit(1);
  }  

 if (mysql_real_connect(con, "localhost", "root", "ufmg3duc", 
         "stream_net", 0, NULL, CLIENT_MULTI_STATEMENTS) == NULL) 
  {
      finish_with_error(con);
  }    

 if (mysql_query(con, "SELECT Id FROM audiencia WHERE data LIKE ('%s') AND (hora LIKE ('%:00:%') OR hora LIKE ('%:30:%')) AND hora > '03:01'",data))

  {
      finish_with_error(con);
  }

But I dont know how to call 'date' in mysql_query:

 if (mysql_query(con, "SELECT Id FROM audiencia WHERE data LIKE ('%s') AND (hora LIKE ('%:00:%') OR hora LIKE ('%:30:%')) AND hora > '03:01'",data))

How can i select Id when my actual date is a str variable type?

1
  • You might like to have look at the snprintf() function. Commented Nov 6, 2013 at 12:59

1 Answer 1

1

You have to store this query in a variable (eg. with sprintf or snprintf) and escape all those %using %%

char query[300];
...
sprintf(query, "SELECT Id FROM audiencia WHERE data LIKE ('%s') ...", data);
mysql_query(con, query);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.