Make the MySQL example code snippet compile.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 18 Dec 2017 18:53:57 +0000 (19:53 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 18 Dec 2017 18:53:57 +0000 (19:53 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
TD5/C/Makefile
TD5/C/exemple_mysql_libmysqlclient.c

index b5cebf81558469c92eedcb80417194475af6210a..04569c35340bc837579141ec54b5001a1b00b797 100644 (file)
@@ -14,6 +14,8 @@
 BINARY_NAME=infovols
 BUILD_TYPE=debug
 #BUILD_TYPE=release
 BINARY_NAME=infovols
 BUILD_TYPE=debug
 #BUILD_TYPE=release
+LDLIBS=-lmysqlclient
+INCLUDES=-I/usr/include/mysql
 
 # ====================================
 # DO NOT CHANGE STUFF BEYOND THIS LINE
 
 # ====================================
 # DO NOT CHANGE STUFF BEYOND THIS LINE
@@ -41,7 +43,7 @@ STRIP_FLAG = -s
 OPTI_FLAG = -O3
 endif
 
 OPTI_FLAG = -O3
 endif
 
-CFLAGS := -DDEBUG=$(DEBUG) $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG)
+CFLAGS := -DDEBUG=$(DEBUG) $(INCLUDES) $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG)
 LDFLAGS := $(LDFLAGS) $(STRIP_FLAG)
 
 OBJDIR := $(BUILDDIR)/objs
 LDFLAGS := $(LDFLAGS) $(STRIP_FLAG)
 
 OBJDIR := $(BUILDDIR)/objs
index 88e82da3ebf47e1077b8f9ad2685d1c924a0b4e2..9f26acc586ba1eb3c50a1530eaf2632ac3740048 100644 (file)
 //execution :
 //./testsqlc
 
 //execution :
 //./testsqlc
 
-
-int main(void) {
-      MYSQL *conn;
-      MYSQL_RES *res;
-      MYSQL_ROW row;
-      MYSQL_RES *result;
-
-      char *server = "";
-      char *user = "";
-      char *password = "";
-      char *database = "";
-
-      conn = mysql_init(NULL);
-
-      /* Connect to database */
-      if (!mysql_real_connect(conn, server,
-            user, password, database, 0, NULL, 0)) {
-          fprintf(stderr, "%s\n", mysql_error(conn));
-          exit(1);
-      }
-
-      /* send SQL query */
-      if (mysql_query(conn, "show tables")) {
-          fprintf(stderr, "%s\n", mysql_error(conn));
-          exit(1);
-      }
-
-      res = mysql_use_result(conn);
-
-      /* output table name */
-      printf("MySQL Tables in mysql database:\n");
-      while ((row = mysql_fetch_row(res)) != NULL)
-          printf("%s \n", row[0]);
-
-      /* query */
-      if (mysql_query(conn, "SELECT * FROM Usine")) 
-      {
-          fprintf(stderr, "%s\n", mysql_error(conn));
-          exit(1);
-      }
-  
-      result = mysql_store_result(conn);
-  
-      if (result == NULL) 
-      {
-          fprintf(stderr, "%s\n", mysql_error(conn));
-          exit(1);
-      }
-
-      int num_fields = mysql_num_fields(result);
-      int i;
-
-      printf("\nTable Usine :\n");
-      printf("NU\tNomU\tVille\n");
-
-      while ((row = mysql_fetch_row(result))) 
-      { 
-          for(i = 0; i < num_fields; i++) 
-          { 
-            printf("%s\t", row[i] ? row[i] : "NULL"); 
-          } 
-          printf("\n"); 
-      }
-
-      /* close connection */
-      mysql_free_result(res);
-      mysql_close(conn);
-
-      return 0;
+int main(void)
+{
+       MYSQL *conn;
+       MYSQL_RES *res;
+       MYSQL_ROW row;
+       MYSQL_RES *result;
+
+       char *server = "";
+       char *user = "";
+       char *password = "";
+       char *database = "";
+
+       conn = mysql_init(NULL);
+
+       /* Connect to database */
+       if (!mysql_real_connect(conn, server,
+                               user, password, database, 0, NULL, 0)) {
+               fprintf(stderr, "%s\n", mysql_error(conn));
+               exit(1);
+       }
+
+       /* send SQL query */
+       if (mysql_query(conn, "show tables")) {
+               fprintf(stderr, "%s\n", mysql_error(conn));
+               exit(1);
+       }
+
+       res = mysql_use_result(conn);
+
+       /* output table name */
+       printf("MySQL Tables in mysql database:\n");
+       while ((row = mysql_fetch_row(res)) != NULL)
+               printf("%s \n", row[0]);
+
+       /* query */
+       if (mysql_query(conn, "SELECT * FROM Usine")) {
+               fprintf(stderr, "%s\n", mysql_error(conn));
+               exit(1);
+       }
+
+       result = mysql_store_result(conn);
+
+       if (result == NULL) {
+               fprintf(stderr, "%s\n", mysql_error(conn));
+               exit(1);
+       }
+
+       int num_fields = mysql_num_fields(result);
+       int i;
+
+       printf("\nTable Usine :\n");
+       printf("NU\tNomU\tVille\n");
+
+       while ((row = mysql_fetch_row(result))) {
+               for (i = 0; i < num_fields; i++) {
+                       printf("%s\t", row[i] ? row[i] : "NULL");
+               }
+               printf("\n");
+       }
+
+       /* close connection */
+       mysql_free_result(res);
+       mysql_close(conn);
+
+       return 0;
 }
 }
-