我的表格和行如下所示;
Table : Visit
Column : VisitDate
Value : 634993344000000000
VisitDate 列包含一个 Int64 值(例如 DateTime.Now.Ticks)
当我从数据库中读取此内容时,SQLite 无法检测列是否为 Int64 值。我的代码是;
switch (sqlite3_column_type(statement,i))
{
case SQLITE_INTEGER:
intValue = (int)sqlite3_column_int(statement, i);
colNameChar = (const char *)sqlite3_column_name(statement, i);
colName = [NSString stringWithCString:colNameChar encoding:NSUTF8StringEncoding];
colValue = [NSNumber numberWithInteger: intValue];
break;
case SQLITE_FLOAT:
dblValue = (double)sqlite3_column_double(statement, i);
colNameChar = (const char *)sqlite3_column_name(statement, i);
colName = [NSString stringWithCString:colNameChar encoding:NSUTF8StringEncoding];
colValue = [NSNumber numberWithDouble: dblValue];
break;
case SQLITE_TEXT:
strValue = (const char *)sqlite3_column_text(statement, i);
colNameChar = (const char *)sqlite3_column_name(statement, i);
colName = [NSString stringWithCString:colNameChar encoding:NSUTF8StringEncoding];
colValue = [NSString stringWithCString:strValue encoding:NSUTF8StringEncoding];
break;
case SQLITE_BLOB:
strValue = (const char *)sqlite3_column_value(statement, i);
colNameChar = (const char *)sqlite3_column_name(statement, i);
colName = [NSString stringWithCString:colNameChar encoding:NSUTF8StringEncoding];
colValue = [NSString stringWithCString:strValue encoding:NSUTF8StringEncoding];
break;
case SQLITE_NULL:
strValue = nil;
colNameChar = (const char *)sqlite3_column_name(statement, i);
colName = [NSString stringWithCString:colNameChar encoding:NSUTF8StringEncoding];
colValue = [[NSObject alloc] init];
break;
default:
strValue = (const char *)sqlite3_column_value(statement, i);
colNameChar = (const char *)sqlite3_column_name(statement, i);
colName = [NSString stringWithCString:colNameChar encoding:NSUTF8StringEncoding];
colValue = [NSString stringWithCString:strValue encoding:NSUTF8StringEncoding];
break;
}
调试器进入 SQLITE_INTEGER 的 case 并产生一个垃圾值(类似于 -2323423)。我怎样才能得到正确的价值?