Het antwoord is dat we de volgende regel code nodig hebben:
mysql_options( &mysql, MYSQL_OPT_LOCAL_INFILE, 0 );
ingevoegd tussen mysql_init()
en mysql_real_connect()
.
Hieronder vindt u een fragment van de C-code ter referentie. Merk op dat de mysql-backend van SOCI kan worden gepatcht met deze regel code om het te laten werken.
Getest en werkt op Mysql 5.5, gcc 4.7.2, Quantal.
#include <mysql.h>
#include <stdio.h>
main()
{
MYSQL mysql;
mysql_init( &mysql );
mysql_options( &mysql, MYSQL_OPT_LOCAL_INFILE, 0 );
if ( !mysql_real_connect( &mysql,"127.0.0.1","root","open_sasame","tmp_db",0,NULL,0 ))
{
fprintf(stderr, "Failed to connect to database: Error: %s\n",
mysql_error( &mysql ));
}
if ( mysql_query( &mysql, "LOAD DATA LOCAL INFILE '/tmp/junk4.txt' "
"INTO TABLE tmp_db.example_tbl FIELDS TERMINATED BY '|' "
"LINES TERMINATED BY '\\n'" ))
{
fprintf( stderr, "ERROR DURING LOAD DATA LOCAL INFILE\n" );
}
mysql_close( &mysql );
}