#include <stdlib.h>
#include <stdio.h>

#include <mysql.h>
char *broken_q= 
"# Comment line 1 \
# Comment line 2\
CREATE TEMPORARY TABLE tmp_table \
( \
  id1 int unsigned not null, \
  id2 int unsigned not null, \
  KEY id1(id1), \
  KEY id2(id2) \
); \
 \
# this is the mapping. \
INSERT INTO tmp_table (id1, id2) VALUES  \
(1,2) \
; \
 \
# The actual query \
SELECT  \
* \
* FROM tmp_table t \
* ";


char *working_q=
" /* WORKING COMMENT */ \
CREATE TEMPORARY TABLE tmp_table \
( \
  id1 int unsigned not null, \
  id2 int unsigned not null, \
  KEY id1(id1), \
  KEY id2(id2) \
); \
 \
# this is the mapping. \
INSERT INTO tmp_table (id1, id2) VALUES  \
(1,2) \
; \
 \
# The actual query \
SELECT  \
* \
* FROM tmp_table t \
* ";

int main(int argc, char **argv) 
{
  MYSQL *mysql = NULL;

  mysql = mysql_init(mysql);

  if (!mysql) {
    puts("Init faild, out of memory?");
    return EXIT_FAILURE;
  }

  if (argc != 6) {
     printf("%d-%s host user password database port\n",argc,argv[0]);
     return EXIT_FAILURE;
  }

  printf("host:%s; user:%s; password:%s; database:%s; port:%s\n",argv[1],argv[2],argv[3],argv[4],argv[5]);
  if (!mysql_real_connect(mysql,       /* MYSQL structure to use */
			  argv[1],  /* server hostname or IP address */ 
			  argv[2],  /* mysql user */
			  argv[3],   /* password */
			  argv[4],    /* default database to use, NULL for none */
			  atoi(argv[5]),           /* port number, 0 for default */
			  NULL,        /* socket file or named pipe name */
			  CLIENT_FOUND_ROWS /* connection flags */ )) {
    printf("Connect fialed: %s\n", mysql_error(mysql));
  } else { 
     	mysql_query(mysql, "SET NAMES utf8");
  	mysql_set_server_option(mysql,MYSQL_OPTION_MULTI_STATEMENTS_ON);               
    if (mysql_query(mysql, broken_q)) {
      printf("Query failed: %s\n", mysql_error(mysql));
    }
    if (mysql_query(mysql, working_q)) {
      printf("Query failed: %s\n", mysql_error(mysql));
    }
  }
        
  mysql_close(mysql);

  return EXIT_SUCCESS;
}
