Question about size_t and MySQL

I was looking at the old discussion in my CreatureHonor branch where I tried to create a checksum of the config to determine if it had changed. Simply adding the values isn’t sufficient so I thought about a hash:

std::hashstd::string()(myString);
// myString is the config values appended together, eg: 101005103045001

Unfortunately the return is a size_t and I haven’t been able to find any documentation on what field to use in MySQL to store this. Also, the core only offers specific types when saving / parsing a query:

stmt->setInt32()
stmt->setString()
stmt->setInt64()
…etc…
fields[0].GetUint32()
fields[0].GetString()
fields[0].GetUInt64()
…etc…

It’s my understanding that size_t is different depending on platform so wouldn’t saving it as a uint32 possibly cause loss of data?

trying to save platform dependent types (like size_t, time_t, ptrdiff_t) anywhere (disk, network, database) makes no sense, you have to cast it to whatever type can hold all the information for every platform you want to support.

It should be UInt64

trying to save platform dependent types (like size_t, time_t, ptrdiff_t) anywhere (disk, network, database) makes no sense, you have to cast it to whatever type can hold all the information for every platform you want to support.

​Indeed, I just wasn’t sure what to cast it as. I saved it as a uint32 which worked but visual studio gave me a warning about possible loss of data and I wasn’t sure if in my case I would ever hit that or not.

It should be UInt64

​Thanks! I tried to find what algorithm std::hash used (md5, sha, etc.) to get an idea of the size of the result but nobody seems to know. Also, boost has an implementation which also returns a size_t

In any case, the hash seems to give the result I want:

val1 = 1
val2 = 0
val3 = 1
val4 = 0
str = 1010

Adding all the vals = 2, hashing str is

val1 = 0
val2 = 1
val3 = 0
val4 = 1
str = 0101

Adding all the vals = 2 so it appears the config did not change. Hashing str is