Skip to content

Commit 986ea53

Browse files
author
g_j_m
committedJul 25, 2006
If an SQL insert fails during committing new features to the database,
include the offending sql in the error dialog box. Also fix the remaining part of ticket #131 - the code wasn't coping correctly with blank data fields. git-svn-id: http://svn.osgeo.org/qgis/trunk@5637 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent fd39376 commit 986ea53

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed
 

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,8 @@ bool QgsPostgresProvider::addFeature(QgsFeature* f, int primaryKeyHighWater)
16951695
)
16961696
{
16971697
QString fieldvalue = it->fieldValue();
1698+
if (fieldvalue.isEmpty())
1699+
fieldvalue = "NULL";
16981700
bool charactertype=false;
16991701
insert+=",";
17001702

@@ -1753,7 +1755,18 @@ bool QgsPostgresProvider::addFeature(QgsFeature* f, int primaryKeyHighWater)
17531755
ExecStatusType message=PQresultStatus(result);
17541756
if(message==PGRES_FATAL_ERROR)
17551757
{
1756-
QMessageBox::information(0,tr("INSERT error"),QString(PQresultErrorMessage(result)),QMessageBox::Ok);
1758+
// Use QgsMessage viewer here instead of a QMessageBox because
1759+
// we want to include the offending SQL, which may be quite
1760+
// long, and the QMessageBox doesn't wrap text, etc.
1761+
1762+
QString sqlDetails = PQresultErrorMessage(result);
1763+
sqlDetails += tr("The sql was:\n\n") + insert;
1764+
QgsMessageViewer viewer;
1765+
viewer.setWindowTitle(tr("SQL error"));
1766+
viewer.setMessageAsPlainText(sqlDetails);
1767+
viewer.exec();
1768+
1769+
// QMessageBox::information(0,tr("INSERT error"), sqlDetails,QMessageBox::Ok);
17571770
return false;
17581771
}
17591772

0 commit comments

Comments
 (0)
Please sign in to comment.