/* Copyright (C) 2014 Hartmut Holzgraefe This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #define MYSQL_HOST "127.0.0.1" #define MYSQL_DB "test" #define MYSQL_USER "root" #define MYSQL_PWD "" int main(int argc, char **argv) { MYSQL *mysql = NULL; int opt_local_infile = 1; int client_flags = 0; int stat; mysql = mysql_init(mysql); printf("before setting options:\n"); printf("mysql->client_flag : %lX\n", mysql->client_flag); printf("mysql->options.client_flag: %lX\n", mysql->options.client_flag); if (mysql->options.client_flag & CLIENT_LOCAL_FILES) { printf("WARNING: client library built with ENABLED_LOCAL_INFILE so test will never fail!\n"); printf("WARNING: make sure to use a build compiled with ENABLED_LOCAL_INFILE=OFF!\n"); } if (!mysql) { puts("Init faild, out of memory?"); return EXIT_FAILURE; } if (argc == 1) { puts("using mysql_options()"); mysql_options(mysql, MYSQL_OPT_LOCAL_INFILE, (char*) &opt_local_infile); } else { puts("using connect flag"); client_flags = CLIENT_LOCAL_FILES; } if (!mysql_real_connect(mysql, /* MYSQL structure to use */ MYSQL_HOST, /* server hostname or IP address */ MYSQL_USER, /* mysql user */ MYSQL_PWD, /* password */ MYSQL_DB, /* default database to use, NULL for none */ 0, /* port number, 0 for default */ NULL, /* socket file or named pipe name */ client_flags )) { fprintf(stderr, "Connect failed: %s\n", mysql_error(mysql)); exit(EXIT_FAILURE); } else { puts("Connect OK\n"); } printf("mysql->client_flag : %lX\n", mysql->client_flag); printf("mysql->options.client_flag: %lX\n", mysql->options.client_flag); stat = mysql_query(mysql, "DROP TABLE IF EXISTS t1"); if (stat) { fprintf(stderr, "DROP failed: %d %d %s\n", stat, mysql_errno(mysql), mysql_error(mysql)); exit(EXIT_FAILURE); } stat = mysql_query(mysql, "CREATE TABLE t1(id INT PRIMARY KEY, msg VARCHAR(100))"); if (stat) { fprintf(stderr, "CREATE failed: %d %d %s\n", stat, mysql_errno(mysql), mysql_error(mysql)); exit(EXIT_FAILURE); } stat = mysql_query(mysql, "LOAD DATA LOCAL INFILE 't1.csv' INTO TABLE test.t1"); if (stat) { fprintf(stderr, "LOAD failed: %d %d %s\n", stat, mysql_errno(mysql), mysql_error(mysql)); exit(EXIT_FAILURE); } printf("\ntest OK\n"); mysql_close(mysql); return EXIT_SUCCESS; }