Uh oh!
There was an error while loading. Please reload this page.
fix: [Postgre] updateBatch() breaks char type data - #8524
Conversation
sclubricants
left a comment
There was a problem hiding this comment.
This looks good.
One other option - though I don' t know that it would be any better would be to change CHARACTER into CHARACTER VARYING in the cast method. The only reason is that it would keep the getFieldType() method more 'pure' in a sense. But I'm not sure this would be any better.
You could change to CHARACTER | CHAR TO VARCHAR in the cast() method. This should cover the other DBMS too. https://onecompiler.com/postgresql/423ynm2e2 CREATETABLEtest_table
(
id integer,
charchar(10),
varcharvarchar(10)
);
INSERT INTO test_table (id, char, varchar) VALUES (1, 'foo', 'foo');
INSERT INTO test_table (id, char, varchar) VALUES (2, 'bar', 'bar');
INSERT INTO test_table (id, char, varchar) VALUES (3, 'baz', 'baz');
UPDATE"test_table"SET"char"= CAST(_u."char"ASVARCHAR),
"varchar"= CAST(_u."varchar"AS CHARACTER VARYING)
FROM (SELECT'Foo'"char", 1"id", 'Foo'"varchar"UNION ALLSELECT'Bar'"char", 2"id", 'Bar'"varchar"UNION ALLSELECT'Baz'"char", 3"id", 'Baz'"varchar") _u
WHERE"test_table"."id"= CAST(_u."id"ASINTEGER);
SELECT*FROM test_table;privatefunctioncast($expression, ?string$type): string
{
if (strtoupper($type) === 'CHAR' || strtoupper($type) === 'CHARACTER') {
$type = 'VARCHAR';
}
return ($type === null) ? $expression : 'CAST(' . $expression . ' AS ' . strtoupper($type) . ')';
} |
kenjis
commented
Feb 10, 2024
@sclubricants Thank you for the review! If Anyway, the method is only for Postgre, and it will override even if the parent class has the method. |
sclubricants
commented
Feb 10, 2024
CHAR = CHARACTER Anyways, looks good |
sclubricants
commented
Feb 10, 2024
SELECT CAST('STRING'ASVARCHAR) AS TEST;This runs on postgre but not on mysql |
Description
Follow-up #8439
From https://forum.codeigniter.com/showthread.php?tid=89336
Checklist: