2010-06-17 44 views
1

如何从iPhone获取数据作为iphone技术中的整数。 我已经提取了数据作为字符串,代码在下面提到,现在什么 必须chage在这个代码中,我可以通过它获取数据作为一个整数。 请帮我一把。使用iPhone从sqlite获取数据作为整数使用iPhone

databaseName = @"KNAJ.sqlite"; 

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDir = [documentPaths objectAtIndex:0]; 
databasePath =[documentsDir stringByAppendingPathComponent:databaseName]; 

[self checkAndCreateDatabase]; 

list1 = [[NSMutableArray alloc] init]; 

sqlite3 *database; 
if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) 
{ 
    if(detailStmt == nil) 
    { 
     ///const char *sql = "Select * from Purch1 "; 

     // const char *sql = "select item from purchase order by item desc limit 1 "; 


     const char *sql = "select * from product2";   

     if(sqlite3_prepare_v2(database, sql, -1, &detailStmt, NULL) == SQLITE_OK) 
     {    
      //NSLog(@"Hiiiiiii"); 
      //sqlite3_bind_text(detailStmt, 1, [t1 UTF8String], -1, SQLITE_TRANSIENT); 
      //sqlite3_bind_text(detailStmt, 2, [t2 UTF8String], -2, SQLITE_TRANSIENT); 
      //sqlite3_bind_int(detailStmt, 3, t3); 

      while(sqlite3_step(detailStmt) == SQLITE_ROW) 
      { 
       //NSLog(@"Helllloooooo"); 












       //NSString *item= [NSString stringWithUTF8String:(char *)sqlite3_column_text(detailStmt, 0)]; 


       NSString *item= [NSString stringWithUTF8String:(char *)sqlite3_column_text(detailStmt, 0)]; 


       char *str=(char*)sqlite3_column_text(detailStmt, 0); 

       if(str) 
       { 
        item = [ NSString stringWithUTF8String:str ]; 

       } 

       else 
       { 
        item= @""; 
       } 







       //+ (NSString*)stringWithCharsIfNotNull: (char*)item 
       /// { 
       // if (item == NULL) 
       // return nil; 
       //else 
       // return [[NSString stringWithUTF8String: item] 
       //stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]; 
       //}     









       //NSString *fame= [NSString stringWithUTF8String:(char *)sqlite3_column_text(detailStmt, 1)]; 
       //NSString *cinemax = [NSString stringWithUTF8String:(char *)sqlite3_column_text(detailStmt, 2)]; 
       //NSString *big= [NSString stringWithUTF8String:(char *)sqlite3_column_text(detailStmt, 3)]; 

       //pvr1 = pvr; 
       item1=item; 
       //NSLog(@"%@",item1); 

       data = [[NSMutableArray alloc] init]; 


       list *animal=[[list alloc] initWithName:item1]; 

       // Add the animal object to the animals Array 
       [list1 addObject:animal]; 
       //[list1 addObject:item]; 
       NSLog(@"%@",item1);     
      } 
      sqlite3_reset(detailStmt); 
     } 
     sqlite3_finalize(detailStmt); 
     // sqlite3_clear_bindings(detailStmt); 
    } 
} 
detailStmt = nil; 
sqlite3_close(database); 

}

回答

0

你也许猜到你需要做的给定函数名sqlite3_column_text什么...

有足够的documentation on SQLite,而是直接回答你的问题是使用sqlite3_column_intsqlite3_column_int64取决于你需要的整数大小。

相关问题