Clayton
Clayton

Reputation: 6271

Call mysql SOURCE command from a C program

I want to execute some mysql statements that are stored in a text file from my C program using the mysql.h library.

My inclination was to do something like the following, but this doesn't work:

mysql_query(conn, "source test.mysql");

This is because the SOURCE command is not a mysql statement in and of itself.

Is there a way call the SOURCE command programmatically and not from the command line?

Upvotes: 2

Views: 454

Answers (1)

Robert Gamble
Robert Gamble

Reputation: 109052

The source command is a built-in command in the mysql client program, it isn't a SQL command. Your best bet is to either call the mysql client program using the C system function (or an equivalent), or read the file text file yourself a command at a time and pass them to your query function.

Upvotes: 4

Related Questions