db資料庫利用第三方架構進行提取和解析資料

來源:互聯網
上載者:User

標籤:firefox   github   架構   資料庫   sqlite   

db的資料包用從github上下載的三方架構進行解析和資料提取,格式一般為數組和字典。db的查看工具是firefox上的解析db外掛程式SQLite

三方架構為FMDB

#import "ViewController.h"//1. 引入標頭檔,需要引入libsqlite3的庫#import "FMDB.h"#import "Word.h"@interface ViewController ()            @end@implementation ViewController            - (void)viewDidLoad {    [super viewDidLoad];        //2. 建立一個FMDatabase對象,並指定檔案路徑    FMDatabase *database = [FMDatabase databaseWithPath:@"/Users/apple/Desktop/japanese.db"];    //3. 開啟檔案    if (![database open]) {        NSLog(@"Can not open file");        return;    }        //4. 執行查詢    FMResultSet *result = [database executeQuery:@"SELECT * FROM jp"];        NSMutableArray *array = [NSMutableArray array];    //5. 擷取表格中的一行    while ([result next]) {//        NSMutableDictionary *dict = [NSMutableDictionary dictionary];                Word *word = [[Word alloc] init];                //根據名字(列名)擷取資料        int rid = [result intForColumn:@"id"];        NSLog(@"rid: %d", rid);                word.rid = rid;        //        [dict setObject:[NSNumber numberWithInt:rid] forKey:@"id"];                //根據位置擷取資料        int rid1 = [result intForColumnIndex:0];        NSLog(@"rid1: %d", rid1);                NSString *kana = [result stringForColumn:@"kana"];        NSLog(@"kana: %@", kana);        //        [dict setObject:kana forKey:@"kana"];                NSString *kana1 = [result stringForColumnIndex:5];        NSLog(@"kana1: %@", kana1);                word.kana = kana1;                [array addObject:word];    }        //6. 關閉檔案    [database close];        NSLog(@"-----------");    NSLog(@"%@", array);}



這是word.h和word.m中的代碼

#import <Foundation/Foundation.h>@interface Word : NSObject@property (nonatomic, assign) NSInteger rid;@property (nonatomic, copy) NSString *kana;@end

#import "Word.h"@implementation Word- (NSString *)description{    return [NSString stringWithFormat:@"%@: rid: %d---kana: %@", [super description], _rid, _kana];}@end


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.