2016-04-06 9 views
0

私のアプリでsqliteデータベースを使用しています。私はCURD操作をしています。私はjsonからデータを取得してから配列にデータを変換します。データをsqliteデータベースに挿入します。 1000レコード以上。データベースが完成したら、私はメモリ警告を取得します。メモリsqliteデータベースiOSでの問題?

私はデータは、その後、他のデータを更新し、新しいレコードを挿入存在する場合data.Itは、まずチェック挿入するための一つの機能を持っている

[[DBManager getSharedInstance]insertData:object]。

関数定義 -

(BOOL) insertData:(SubComponent *)subcomponent 
{ 


    const char *dbpath = [databasePath UTF8String]; 
    if([self getSubComponentDataBySubclientClientInspectionid:subcomponent.componentid : subcomponent.componentsubclientid:subcomponent.componentClientid : subcomponent.componentinspectionid] != nil) 
    { 

     [self updateCompSubComponentDataBySubclientId:subcomponent]; 
     return YES; 
    } 
    else 
    { 
     if (sqlite3_open(dbpath, &database) == SQLITE_OK) 
     { 

      if (sqlite3_exec(database, [@"PRAGMA CACHE_SIZE=500000;" UTF8String], NULL, NULL, NULL) == SQLITE_OK) { 
       NSLog(@"Successfully changed cache size"); 
      } 
      else 
       NSLog(@"Error: failed to set cache size with message %s.", sqlite3_errmsg(database)); 
      NSLog(@"inside isnert query"); 
      NSString *insertSQL = [NSString stringWithFormat: 
            @"insert into subcomponent(subcomponentid,name,createddate,subclientid,clientid,cliententityid, inspectionid, initialstatus,componentclientname,componentsubclientname, checkedstatus) values (\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%ld\",\"%@\",\"%@\",\"2\")",subcomponent.componentid,subcomponent.componentName,subcomponent.componentcreateddate,subcomponent.componentsubclientid,subcomponent.componentClientid, subcomponent.componentEntityid,subcomponent.componentinspectionid,(long)subcomponent.componentStatus,subcomponent.componentClientName,subcomponent.componentSubclientName]; 
      NSLog(@"%@",insertSQL); 
      const char *insert_stmt = [insertSQL UTF8String]; 
      sqlite3_prepare_v2(database, insert_stmt,-1, &statement, NULL); 
      if (sqlite3_step(statement) == SQLITE_DONE) 
      { 

       sqlite3_finalize(statement); 
       return YES; 
      } 
      else 
      { 
       NSLog(@"REMASH DB ERROR %s",sqlite3_errmsg(database)); 
       // sqlite3_reset(statement); 
       //sqlite3_close(database); 
       sqlite3_finalize(statement); 
       return NO; 
      } 
     } 
     sqlite3_close(database); 
    } 
    return YES; 
} 

GETデータFUNCTION

- (SubComponent*) getSubComponentDataBySubclientClientInspectionid:(NSString*)componentid : (NSString *)subclientid : (NSString *)clientId : (NSString *)inspectionid 
{ 
    const char *dbpath = [databasePath UTF8String]; 
    if (sqlite3_open(dbpath, &database) == SQLITE_OK) 
    { 
     NSString *querySQL = [NSString stringWithFormat:@"select * from subcomponent where subcomponentid = \"%@\" and subclientid = \"%@\" and clientid = \"%@\" and inspectionid = \"%@\"",componentid,subclientid, clientId,inspectionid]; 
     NSLog(@"gghgh query is %@",querySQL); 
     const char *query_stmt = [querySQL UTF8String]; 
     SubComponent *resultArray = [[SubComponent alloc]init]; 
     if (sqlite3_prepare_v2(database,query_stmt, -1, &statement, NULL) == SQLITE_OK) 
     { 
      if (sqlite3_step(statement) == SQLITE_ROW) 
      { 
       NSString *component_id = [[NSString alloc] initWithUTF8String: 
              (const char *) sqlite3_column_text(statement, 0)]; 
       resultArray.componentid = component_id; 
       NSString *name = [[NSString alloc] initWithUTF8String: 
            (const char *) sqlite3_column_text(statement, 1)]; 
       resultArray.componentName = name; 
       NSString *createddate = [[NSString alloc] initWithUTF8String: 
             (const char *) sqlite3_column_text(statement, 2)]; 
       resultArray.componentcreateddate = createddate; 
       NSString *subclientid = [[NSString alloc] initWithUTF8String: 
             (const char *) sqlite3_column_text(statement, 3)]; 
       resultArray.componentsubclientid = subclientid; 
       NSString *clientid = [[NSString alloc] initWithUTF8String: 
             (const char *) sqlite3_column_text(statement, 4)]; 
       resultArray.componentClientid = clientid; 
       NSString *entityid = [[NSString alloc] initWithUTF8String: 
             (const char *) sqlite3_column_text(statement, 5)]; 
       resultArray.componentEntityid = entityid; 
       NSString *inspectionid = [[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 6)]; 
       resultArray.componentinspectionid = inspectionid; 
       NSString *clientName = [[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 8)]; 
       resultArray.componentClientName = clientName; 
       NSString *subclientName = [[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 9)]; 
       resultArray.componentSubclientName = subclientName; 
//    sqlite3_finalize(statement); 
//    sqlite3_close(database); 
       return resultArray; 
      } 
      else 
      { 


//    sqlite3_finalize(statement); 
//    sqlite3_close(database); 
       return nil; 
      } 
     } 
     else 
     { 
      NSLog(@"error is %s",sqlite3_errmsg(database)); 
     } 
    } 
    // sqlite3_reset(statement); 
    // sqlite3_finalize(statement); 
    sqlite3_close(database); 

    return nil; 
} 

