diff --git a/qgis/plugins/spit/qgsshapefile.cpp b/qgis/plugins/spit/qgsshapefile.cpp index aec365f91ba..ff951e6b99d 100644 --- a/qgis/plugins/spit/qgsshapefile.cpp +++ b/qgis/plugins/spit/qgsshapefile.cpp @@ -23,10 +23,6 @@ #include #include #include -extern "C" -{ - #include -} #include "qgsdbfbase.h" #include "cpl_error.h" @@ -125,6 +121,8 @@ QString QgsShapeFile::getTable(){ } void QgsShapeFile::setTable(QString new_table){ + new_table.replace("\'","\\'"); + new_table.replace("\\","\\\\"); table_name = new_table; } @@ -141,14 +139,17 @@ bool QgsShapeFile::insertLayer(QString dbname, QString geom_col, QString srid, P QString message; QString query = "CREATE TABLE "+table_name+"(gid int4, "; - for(int n=0; nGetFieldAsString(n); - val.replace("\'","\\\'"); - val.replace("\'","\\\'"); + val.replace("\'","\\'"); + val.replace("\\","\\\\"); + // add escaped value to the query query += val; query += QString(quotes + ", "); diff --git a/qgis/plugins/spit/qgsshapefile.h b/qgis/plugins/spit/qgsshapefile.h index cf23755256e..157833ed103 100644 --- a/qgis/plugins/spit/qgsshapefile.h +++ b/qgis/plugins/spit/qgsshapefile.h @@ -24,15 +24,15 @@ #include #include #include + +class OGRLayer; +class OGRDataSource; extern "C" { #include } -class OGRLayer; -class OGRDataSource; - class QgsShapeFile : public QObject { Q_OBJECT @@ -42,7 +42,7 @@ class QgsShapeFile : public QObject ~QgsShapeFile(); int getFeatureCount(); QString getFeatureClass(); - bool insertLayer(QString dbname, QString geom_col, QString srid, struct pg_conn* conn, QProgressDialog * pro, bool &fin); + bool insertLayer(QString dbname, QString geom_col, QString srid, PGconn * conn, QProgressDialog * pro, bool &fin); bool is_valid(); QString getName(); diff --git a/qgis/plugins/spit/qgsspit.cpp b/qgis/plugins/spit/qgsspit.cpp index d4b01372c69..4860e2047ae 100644 --- a/qgis/plugins/spit/qgsspit.cpp +++ b/qgis/plugins/spit/qgsspit.cpp @@ -30,6 +30,7 @@ #include #include #include +#include extern "C" { #include @@ -252,10 +253,17 @@ void QgsSpit::import(){ pro->setAutoClose(true); qApp->processEvents(); //pro->setAutoReset(true); - - PQexec(pd, "BEGIN"); for(int i=0; igetTable()[0]).isLetter()){ + QMessageBox::warning(pro, "Import Shapefiles", + "Problem inserting file:\n"+fileList[i]->getName()+"\nInvalid table name."); + std::cout<setTable(tblShapefiles->text(i, 3)); pro->show(); pro->setLabelText("Importing files\n"+fileList[i]->getName()); @@ -280,7 +288,7 @@ void QgsSpit::import(){ QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape, - QMessageBox::NoButton, this, "Relation Exists"); + QMessageBox::NoButton, pro, "Relation Exists"); } if ((!rel_exists1 && !rel_exists2) || del_confirm->exec() == QMessageBox::Yes){ if(rel_exists1){ @@ -298,18 +306,13 @@ void QgsSpit::import(){ if(!fileList[i]->insertLayer(settings.readEntry(key + "/database"), txtGeomName->text(), QString("%1").arg(spinSrid->value()), pd, pro, finished)){ if(!finished){ - pro->close(); - QMessageBox::warning(this, "Import Shapefiles", - "Problem inserting features\nOne or more of your shapefiles may be corrupted"); + QMessageBox::warning(pro, "Import Shapefiles", + "Problem inserting features from file:\n"+fileList[i]->getName()); + PQexec(pd, "ROLLBACK"); } - finished = true; - break; - } - else if(finished){ - pro->close(); - break; } else{ // if file has been imported, remove it from the list + PQexec(pd, "COMMIT"); for(int j=0; jnumRows(); j++) if(tblShapefiles->text(j,0)==QString(fileList[i]->getName())){ tblShapefiles->selectRow(j); @@ -321,13 +324,7 @@ void QgsSpit::import(){ } else{ pro->setProgress(pro->progress()+fileList[i]->getFeatureCount()); - } - } - - if(finished) - PQexec(pd, "ROLLBACK"); - else{ - PQexec(pd, "COMMIT"); + } } } else diff --git a/qgis/plugins/spit/qgsspitplugin.cpp b/qgis/plugins/spit/qgsspitplugin.cpp index f02a735add2..0173bc733eb 100644 --- a/qgis/plugins/spit/qgsspitplugin.cpp +++ b/qgis/plugins/spit/qgsspitplugin.cpp @@ -88,7 +88,7 @@ void QgsSpitPlugin::initGui() QPopupMenu *pluginMenu = new QPopupMenu(qgisMainWindow); pluginMenu->insertItem("&Import Shapefiles to PostgreSQL", this, SLOT(spit())); - pluginMenu->insertItem("&Unload SPTI Plugin", this, SLOT(unload())); + pluginMenu->insertItem("&Unload SPIT Plugin", this, SLOT(unload())); menu = ((QMainWindow *) qgisMainWindow)->menuBar();