Do you know why do I get “Library Routine Called Out Of Sequence” when I call `sqlite3_prepare_v2(CREATE TABLE)` on an empty database?

I create an empty database and then open it. Later I save all information that has to be written to the database in RAM (I need to save that information in RAM and flush it to permanent storage at the end of execution), but I get this error message when I call `sqlite3_prepare_v2(CREATE TABLE)`. It returns “Library Routine Called Out Of Sequence” as an error message. 

I do open my database correctly and (I thought that it can be a problem so I did `close()` my DB and then `open()` right before calling `sqlite3_prepare_v2(CREATE TABLE)`). I thought it could be because of thread concurrency, but using critical section didn't help too.