1

In a sqlite3 database, I've a table "data" with two fields: type and path. The field type is defined as INTEGER. In this field I insert a NSUInteger value (which will be for example 0 or 1). The problem is that, when I retrieve it, I obtain a "strange" value. I don't know where I'm wronging.

   if (init_statement == nil) {
        const char *sql = "SELECT type,path FROM data WHERE id=?";
        if (sqlite3_prepare_v2(database, sql, -1, &init_statement, NULL) != SQLITE_OK) {
            NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
        }
    }

    sqlite3_bind_int(init_statement, 1, primaryKey);

    if (sqlite3_step(init_statement) == SQLITE_ROW) {
     int type = (int)sqlite3_column_text(init_statement, 0);
     char *relPath = (char *)sqlite3_column_text(init_statement, 1);

    // other stuff
    } 

    // Reset the statement for future reuse.
    sqlite3_reset(init_statement);

1 Answer 1

1

SQLite allows only 64 bit signed integers. You are assigning it an unsigned integer. Change it to NSInteger instead.

Sign up to request clarification or add additional context in comments.

4 Comments

I change it to NSInteger. The right value is inserted, but when I retrieve it with the code above it's not so.
Why aren't you casting it back to NSInteger?
there is the same problem if I cast it. I'll do some other tests.
Why aren't you using sqlite3_column_int64?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.