I'm writing some C code using the MySQL api to create databases, insert, update etc. I'm having a little trouble finding the cleanest/correct way to build the queries since the MySQL syntax can be tricky to put in a c string, for example, I'd like a query to look like this for readability:
strcpy(query, "CREATE TABLE Users (
userID INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (userID),
email VARCHAR(31) NOT NULL,
timeEntered TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
address VARCHAR(31) NOT NULL,
index (email))
");
then of course I'd be running the query with something like
/* send SQL query */
if (mysql_query(conn, query)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
} else { printf("table created\n"); }
however the compiler complains about expected ‘)’ and missing terminating " etc. Whats the best solution?