19 messages in com.mysql.lists.win32LOAD DATA INFILE Problem
FromSent OnAttachments
Addison, Darrick30 Apr 2001 12:32 
Jerry Lake30 Apr 2001 12:53 
Addison, Darrick01 May 2001 08:22.txt
Addison, Darrick02 May 2001 07:50.txt, .txt
Jerry Lake02 May 2001 09:14 
Addison, Darrick02 May 2001 09:25 
Addison, Darrick02 May 2001 09:34 
Stefan Schmiedl02 May 2001 09:35 
Addison, Darrick02 May 2001 09:36 
Addison, Darrick02 May 2001 11:38 
Stefan Schmiedl02 May 2001 11:50 
Jack van Luik02 May 2001 12:47 
Jack van Luik02 May 2001 12:53 
Addison, Darrick02 May 2001 13:17 
Addison, Darrick02 May 2001 13:27.txt
Addison, Darrick02 May 2001 13:28.txt
Addison, Darrick03 May 2001 05:33.txt
Larry Nobles03 May 2001 05:59 
Addison, Darrick03 May 2001 07:21 
Subject:LOAD DATA INFILE Problem
From:Addison, Darrick (Addi@atsgroup.saic.com)
Date:05/02/2001 07:50:03 AM
List:com.mysql.lists.win32
Attachments:

Jerry,

I moved the load.txt file to d:\mysql\data\UserProfile (which is the name of my database) and the load still doesn't work. However, if I executed the same command from the command prompt from the directory (d:\mysql\bin) with the load.txt file located in the same directory it seems to load the data file okay. In other words, using the equivalent command at the prompt works but when I use the mysql_query command from within C code it always fails. Any more suggestions on this. My guess is that the load.txt file is somehow not be located.

Take a look at the revised code: <<load.txt>>

/* The function parameters are getting passed in from another procedure */ int mysql_insert(MYSQL *conn, char *user_id, char *host_id, unsigned int Ppid, unsigned int Pid, double cputime, char *activity_code, double ctls, double cpusls, char *command, char *mode) {

FILE *mysql_load_file; char ip_addr[] = "149.8.6.103"; char datetime[] = "0000-00-00 00:00:00";

/* open mysql load file for writing */ if ((mysql_load_file = fopen("d:\\mysql\\data\\UserProfile\\load.txt","a+")) == NULL) // Doesn't seem to work using (d:\\mysql\\data\\UserProfile\\load.txt) either { printf("Couldn't open the bulk_load_file for writing\n"); exit(2); }

fprintf(mysql_load_file,"%s\t%s\t%lu\t%ld\t%s\t%s\n", user_id,host_id,Pid, Ppid, mode, command);

if (mysql_query(conn,"LOAD DATA LOCAL INFILE 'load.txt' INTO TABLE Process FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' ") != 0) { printf("LOAD DATA process failed\n");

}

else { printf("LOAD statement succeeded: %lu rows affected \n", (unsigned long) mysql_affected_rows (conn)); }

fprintf(mysql_load_file,"%s\t%s\t%s\t%s\n",user_id, host_id, ip_addr, datetime);

if (mysql_query(conn,"LOAD DATA LOCAL INFILE 'load.txt' INTO TABLE Session FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'") != 0) { printf("LOAD DATA process failed\n");

}

else { printf("LOAD statement succeeded: %lu rows affected \n", (unsigned long) mysql_affected_rows (conn)); }

fprintf(mysql_load_file,"%lu\t%ld\t%12.3f\t%12.3f\t%12.3f%\t%c\n", Pid, Ppid, cputime,(double)ctls,cpusls,activity_code);

if (mysql_query(conn,"LOAD DATA LOCAL INFILE 'load.txt' INTO TABLE Activity FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'") != 0) { printf("LOAD DATA process failed\n");

}

else { printf("LOAD statement succeeded: %lu rows affected \n", (unsigned long) mysql_affected_rows (conn)); }

return 0; }

Regards, Darrick Addison SAIC Software Engineer

-----Original Message----- From: Addison, Darrick Sent: Tuesday, May 01, 2001 11:23 AM To: 'win@lists.mysql.com' Cc: 'Jerry Lake' Subject: RE: LOAD DATA INFILE Problem

The load.txt file resides in d:\mysql\data which is where the database is installed and the load command still fails.

What's really weird about this is that when I booted my machine for the first time today and move the load.txt file to d:\mysql\data directory, it WORKED!!! However, the first line of my text file was getting inserted into one of my tables incorrectly (2 rows was getting updated instead of 1). And the last

line of load.txt was not getting inserted at all in another table. I have a total of three tables that are getting updated from the load.txt file (1 line per table respectively). Here is a segment of the C code that i'm using. The load.txt file is attached. Any suggestions:

<<load.txt>>

/* The function parameters are getting passed in from another procedure */ int mysql_insert(MYSQL *conn, char *user_id, char *host_id, unsigned int Ppid, unsigned int Pid, double cputime, char *activity_code, double ctls, double cpusls, char *command, char *mode) {

FILE *mysql_load_file; char ip_addr[] = "149.8.6.103"; char datetime[] = "0000-00-00 00:00:00";

/* open mysql load file for writing */ if ((mysql_load_file = fopen("d:\\mysql\\data\\load.txt","a+")) == NULL) { printf("Couldn't open the bulk_load_file for writing\n"); exit(2); }

fprintf(mysql_load_file,"%s\t%s\t%lu\t%ld\t%s\t%s\n", user_id,host_id,Pid, Ppid, mode, command);

if (mysql_query(conn,"LOAD DATA LOCAL INFILE 'load.txt' INTO TABLE Process") != 0) { printf("LOAD DATA process failed\n");

}

else { printf("LOAD statement succeeded: %lu rows affected \n", (unsigned long) mysql_affected_rows (conn)); }

fprintf(mysql_load_file,"%s\t%s\t%s\t%s\n",user_id, host_id, ip_addr, datetime);

if (mysql_query(conn,"LOAD DATA LOCAL INFILE 'load.txt' INTO TABLE Session") != 0) { printf("LOAD DATA process failed\n");

}

else { printf("LOAD statement succeeded: %lu rows affected \n", (unsigned long) mysql_affected_rows (conn)); }

fprintf(mysql_load_file,"%lu\t%ld\t%12.3f\t%12.3f\t%12.3f%\t%c\n", Pid, Ppid, cputime,(double)ctls,cpusls,activity_code);

if (mysql_query(conn,"LOAD DATA LOCAL INFILE 'load.txt' INTO TABLE Activity") != 0) { printf("LOAD DATA process failed\n");

}

else { printf("LOAD statement succeeded: %lu rows affected \n", (unsigned long) mysql_affected_rows (conn)); }

return 0; }

the load.txt file if just used as "load.txt" should be in whichever database you are using's folder in you mysql/data directory

-----Original Message----- From: Addison, Darrick [mailto:Addi@atsgroup.saic.com] Sent: Monday, April 30, 2001 12:32 PM To: 'win@lists.mysql.com' Subject: LOAD DATA INFILE Problem

Hello,

When I use the mysql_query command to send a SQL command (i.e. "LOAD DATA INFILE 'load.txt' INTO TABLE Process") using the C API the LOAD command always fails. The return_code is -1. However, if I execute the same command in from the command prompt the command seems to work successfully. Any suggestions? Does the load.txt file have to reside in a specific directory or this a permission problem. Any help will be glady appreicate.

Regards, Darrick Addison SAIC Software Engineer

To unsubscribe, send a message to the address shown in the List-Unsubscribe header of this message. If you cannot see it, e-mail win3@lists.mysql.com instead.