2013-04-16 47 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