Sqlite Error with Bool Values

I have a table with 3 Bool columns.

  • Invisible by default 1
  • AnsweredCorrect Default value 0
  • AnsweredWrong Default 0

Now all the invisible rows are 1, AnsweredCorrect 0 and AnsweredWrong 0. Now I want to count all 3 columns for their ON values. I ask

SELECT SUM(Unseen) as Unseen, SUM(AnsweredCorrect) as Correct, SUM(AnsweredWrong) as Wrong FROM table_name 

when I run this query in Sqlite browser, it returns

Invisible 20, Right 0, False 0

It is right. But when I use it in code, it returns all 0 values.

FMResultSet *query = [db executeQuery:[NSString stringWithFormat:@"SELECT SUM(Unseen) as Unseen, SUM(AnsweredCorrect) as Correct, SUM(AnsweredWrong) as Wrong FROM %@;",tableName]];

[counters addObject:[NSNumber numberWithInt:[query intForColumn:@"Unseen"]] ];
[counters addObject:[NSNumber numberWithInt:[query intForColumn:@"Correct"]] ];
[counters addObject:[NSNumber numberWithInt:[query intForColumn:@"Wrong"]] ];

I use FMDB for database operations. What's wrong?

Thanks for the help!

+4
source share
2 answers

This doesn't make much sense, so I would advise you to start with a check.

, .

, , , .

, , .

, sqlite, .

, SQL 1, 0, 0, SLQlite.

- SQLite, , , , , SQLite.

, , .

0

FMResultSet, FMDatabase. , -executeQuery:

, while(). "" ( [FMResultSet next]) .

, FMResultSet, "stepping".

Edit:

% @placeholder ? .

ExecuteQuery:

select

  • (FMResultSet *) executeQuery: (NSString *) sql,... sql SELECT, , ? .

... ? SQL . Objective-C (, NSString, NSNumber ..), C (, int, char *, .).

0

Source: https://habr.com/ru/post/1540861/


All Articles