60 changes: 31 additions & 29 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3255,9 +3255,9 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
",styleSLD xml"
",useAsDefault boolean"
",description text"
",ownervarchar(30)"
",owner varchar(30)"
",ui xml"
",update_time timestamp DEFAULT CURRENT_TIMESTAMP "
",update_time timestamp DEFAULT CURRENT_TIMESTAMP"
")" );
if ( res.PQresultStatus() != PGRES_COMMAND_OK )
{
Expand All @@ -3277,8 +3277,9 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS

QString sql = QString( "INSERT INTO layer_styles("
"f_table_catalog,f_table_schema,f_table_name,f_geometry_column,styleName,styleQML,styleSLD,useAsDefault,description,owner%11"
") VALUES("
"%1,%2,%3,%4,%5,XMLPARSE( DOCUMENT %6),XMLPARSE(DOCUMENT %7),%8,%9,%10%12)" )
") VALUES ("
"%1,%2,%3,%4,%5,XMLPARSE(DOCUMENT %6),XMLPARSE(DOCUMENT %7),%8,%9,%10%12"
")" )
.arg( QgsPostgresConn::quotedValue( dsUri.database() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.schema() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.table() ) )
Expand All @@ -3299,23 +3300,24 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
" AND f_table_name=%3"
" AND f_geometry_column=%4"
" AND styleName=%5" )
.arg( QgsPostgresConn::quotedValue( dsUri.database() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.schema() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.table() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.geometryColumn() ) )
.arg( QgsPostgresConn::quotedValue( styleName.isEmpty() ? dsUri.table() : styleName ) );
.arg( QgsPostgresConn::quotedValue( dsUri.database() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.schema() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.table() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.geometryColumn() ) )
.arg( QgsPostgresConn::quotedValue( styleName.isEmpty() ? dsUri.table() : styleName ) );

res = conn->PQexec( checkQuery );
if ( res.PQntuples() > 0 )
{
QString message = QObject::tr( "A style named \"%1\" already exists in the database for this layer. Do you want to overwrite it?" ).arg( styleName.isEmpty() ? dsUri.table() : styleName );
QMessageBox* duplicateMessageBox = new QMessageBox( QMessageBox::Question, "Save style in database", message, QMessageBox::Yes|QMessageBox::No );

if( duplicateMessageBox->exec() == QMessageBox::No )
if ( QMessageBox::question( 0, QObject::tr( "Save style in database" ),
QObject::tr( "A style named \"%1\" already exists in the database for this layer. Do you want to overwrite it?" )
.arg( styleName.isEmpty() ? dsUri.table() : styleName ),
QMessageBox::Yes | QMessageBox::No ) == QMessageBox::No )
{
errCause = QObject::tr( "Operation aborted. No changes were made in the database" );
return false;
errCause = QObject::tr( "Operation aborted. No changes were made in the database" );
return false;
}

sql = QString( "UPDATE layer_styles"
" SET useAsDefault=%1"
",styleQML=XMLPARSE(DOCUMENT %2)"
Expand All @@ -3327,16 +3329,16 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
" AND f_table_name=%8"
" AND f_geometry_column=%9"
" AND styleName=%10" )
.arg( useAsDefault ? "true" : "false" )
.arg( QgsPostgresConn::quotedValue( qmlStyle ) )
.arg( QgsPostgresConn::quotedValue( sldStyle ) )
.arg( QgsPostgresConn::quotedValue( styleDescription.isEmpty() ? QDateTime::currentDateTime().toString() : styleDescription ) )
.arg( QgsPostgresConn::quotedValue( dsUri.username() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.database() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.schema() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.table() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.geometryColumn() ) )
.arg( QgsPostgresConn::quotedValue( styleName.isEmpty() ? dsUri.table() : styleName ) );
.arg( useAsDefault ? "true" : "false" )
.arg( QgsPostgresConn::quotedValue( qmlStyle ) )
.arg( QgsPostgresConn::quotedValue( sldStyle ) )
.arg( QgsPostgresConn::quotedValue( styleDescription.isEmpty() ? QDateTime::currentDateTime().toString() : styleDescription ) )
.arg( QgsPostgresConn::quotedValue( dsUri.username() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.database() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.schema() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.table() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.geometryColumn() ) )
.arg( QgsPostgresConn::quotedValue( styleName.isEmpty() ? dsUri.table() : styleName ) );
}

if ( useAsDefault )
Expand All @@ -3347,10 +3349,10 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
" AND f_table_schema=%2"
" AND f_table_name=%3"
" AND f_geometry_column=%4" )
.arg( QgsPostgresConn::quotedValue( dsUri.database() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.schema() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.table() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.geometryColumn() ) );
.arg( QgsPostgresConn::quotedValue( dsUri.database() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.schema() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.table() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.geometryColumn() ) );
sql = QString( "BEGIN; %1; %2; COMMIT;" ).arg( removeDefaultSql ).arg( sql );
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/qgsprojectpropertiesbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@
<string notr="true">font-weight:bold;</string>
</property>
<property name="text">
<string>Defaut styles</string>
<string>Default styles</string>
</property>
</widget>
</item>
Expand Down
2 changes: 1 addition & 1 deletion src/ui/qgssavetodbdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<item row="2" column="0" rowspan="2" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Optionally pick an input form for attribute editing (QT Creator UI format), it will be stored in the db</string>
<string>Optionally pick an input form for attribute editing (QT Designer UI format), it will be stored in the database</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
Expand Down