Skip to content

Commit

Permalink
If an SQL insert fails during committing new features to the database,
Browse files Browse the repository at this point in the history
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/qgis@5637 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed Jul 25, 2006
1 parent a031af4 commit bf71f52
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -1695,6 +1695,8 @@ bool QgsPostgresProvider::addFeature(QgsFeature* f, int primaryKeyHighWater)
)
{
QString fieldvalue = it->fieldValue();
if (fieldvalue.isEmpty())
fieldvalue = "NULL";
bool charactertype=false;
insert+=",";

Expand Down Expand Up @@ -1753,7 +1755,18 @@ bool QgsPostgresProvider::addFeature(QgsFeature* f, int primaryKeyHighWater)
ExecStatusType message=PQresultStatus(result);
if(message==PGRES_FATAL_ERROR)
{
QMessageBox::information(0,tr("INSERT error"),QString(PQresultErrorMessage(result)),QMessageBox::Ok);
// Use QgsMessage viewer here instead of a QMessageBox because
// we want to include the offending SQL, which may be quite
// long, and the QMessageBox doesn't wrap text, etc.

QString sqlDetails = PQresultErrorMessage(result);
sqlDetails += tr("The sql was:\n\n") + insert;
QgsMessageViewer viewer;
viewer.setWindowTitle(tr("SQL error"));
viewer.setMessageAsPlainText(sqlDetails);
viewer.exec();

// QMessageBox::information(0,tr("INSERT error"), sqlDetails,QMessageBox::Ok);
return false;
}

Expand Down

0 comments on commit bf71f52

Please sign in to comment.