"Fossies" - the Fresh Open Source Software Archive

Member "mariadb-connector-c-3.0.8-src/examples/mysql_debug.c" (18 Dec 2018, 947 Bytes) of package /linux/misc/mariadb-connector-c-3.0.8-src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include <mysql.h>
    2 #include <stdio.h>
    3 #include <string.h>
    4 #include <stdlib.h>
    5 
    6 void show_error(MYSQL *mysql)
    7 {
    8   printf("Error(%d) [%s] \"%s\"", mysql_errno(mysql),
    9                                   mysql_sqlstate(mysql),
   10                                   mysql_error(mysql));
   11   mysql_close(mysql);
   12   exit(-1);
   13 }
   14 
   15 int main(int argc, char *argv[])
   16 {
   17   MYSQL *mysql;
   18   const char *query;
   19 
   20   mysql_debug("d:t:O");
   21 
   22   mysql= mysql_init(NULL);
   23 
   24   if (!mysql_real_connect(mysql, "localhost", "example", "example_pw", 
   25                           "example_db", 0, "/tmp/mysql.sock", 0))
   26     show_error(mysql);
   27 
   28   query= "DROP TABLE IF EXISTS debug_example";
   29   if (mysql_real_query(mysql, query, strlen(query)))
   30     show_error(mysql);
   31  
   32   query= "CREATE TABLE debug_example (id int not null, my_name varchar(50),"
   33          "PRIMARY KEY(id))";
   34   if (mysql_real_query(mysql, query, strlen(query)))
   35     show_error(mysql);
   36 
   37   mysql_close(mysql);
   38 
   39   return 0;
   40 }