How can i fetch the data from sqlite as an integer in iphone technology. I have fetched the data as a string that code is mentioned below,now what have to chage in this code by which i can fetch the data as an integer. Please help me out.
如何在iphone技术中从sqlite获取数据作为整数。我已经将数据作为字符串获取,下面提到了代码,现在必须在这段代码中使用,我可以通过该代码获取整数数据。请帮帮我。
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);
}
}
1 个解决方案
#1
0
You could probably guess what you need to do given the function name sqlite3_column_text
...
考虑到函数名sqlite3_column_text,你可能猜到你需要做什么...
There is plenty of documentation on SQLite, but the direct answer to your question is use sqlite3_column_int
or sqlite3_column_int64
depending on the size of integer you need.
有关SQLite的大量文档,但您问题的直接答案是使用sqlite3_column_int或sqlite3_column_int64,具体取决于您需要的整数大小。
#1
0
You could probably guess what you need to do given the function name sqlite3_column_text
...
考虑到函数名sqlite3_column_text,你可能猜到你需要做什么...
There is plenty of documentation on SQLite, but the direct answer to your question is use sqlite3_column_int
or sqlite3_column_int64
depending on the size of integer you need.
有关SQLite的大量文档,但您问题的直接答案是使用sqlite3_column_int或sqlite3_column_int64,具体取决于您需要的整数大小。