#include <stdio.h> /* needed for vsnprintf */
#include <stdlib.h> /* needed for malloc-free */
#include <string.h>
#include <sqlite3.h>
char *table[10] = { "John", "peter", "Nolan" };
int i ;
for(i=0; i<3; i++)
{
char *sql1 = "ALTER TABLE names ADD column '%s'",table[i];
rc = sqlite3_exec(db, sql1, callback, 0, &zErrMsg);
if (rc != SQLITE_OK )
{
printf("Error: %s:Unable to ALTER the table\n", zErrMsg);
}
}
- In the above code to add '3' columns(such as John, Peter, Nolan) I re-run SQL statement for '3' times.
- Is it possible to add above '3' columns through a single SQL statement (or) any other API is available?
NOTE: I don't want to do the following things
- Using a loop statement to add the columns.
- Executing many SQL statements to add the columns.
- Backup of the existing database and renaming it after adding the columns.