0

How do I get a meaningfull error message like "table 'table_that_does_not_exist' doesn't exists" for my following sample ?

    var sql = "select * from table_that_does_not_exist";
    var statement:COpaquePointer = nil

    if sqlite3_prepare_v2(db, sql, -1, &statement, nil) != SQLITE_OK {
        println("Failed to prepare statement");
        var result=sqlite3_errmsg(db);
        println(result);
        exit(1);
    }else{

My prinltn in this sample reports : "0x0000000102ee3380", which doesn't say something to me nor to google. (ok, when I don't know its not surprising :-) , but google)

UPDATE SOLUTION As CL. explained, this is C-pointer returned. So I have to get the message like :

let errmsg=String.fromCString(sqlite3_errmsg(db));

Thanks a lot to CL.

Kirsteins
  • 27,065
  • 8
  • 76
  • 78
mcfly soft
  • 11,289
  • 26
  • 98
  • 202
  • actually it is not my intention to solve my missing table issue (which is only a sample) :-). I just want an error message so I could figure out what is the problem. This is only a sample. In future I will have other problems (not like this simple sample of a missing table), and then I would like to get an error message from the db. – mcfly soft Aug 14 '15 at 08:26
  • possible duplicate of [Working with C strings in Swift, or: How to convert UnsafePointer to CString](http://stackoverflow.com/questions/24418955/working-with-c-strings-in-swift-or-how-to-convert-unsafepointercchar-to-cstr) – CL. Aug 14 '15 at 09:23
  • Thanks, but I see no relation to the mentoined question. This is something totally different. Or can you help me pointing out, how I can get the errormessage from the mentoined question ? – mcfly soft Aug 14 '15 at 09:25
  • `sqlite3_errmsg()` returns a C string. – CL. Aug 14 '15 at 09:42
  • Thanks a lot CL ! Now I got it. I updated the question with the solution. – mcfly soft Aug 14 '15 at 10:31

0 Answers0