views:

26

answers:

1

i m using sqlite

i am geting a return value frmo DB in this manner

"returnCount = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,0)];"

but the returend value is an integer value. how can i get a int value instead of paasing it in string...like this thing here "[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,0)];"

is for string, is there any way to get it in "integer" right away, otherwise i need to cast it.

suggestions please.

+1  A: 

The simplest answer, since it seems you know it's going to be an integer count, read it as an int with sqlite3_column_int().

That said, you may want to refactor your code after you drop in FMDB. FMDB will do the conversion for you when pulling data from integer or float columns. In your case, the result of a SELECT count(*) FROM myTable... would be a a single column of type integer and the [resultSet valueForkey:@"count"] will be an NSNumber as expected.

John Franklin
@John..."sqlite3_column_int()." dat worked for me...thanks a ton man
shishir.bobby
To be fair, the simplest way is to just use Core Data. ;)
bbum
@bbum, Yes, Core Data rocks, but that wasn't the question.
John Franklin
Sometimes there is an an answer and a meta-answer. The meta-answer is for folks new to the platform and/or new to SQLite to stop wasting their time and just use Core Data. It will require less engineering effort over the lifetime of a project. There are legitimate reasons not to, but they are pretty few and far between.
bbum