LoginSignup
10
10

More than 5 years have passed since last update.

FMDBを使ってデータを取り出すときのメモ

Posted at

随時追記していきたい、アプリ開発初心者の自分用メモ

//現在のレコード数を確認する

-(int)RecordCount{

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDirectry = paths[0];
    NSString *databaseFilePath = [documentDirectry stringByAppendingPathComponent:@"MYDataBaseFile.db"];    
    FMDatabase *database = [FMDatabase databaseWithPath:databaseFilePath];

    [database open];

    NSString *sql = @"SELECT COUNT(*) AS COUNT FROM MyTable;";
    //COUNT(*)で取り出した結果をCOUNTに入れる

    FMResultSet *results = [database executeQuery:sql];

    while([results next]){//必ず回す、そうしないと結果は0になる

        _dataCount = [results intForColumn:@"COUNT"];
    }

    [database close];

    return _dataCount;

}
10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10