Closed rentalhost closed 1 month ago
@rentalhost is attempting to deploy a commit to the Mediaload Team on Vercel.
A member of the Team first needs to authorize it.
This approach has several short-coming
TextCell
to BigNumberCell
.I believe you are in the right track, just need a few twist:
if (
header.dataType === TableColumnDataType.INTEGER &&
databaseDriver.supportBigInt() &&
isBigNumber(value)
) {
// BigNumberCell
} else if ((
header.dataType === TableColumnDataType.INTEGER ||
header.dataType === TableColumnDataType.REAL
) && isNumber(value)) {
// NumberCell
} else if (
header.dataType === TableColumnDataType.TEXT &&
isString(value)
) {
// TextCell
} else {
// GenericCell
}
function isBigNumber(value) {
if (typeof value === 'bigint') return true;
if (value === null) return true;
if (value === undefined) return true;
try {
BigInt(value);
return true;
} catch {
return false;
}
}
function isNumber(value) {
if (typeof value === 'number') return true;
if (value === null) return true;
if (value === undefined) return true;
return Number.isFinite(value);
}
function isString(value) {
if (typeof value === 'string') return true;
if (value === null) return true;
if (value === undefined) return true;
return false;
}
Perfect!
I tried to compare as much as I could between the current version and the proposed one, always aiming to keep the current behavior intact while only modifying the issue with NULL
where it shouldn’t appear. So here are a few points:
BLOB
field can never be edited, so even if it's NULL
, it also cannot be modified. However, my implementation overlooked this when the field was NULL
for a non-BLOB
field. This is fixed in the latest commit I just made. This happened because the determineCellType()
function was checking for object
(which is the typeof
for null
) and ended up treating it as BLOB
instead of returning undefined
and using the column type instead. I had initially used Array.isArray()
, but I switched to a simpler check and incorrectly ignored the typeof
for null
.TextCell
to BigNumberCell
.
Essa tradução mantém a clareza e o contexto técnico do original.
Regarding the last point, just to be sure I understood correctly: you were making a statement, not asking a question, right? If it’s a question, SQLite will automatically convert a value that looks like a number to an INTEGER when it's received in an INTEGER field, rather than keeping it as the wrong type, TEXT, if that’s the case.
Regarding the last point, just to be sure I understood correctly: you were making a statement, not asking a question, right? If it’s a question, SQLite will automatically convert a value that looks like a number to an INTEGER when it's received in an INTEGER field, rather than keeping it as the wrong type, TEXT, if that’s the case.
I was not sure what was the sqlite behavior, so I was raising concern.
@rentalhost lets me test further. It looks good so far.
This is specified in the Type Affinity section, specifically in section 3.4.
Note that in the first INSERT
example, even though all VALUES
are sent as strings, they are converted to their affinity types according to the column type. So, "500.0"
is kept as a string in a TEXT
column but is converted to an integer for the INTEGER
column.
In the third example, the test is done using 500
as an integer literal, so it is cast to a string in the TEXT
column but remains an integer in the INTEGER
column.
Since SQLite is flexible with types, we can't blindly trust the column-defined type. Instead, we now determine the display type based on the type of the received data.
Here's how it works:
string
received type will be treated asTEXT
.bigint
received type will be treated asINTEGER
(since theBigNumberCell
component handlesbigint
, which aligns with howINTEGER
data is managed internally).number
received type will be treated asREAL
(because theNumberCell
component can handlenumber
, which can represent bothinteger
orfloat
in JavaScript, so even if anINTEGER
is treated asnumber
, it won't be an issue).object
(Array) received type will be treated asBLOB
.BLOB
orNULL
types are handled as generic types (managed by theGenericCell
component).Additional improvements:
useTableResultCellRenderer()
has been refactored into a direct callback instead of a React hook since it no longer has hook dependencies (specifically,useDatabaseDriver()
). As there was only one use of this hook, I moved the call directly to the final point of use instead of passing it down through component dependencies.Additional notes: