2013-04-16 46 views
0

我是新手機programming.I存儲imagepath和audiopath數據庫。現在我想檢索imagepath表單數據庫我得到所有的圖像路徑,但我只想檢索3 imagepaths剩餘的東西,我想在其他地方使用。任何機構可以告訴我怎麼只能檢索到3 ImagePath的形式數據庫 下面的代碼從數據庫中檢索的ImagePath如何檢索只有3imagepaths或id從數據庫中的iPhone

 NSString *docsDir; 
       NSArray *dirPaths; 

       // Get the documents directory 
       dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

       docsDir = [dirPaths objectAtIndex:0]; 
       arrayy=[[NSMutableArray alloc]init]; 
       arrayy2=[[NSMutableArray alloc]init]; 
       arrayy1=[[NSMutableArray alloc]init]; 
       // array2=[[NSMutableArray alloc]init]; 


       // Build the path to the database file 
       databasePath = [docsDir stringByAppendingPathComponent: @"Taukydaataaa.db"]; 
       // NSLog(@"%@",databasePath); 
       NSFileManager *fn=[NSFileManager defaultManager]; 
       NSError *error; 
       BOOL success=[fn fileExistsAtPath:databasePath]; 

       if(!success) { 

        NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Taukydaataaa.db"]; 
        success = [fn copyItemAtPath:defaultDBPath toPath:databasePath error:&error]; 
       } 


       const char *dbpath = [databasePath UTF8String]; 

       sqlite3_stmt *statement; 

       if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK) 
       { 

    NSString *querySQL = [NSString stringWithFormat: @" select t.imagepath,t.audiopath,t.id from blauky b,taukyblauky tb,tauky t where tb.blaukyid=b.id and tb.taukyid=t.id and tb.blaukyid=1"]; 

        const char *query_stmt = [querySQL UTF8String]; 


        if (sqlite3_prepare_v2(contactDB, query_stmt, -1, &statement, NULL) == SQLITE_OK) 
        { 

         while(sqlite3_step(statement) == SQLITE_ROW) 
         { 

          email_idField = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement,2)]; 

          email_idField1 = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement,1)]; 
          email_idField2 = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement,0)]; 


          //  NSString *email_idField2 = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement,2)]; 
          NSLog(@"ASlma"); 
          NSLog(@"%@",email_idField); 

          NSLog(@"%@",email_idField1); 
          NSLog(@"%@",email_idField2); 
          [arrayy addObject:email_idField]; 
          [arrayy1 addObject:email_idField1]; 
          [arrayy2 addObject:email_idField2]; 
          NSLog(@"%@",arrayy); 
          NSLog(@"%@",arrayy1); 
          NSLog(@"%@",arrayy2); 
          NSLog(@"Iam here"); 

          } 
         } 
        } 
       } 

感謝 阿斯拉姆

回答

1

你可以添加LIMIT 3到您的查詢。

+0

感謝您給予重播其工作f9。 – Aslam

+0

@Aslam:正常工作意味着接受答案的費用。 – Ganapathy