On 06/21/2011 07:22 AM, e-mail mgbg25171 wrote:
> The commented out lines work.
> I'm wondering...
> a) is it possible to do what's not commented out
> b) what's the syntax re the "sql =..." and "sql +=..." lines
> Any help much appreciated!
><snip> >
> sql = "BEGIN";   //you need to add newline here
> sql += "create table episodes (id integer primary key, season int, name
> text)";
> sql += "insert into episodes(id, season, name) Values(1,2,'bill')";
> sql += "insert into episodes(id, season, name) Values(2,3,'bob')";
> sql += "COMMIT";
> rc = sqlite3_prepare(db, sql.c_str(), strlen( sql.c_str() ),&stmt,&tail);
> rc = sqlite3_step(stmt);

You will need to add semicolons within the quotes between each statement 
as someone has already pointed out.

Secondly, prepare only prepares one statement, so you would have to loop 
through the statements. My C is rusty, but I think it is something like:

tail = sql.c_str();
while (tail)
{
   rc = sqlite3_prepare(db, tail, strlen(tail), &stmt, &tail);
   rc = sqlite3_step(stmt);
   rc = sqlite3_finalize(stmt);
}


Alternatively, you can run the combined multi statements through 
sqlite3_exec() in one shot.

David
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to