Skip to content

multiple statements fail - expected behavior? #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
samhatchett opened this issue Feb 23, 2017 · 2 comments
Closed

multiple statements fail - expected behavior? #99

samhatchett opened this issue Feb 23, 2017 · 2 comments

Comments

@samhatchett
Copy link

I've noticed that when feeding in multiple semicolon-delimited statements as part of a single string, only the first statement is actually executed. for example:

database db("test.db");
db << "create table 'data'('col' integer); create table 'meta'('col' integer);";
// only the first table is created

The practical use case here is executing a whole bunch of statements to setup the schema when creating a new db.

if I split the string on semicolons and feed each string in, everything works. If this is expected behavior, it should probably be documented - even though I notice the the usage idioms only show examples of single statements.

@zauguin
Copy link
Collaborator

zauguin commented Feb 23, 2017

Yes, this is expected behaviour. Documentation and errors should be added.

When you emulate this by splitting on semicolons take care, there might be semicolons in a single statement.
I do not think this is a good idea in general, but you can try code like this instead if you really need it. All results will be ignored, if something fails you can't easily trace which commands were executed.

@samhatchett
Copy link
Author

Thanks - that's very helpful. For initializing complex table schemas, looks like I'll be either splitting a string literal on semicolons or on line-breaks, making sure that the split delimiter is placed carefully - rather than hard-coding each create statement into the stream. Similarly for sql scripts for migrating versioned schema.

btw, I'm really liking this wrapper!

feel free to close, as i think the question has been answered - unless you need a reminder about documenting this feature.

zauguin added a commit to zauguin/sqlite_modern_cpp that referenced this issue Feb 24, 2017
zauguin added a commit to zauguin/sqlite_modern_cpp that referenced this issue Feb 24, 2017
zauguin added a commit to zauguin/sqlite_modern_cpp that referenced this issue Feb 24, 2017
zauguin added a commit to zauguin/sqlite_modern_cpp that referenced this issue Feb 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants