#1493·wcdb

Storing NSNumber as a double type may cause data loss when storing long long type.

Author: cntrumpCreated Oct 20, 2025Updated Oct 21, 2025
LabelsenhancementObjective-C

If I store data of type long long (such as 95811454522411188) into a WCDB database and then read and process it, I find that the data is different from before. By examining the source code, I discovered that long long is being stored as a double.

https://github.com/Tencent/wcdb/blob/9e497410dbdb65ac0f2c22cd5fd36959e374b360/src/objc/builtin/NSNumber%2BWCTColumnCoding.mm#L41

objc
#import "NSNumber+WCTColumnCoding.h"

@implementation NSNumber (WCTColumnCoding)

+ (instancetype)unarchiveWithWCTValue:(NSNumber *)value
{
    return value;
}

- (NSNumber *)archivedWCTValue
{
    return self;
}

+ (WCTColumnType)columnType
{
    return WCTColumnTypeFloat;
}

@end

It's best to explicitly specify whether the database field type is long long or double.