I’m new to Xcode and trying to learning myself, my problem may be naive but I really need helps.
I’m learning creating an ebook by learning from a finished project with source code.
It works perfectly about recording bookmark through sqlite3.
But when I create a new project with different name and path, built pharse of libsqlite3.dylib correctly and copied almost everything of the code, the else statement is called and crashes when I’m trying to visit bookmark window.
Here’s some question I asked myself,
- did I miss anything, or failed on changing names or paths? answered: no.
- as the one runs perfectly and the other one with almost same code crashes, what’s the most possible mistake? answered: the very few differences from these two project,etc path, name, content in file.
Then I changed the database file name of the good project, and it becomes crashing.
I couldn’t believe, because I heard that sqlite3_open([dbPath UTF8String], &dataBase); will create file if it doesn’t exist, why won’t it just create a new file with the new name after it was told to access the new file?
Second test I did is manually changing the db file path of the new project to the db file path of the original one. like the path is no more [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; but it is @”/Users/~(path of the original one)~/Documents/archive” and omg it works.
But of course I can’t leave it like that cause that path means nothing on a real iPhone and it still depends the db file of the original one.
At least I know the path really matters and I seems really missing some thing like db file in my new project.
But the thing is I didn’t find any db file in the path of the original project, it seems exist and important, but doesn’t show in finder.
I even tried to copy the file to my new path programmaticlly, like calling [self createEditableCopyOfDatabaseIfNeeded]; with the new and the old path.
That’s all I tried so far.
The strange thing is it somehow record font and color after an unknown attempt, but still crashes on going to bookmark window.
That’s all I tried in three days. It may help you answer the question or at least know how I was upset after thousands attempts.
Waiting for help and thank you very much!
const char *createSQL = “CREATE TABLE IF NOT EXISTS BOOKMARK(pos REAL PRIMARY KEY,\fontsize REAL,\bookpath TEXT)”;
newly added: As the program automatically issue the crash when the database is not prepared, the error meg, as someone said, is useless. All I need is maybe making sqlite3_prepare(dataBase, [querySQL UTF8String], -1, &statement, nil) == SQLITE_OK not false..
The SQL you’re using to create the table in the new DB appears to be messed up. Try removing the \’s
Try this instead:
Additionally you should take a look at what
sqlite3_prepareactually returns. The SQLite documentation gives a list of error codes to check against. An example of logging the error code: