Massive icon indicating copy to clipboard operation
Massive copied to clipboard

When the identity is a BIGINT

Open dyanarose opened this issue 8 years ago • 4 comments

Hi,

Looking at these two lines, it looks like the code assumes identities will be Int32s. So this would fail if instead, it's an Int64 for example.

https://github.com/FransBouma/Massive/blob/v2.0/src/Massive.Shared.cs#L1053 https://github.com/FransBouma/Massive/blob/v2.0/src/Massive.Shared.cs#L1066

dyanarose avatar Sep 07 '16 20:09 dyanarose

You're right!

Problem is though: there's no info to determine what the type should be, everything is dynamic... so I picked 'int' as in general that's a safe bet in this case... Any suggestions?

FransBouma avatar Sep 08 '16 15:09 FransBouma

For the case of MS SQL I know you can ignore the overflow values by using

SET ARITHABORT OFF; - MSDN SET ARITHIGNORE ON; - MSDN

In that case at least you can use Int64 and the downcast to Int32 identities should work. Helpful?

Siliconrob avatar Jan 29 '17 00:01 Siliconrob

Hmm. It smells like on error resume next however ;) Perhaps some other route to specify the type might be better... But haven't given it much thought

FransBouma avatar Jan 29 '17 09:01 FransBouma

Looking at the code at that date #L1053 #L1066 those two lines will not fail if the PK is a long which can fit into an int, only if the value is a long which can't fit.

Massive probably/possibly can't do better than this, as a cross-DB wrapper where most supported DBs work with ints.

But actually there was a line in that file #L785 which used an (int) cast instead of Convert.ToInt32(), to handle the result of COUNT, and that line failed with an exception (even for values which should fit into int) when ported to a DB which sent back a long count.

This is now fixed, or at least now follows the reasonable(?) pattern of the other two lines, as of https://github.com/FransBouma/Massive/commit/57073a937915f69ae060cc3e928ed097bfb100a8 for MySQL support. It will basically work for most users, if you really need long for PKs and COUNT values in your DB, you'd have to go in and edit these three lines.

mikebeaton avatar Mar 16 '17 18:03 mikebeaton