Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oracle - Wrong default value FIX #34482 #36769

Merged

Conversation

SebastienPeillet
Copy link
Contributor

@SebastienPeillet SebastienPeillet commented May 27, 2020

FIX #34482
FIX #32401

Description

Default values are misreaded from all_tab_columns table.

Default values are retrieving from the data_default field in all_tab_columns table (see here).

And long story short :

  • data_default is a long type column
  • long is a type that can contains a lot of data, so data is readed in a "piecewise" mode (see qsql_ocispatial.cpp and oracle documentation)
  • piecewise read mode concatenates the value piece by piece (for a single row), but after the first row the value is not cleared, so it concatenates the current default value with the previous one, etc

The solution is to clear values if piecewise mode is used.

We already test default values in test_provider_oracle.py :

    def testDefaultValue(self):
        self.assertEqual(self.source.defaultValue(1), NULL)
        self.assertEqual(self.source.defaultValue(2), "'qgis'")

I add self.assertEqual(self.source.defaultValue(3), "'qgis'") that is not tested yet. Without the PR changes, self.source.defaultValue(3) is equal to "qgisqgis" and not "qgis"

No backport before backporting #36654

@github-actions github-actions bot added this to the 3.14.0 milestone May 27, 2020
…ncatenates current default value with default value of the previous row in result)
@uclaros
Copy link
Contributor

uclaros commented Apr 22, 2021

@SebastienPeillet @nyalldawson I am not quite sure what this change fixed or what piecewise is, but I am quite confident it is responsible for #42857 that I stumbled upon recently.

Right after clearing values:

values.clear();
r = d->cols->readPiecewise( values, index );

values is accessed by index within readPiecewise() causing a crash:
if ( isStringField )
{
QString str = values.at( fieldNum + index ).toString();
str += QString( reinterpret_cast<const QChar *>( col ), chunkSize / 2 );
values[fieldNum + index] = str;
fieldInf[fieldNum].ind = 0;
}
else
{
QByteArray ba = values.at( fieldNum + index ).toByteArray();
int sz = ba.size();
ba.resize( sz + chunkSize );
memcpy( ba.data() + sz, reinterpret_cast<char *>( col ), chunkSize );
values[fieldNum + index] = ba;
fieldInf[fieldNum].ind = 0;
}

I don't know what changed to force me to the piecewise codepath though, I've never had issues until this week!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants