2010-06-17 47 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取決於你需要的整數大小。

相關問題