更新機能

-(void)updateCompSubComponentDataBySubclientId:(SubComponent *)subcomponent 
{ 
    NSLog(@"inside update data"); 
    const char *dbpath = [databasePath UTF8String]; 
    if (sqlite3_open(dbpath, &database) == SQLITE_OK) 
    { 


      if (sqlite3_exec(database, [@"PRAGMA CACHE_SIZE=500000;" UTF8String], NULL, NULL, NULL) == SQLITE_OK) { 
       NSLog(@"Successfully changed cache size"); 
      } 
      else 
       NSLog(@"Error: failed to set cache size with message %s.", sqlite3_errmsg(database)); 



     NSString *querySql=[NSString stringWithFormat: 
          @"UPDATE subcomponent SET name=\"%@\", createddate=\"%@\", cliententityid =\"%@\",componentclientname=\"%@\", componentsubclientname = \"%@\", checkedstatus = \"2\" where subcomponentid = \"%@\" and subclientid = \"%@\" and clientid = \"%@\" and inspectionid =\"%@\"",subcomponent.componentName,subcomponent.componentcreateddate, subcomponent.componentEntityid,subcomponent.componentClientName,subcomponent.componentSubclientName,subcomponent.componentid, subcomponent.componentsubclientid,subcomponent.componentClientid,subcomponent.componentinspectionid]; 
     const char *sql=[querySql UTF8String]; 
     if(sqlite3_prepare_v2(database,sql, -1, &statement, NULL) == SQLITE_OK) 
     { 
      if(SQLITE_DONE != sqlite3_step(statement)) 
      { 
       NSLog(@"REMASH Error while updating. '%s'", sqlite3_errmsg(database)); 
      } 
      else 
      { 
       //sqlite3_reset(statement); 
       NSLog(@"Update done successfully!"); 
      } 
     } 

     NSLog(@"NOT OK"); 
     sqlite3_finalize(statement); 
     sqlite3_close(database); 
    } 


} 

PS:誰かが私のコードを見てsqlite_finilaize()、sqlite_close()。sqlite_reset()が正しいかどうかを提案できますか?メモリが増えています。

+0

質問を再投稿しないでください。 – rmaddy

答えて

-2

これはデータベースの問題ではありません。

この問題は、アプリケーションに実行しようとしているデバイス用のストーリーボードがないために発生します。

XCode no valid compiled storyboard at path

+0

これはストーリーボードの問題ではありません。なぜなら、データがlesss.checkの同じリンクをここで再度取得しないからです。http://stackoverflow.com/questions/29563618/xcode-no-valid-compiled-storyboard-at-path/31965597#31965597 – TechGuy

+0

"有効なコンパイル済みのストーリーボードがパスにないようです"エラーは明らかにDBとは関係ありません..... – iSaalis

+0

私が最初に投稿したリンクをご覧ください。この場合、メモリ警告が表示されます。 – TechGuy

関連する問題