iphone
  • xcode
  • fmdb
  • 2013-10-25 90 views 0 likes 
    0

    下面是我使用的代碼:iPhone,FMDatabase:的executeQuery不工作

    FMDatabaseQueue *queue = [[DataBaseHelper sharedManager] queue]; 
    [queue inDatabase:^(FMDatabase *db) { 
    
    FMResultSet *results = [db executeQuery:@"select * from EVENT where ESTATUS='unread' and HIT_ATTEMPTS < 5 "]; 
    
    if([results next]) 
    { 
        [results close]; 
    
        @try { 
          BOOL success=FALSE; 
          NSString *query=[NSString stringWithFormat:@"insert into EVENT (EDATA, ESTATUS ,EUSER) values('%@','%@','%@')",@"google.com",@"unread",@"xyz"]; 
    
          success = [db executeUpdate:query]; 
          NSLog(@"create edata row, %d:%@", [db lastErrorCode], [db lastErrorMessage]); 
         } 
    
        @catch (NSException *exception) { 
         NSLog(@"Exception"); 
        } 
    

    在上面的代碼 成功= [分貝的executeUpdate:查詢];不管用。我試過放置斷點。這行代碼全部退出。沒有打印日誌。

    回答

    0

    我不知道爲什麼你使用try和catch,anywayz按照步驟必將工作

    創建數據庫

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *docsPath = [paths objectAtIndex:0]; 
    NSString *path = [docsPath stringByAppendingPathComponent:@"database.sqlite"]; 
    
    FMDatabase *database = [FMDatabase databaseWithPath:path]; 
    

    打開數據庫和創建表(可選)

    [database open]; 
    //optional 
    [database executeUpdate:@"create table user(name text primary key, age int)"]; 
    

    Queryin克將數據庫

    FMResultSet *results = [database executeQuery:@"select * from user"]; 
    while([results next]) { 
        NSString *name = [results stringForColumn:@"name"]; 
        NSInteger age = [results intForColumn:@"age"];   
        NSLog(@"User: %@ - %d",name, age); 
    } 
    [database close]; 
    
    +0

    利用了嘗試捕捉也相同問題仍然存在 – TechFanatic

    +0

    你試過最簡單的方式@TechFanatic,我剛纔提到? – Vizllx

    +0

    我試過了,但它沒有奏效 – TechFanatic

    相關問題