Skip to content

Commit e06bdce

Browse files
author
g_j_m
committed
Fix for the rest of ticket #130 (show the actual column default values
when getting the user to fill in the column values for a just digitised feature). Also add tr() to some user visible text. git-svn-id: http://svn.osgeo.org/qgis/trunk@5602 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 0346096 commit e06bdce

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

src/providers/postgres/qgspostgresprovider.cpp

+35-11
Original file line numberDiff line numberDiff line change
@@ -1704,8 +1704,9 @@ bool QgsPostgresProvider::addFeature(QgsFeature* f, int primaryKeyHighWater)
17041704
<< "." << std::endl;
17051705
#endif
17061706

1707-
//add quotes if the field is a character or date type
1708-
if(fieldvalue != "NULL" && fieldvalue != "DEFAULT")
1707+
//add quotes if the field is a character or date type and not
1708+
//the postgres provided default value
1709+
if(fieldvalue != "NULL" && fieldvalue != getDefaultValue(it->fieldName(), f))
17091710
{
17101711
for(std::vector<QgsField>::iterator iter=attributeFields.begin();iter!=attributeFields.end();++iter)
17111712
{
@@ -1720,6 +1721,7 @@ bool QgsPostgresProvider::addFeature(QgsFeature* f, int primaryKeyHighWater)
17201721
)
17211722
{
17221723
charactertype=true;
1724+
break; // no need to continue with this loop
17231725
}
17241726
}
17251727
}
@@ -1746,13 +1748,13 @@ bool QgsPostgresProvider::addFeature(QgsFeature* f, int primaryKeyHighWater)
17461748
PGresult* result=PQexec(connection, (const char *)(insert.utf8()));
17471749
if(result==0)
17481750
{
1749-
QMessageBox::information(0,"INSERT error","An error occured during feature insertion",QMessageBox::Ok);
1751+
QMessageBox::information(0,tr("INSERT error"),tr("An error occured during feature insertion"),QMessageBox::Ok);
17501752
return false;
17511753
}
17521754
ExecStatusType message=PQresultStatus(result);
17531755
if(message==PGRES_FATAL_ERROR)
17541756
{
1755-
QMessageBox::information(0,"INSERT error",QString(PQresultErrorMessage(result)),QMessageBox::Ok);
1757+
QMessageBox::information(0,tr("INSERT error"),QString(PQresultErrorMessage(result)),QMessageBox::Ok);
17561758
return false;
17571759
}
17581760

@@ -1773,7 +1775,29 @@ bool QgsPostgresProvider::addFeature(QgsFeature* f, int primaryKeyHighWater)
17731775

17741776
QString QgsPostgresProvider::getDefaultValue(const QString& attr, QgsFeature* f)
17751777
{
1776-
return "DEFAULT";
1778+
// Get the default column value from the Postgres information
1779+
// schema. If there is no default we return an empty string.
1780+
1781+
// Maintaining a cache of the results of this query would be quite
1782+
// simple and if this query is called lots, could save some time.
1783+
1784+
QString sql("SELECT column_default FROM "
1785+
"information_schema.columns WHERE "
1786+
"column_default IS NOT NULL AND "
1787+
"table_schema = '" + mSchemaName + "' AND "
1788+
"table_name = '" + mTableName + "' AND "
1789+
"column_name = '" + attr + "'");
1790+
1791+
QString defaultValue("");
1792+
1793+
PGresult* result = PQexec(connection, (const char*)(sql.utf8()));
1794+
1795+
if (PQntuples(result) == 1)
1796+
defaultValue = PQgetvalue(result, 0, 0);
1797+
1798+
PQclear(result);
1799+
1800+
return defaultValue;
17771801
}
17781802

17791803
bool QgsPostgresProvider::deleteFeature(int id)
@@ -1787,13 +1811,13 @@ bool QgsPostgresProvider::deleteFeature(int id)
17871811
PGresult* result=PQexec(connection, (const char *)(sql.utf8()));
17881812
if(result==0)
17891813
{
1790-
QMessageBox::information(0,"DELETE error","An error occured during deletion from disk",QMessageBox::Ok);
1814+
QMessageBox::information(0,tr("DELETE error"),tr("An error occured during deletion from disk"),QMessageBox::Ok);
17911815
return false;
17921816
}
17931817
ExecStatusType message=PQresultStatus(result);
17941818
if(message==PGRES_FATAL_ERROR)
17951819
{
1796-
QMessageBox::information(0,"DELETE error",QString(PQresultErrorMessage(result)),QMessageBox::Ok);
1820+
QMessageBox::information(0,tr("DELETE error"),QString(PQresultErrorMessage(result)),QMessageBox::Ok);
17971821
return false;
17981822
}
17991823

@@ -2106,17 +2130,17 @@ bool QgsPostgresProvider::changeGeometryValues(std::map<int, QgsGeometry> & geom
21062130
PGresult* result=PQexec(connection, (const char *)(sql.utf8()));
21072131
if (result==0)
21082132
{
2109-
QMessageBox::critical(0, "PostGIS error",
2110-
"An error occured contacting the PostgreSQL databse",
2133+
QMessageBox::critical(0, tr("PostGIS error"),
2134+
tr("An error occured contacting the PostgreSQL databse"),
21112135
QMessageBox::Ok,
21122136
Qt::NoButton);
21132137
return false;
21142138
}
21152139
ExecStatusType message=PQresultStatus(result);
21162140
if(message==PGRES_FATAL_ERROR)
21172141
{
2118-
QMessageBox::information(0, "PostGIS error",
2119-
"The PostgreSQL databse returned: "
2142+
QMessageBox::information(0, tr("PostGIS error"),
2143+
tr("The PostgreSQL databse returned: ")
21202144
+ QString(PQresultErrorMessage(result)),
21212145
QMessageBox::Ok,
21222146
Qt::NoButton);

0 commit comments

Comments
 (0)