tdf#128111: "adsrc" doesn't exist from Postgresql 12

Before Postgresql 8.0, there was only "adsrc"
then it's been deprecated
"The adsrc field is historical, and is best not used, because it does not track outside changes
 that might affect the representation of the default value.
 Reverse-compiling the adbin field (with pg_get_expr for example) is a better way to display the default value
"
and finally it's been removed with version 12

See evolution with:
- https://www.postgresql.org/docs/8/catalog-pg-attrdef.html
- https://www.postgresql.org/docs/11/catalog-pg-attrdef.html
- https://www.postgresql.org/docs/12/catalog-pg-attrdef.html

Change-Id: I57e9da423a23b5a96bbb64b0e026b160e9643ab9
Reviewed-on: https://gerrit.libreoffice.org/80722
Tested-by: Jenkins
Reviewed-by: Lionel Elie Mamane <lionel@mamane.lu>
This commit is contained in:
Julien Nabet
2019-10-13 00:26:10 +02:00
parent 414d10d8a3
commit 0c46c81e04
4 changed files with 18 additions and 7 deletions

View File

@@ -629,10 +629,12 @@ static void getAutoValues(
String2StringMap & result,
const Reference< XConnection > & connection,
const OUString &schemaName,
const OUString & tableName )
const OUString & tableName,
ConnectionSettings *pConnectionSettings )
{
OUString strDefaultValue = getDefaultValue(pConnectionSettings);
Reference< XPreparedStatement > stmt = connection->prepareStatement(
"SELECT pg_attribute.attname, pg_attrdef.adsrc "
"SELECT pg_attribute.attname, " + strDefaultValue +
"FROM pg_class, pg_namespace, pg_attribute "
"LEFT JOIN pg_attrdef ON pg_attribute.attrelid = pg_attrdef.adrelid AND "
"pg_attribute.attnum = pg_attrdef.adnum "
@@ -642,7 +644,7 @@ static void getAutoValues(
// LEM TODO: this is weird; why "LIKE" and not "="?
// Most probably gives problems if tableName contains '%'
"pg_class.relname LIKE ? AND "
"pg_attrdef.adsrc != ''"
+ strDefaultValue + " != ''"
);
DisposeGuard guard( stmt );
Reference< XParameters > paras( stmt, UNO_QUERY );
@@ -736,7 +738,7 @@ Reference< XResultSet > getGeneratedValuesFromLastInsert(
{
if( autoValues.empty() )
{
getAutoValues( autoValues, connection, schemaName, tableName );
getAutoValues( autoValues, connection, schemaName, tableName, pConnectionSettings );
}
// this could mean, that the column is a default or auto value, check this ...
bool bColumnMatchAutoValue = false;