mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
fixed segfault errors
git-svn-id: http://svn.osgeo.org/qgis/trunk@688 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
3b8e6d9cd9
commit
af4c26ead2
@ -136,7 +136,6 @@ bool QgsShapeFile::insertLayer(QString dbname, QString geom_col, QString srid, P
|
||||
connect(pro, SIGNAL(cancelled()), this, SLOT(cancelImport()));
|
||||
import_cancelled = false;
|
||||
bool result = true;
|
||||
QString message;
|
||||
|
||||
QString query = "CREATE TABLE "+table_name+"(gid int4 PRIMARY KEY, ";
|
||||
for(int n=0; n<column_names.size() && result; n++){
|
||||
@ -151,22 +150,24 @@ bool QgsShapeFile::insertLayer(QString dbname, QString geom_col, QString srid, P
|
||||
query += " )";
|
||||
|
||||
PGresult *res = PQexec(conn, (const char *)query);
|
||||
message = PQresultErrorMessage(res);
|
||||
if(message != ""){
|
||||
if(PQresultStatus(res)!=PGRES_COMMAND_OK){
|
||||
// flag error and send query and error message to stdout on debug
|
||||
result = false;
|
||||
qWarning(query);
|
||||
qWarning(PQresultErrorMessage(res));
|
||||
}
|
||||
PQclear(res);
|
||||
else {
|
||||
PQclear(res);
|
||||
}
|
||||
|
||||
query = "SELECT AddGeometryColumn(\'" + dbname + "\', \'" + table_name + "\', \'"+geom_col+"\', " + srid +
|
||||
", \'" + QString(geom_type) + "\', 2)";
|
||||
if(result) res = PQexec(conn, (const char *)query);
|
||||
if(message != ""){
|
||||
if(PQresultStatus(res)!=PGRES_COMMAND_OK){
|
||||
result = false;
|
||||
qWarning(query);
|
||||
message = PQresultErrorMessage(res);
|
||||
qWarning(PQresultErrorMessage(res));
|
||||
}
|
||||
else{
|
||||
PQclear(res);
|
||||
}
|
||||
|
||||
//adding the data into the table
|
||||
@ -175,6 +176,7 @@ bool QgsShapeFile::insertLayer(QString dbname, QString geom_col, QString srid, P
|
||||
fin = true;
|
||||
break;
|
||||
}
|
||||
|
||||
OGRFeature *feat = ogrLayer->GetNextFeature();
|
||||
if(feat){
|
||||
OGRGeometry *geom = feat->GetGeometryRef();
|
||||
@ -206,15 +208,17 @@ bool QgsShapeFile::insertLayer(QString dbname, QString geom_col, QString srid, P
|
||||
}
|
||||
query += QString("GeometryFromText(\'")+geometry+QString("\', ")+srid+QString("))");
|
||||
|
||||
PQclear(res);
|
||||
if(result) res = PQexec(conn, (const char *)query);
|
||||
message = PQresultErrorMessage(res);
|
||||
if(message != ""){
|
||||
if(result)
|
||||
res = PQexec(conn, (const char *)query);
|
||||
if(PQresultStatus(res)!=PGRES_COMMAND_OK){
|
||||
// flag error and send query and error message to stdout on debug
|
||||
result = false;
|
||||
qWarning(query);
|
||||
qWarning(PQresultErrorMessage(res));
|
||||
}
|
||||
else {
|
||||
PQclear(res);
|
||||
}
|
||||
|
||||
pro->setProgress(pro->progress()+1);
|
||||
qApp->processEvents();
|
||||
delete[] geo_temp;
|
||||
@ -223,7 +227,6 @@ bool QgsShapeFile::insertLayer(QString dbname, QString geom_col, QString srid, P
|
||||
}
|
||||
}
|
||||
ogrLayer->ResetReading();
|
||||
PQclear(res);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -268,7 +268,14 @@ void QgsSpit::import(){
|
||||
pro->setProgress(pro->progress()+fileList[i]->getFeatureCount());
|
||||
continue;
|
||||
}
|
||||
PQexec(pd, "BEGIN");
|
||||
|
||||
res = PQexec(pd, "BEGIN");
|
||||
if(PQresultStatus(res)!=PGRES_COMMAND_OK){
|
||||
qWarning(PQresultErrorMessage(res));
|
||||
}
|
||||
else {
|
||||
PQclear(res);
|
||||
}
|
||||
|
||||
fileList[i]->setTable(tblShapefiles->text(i, 3));
|
||||
pro->setLabelText("Importing files\n"+fileList[i]->getName());
|
||||
@ -276,14 +283,26 @@ void QgsSpit::import(){
|
||||
int rel_exists2 = 0;
|
||||
QString query = "SELECT f_table_name FROM geometry_columns WHERE f_table_name=\'"+fileList[i]->getTable()+"\'";
|
||||
res = PQexec(pd, (const char *)query);
|
||||
rel_exists1 = PQntuples(res);
|
||||
PQclear(res);
|
||||
query = "SELECT relname FROM pg_tables WHERE tablename=\'"+fileList[i]->getTable()+"\'";
|
||||
if(PQresultStatus(res)!=PGRES_COMMAND_OK){
|
||||
qWarning(PQresultErrorMessage(res));
|
||||
}
|
||||
else {
|
||||
PQclear(res);
|
||||
}
|
||||
|
||||
//rel_exists1 = PQntuples(res);
|
||||
|
||||
query = "SELECT tablename FROM pg_tables WHERE tablename=\'"+fileList[i]->getTable()+"\'";
|
||||
res = PQexec(pd, (const char *)query);
|
||||
rel_exists2 = PQntuples(res);
|
||||
PQclear(res);
|
||||
if(PQresultStatus(res)!=PGRES_COMMAND_OK){
|
||||
qWarning(PQresultErrorMessage(res));
|
||||
}
|
||||
else {
|
||||
PQclear(res);
|
||||
}
|
||||
//rel_exists2 = PQntuples(res);
|
||||
|
||||
std::cout<< rel_exists1 << " " << rel_exists2 << std::endl;
|
||||
//std::cout<< rel_exists1 << " " << rel_exists2 << std::endl;
|
||||
|
||||
QMessageBox *del_confirm;
|
||||
if(rel_exists1!=0 || rel_exists2!=0){
|
||||
@ -301,15 +320,31 @@ void QgsSpit::import(){
|
||||
query = "SELECT DropGeometryColumn(\'"+QString(settings.readEntry(key + "/database"))+"\', \'"+
|
||||
fileList[i]->getTable()+"\', \'"+txtGeomName->text()+"')";
|
||||
res = PQexec(pd, (const char *)query);
|
||||
PQclear(res);
|
||||
if(PQresultStatus(res)!=PGRES_COMMAND_OK){
|
||||
qWarning(PQresultErrorMessage(res));
|
||||
}
|
||||
else {
|
||||
PQclear(res);
|
||||
}
|
||||
}
|
||||
else if (del_confirm->exec() == QMessageBox::Yes && rel_exists2!=0){
|
||||
query = "DROP TABLE " + fileList[i]->getTable();
|
||||
res = PQexec(pd, (const char *)query);
|
||||
PQclear(res);
|
||||
if(PQresultStatus(res)!=PGRES_COMMAND_OK){
|
||||
qWarning(PQresultErrorMessage(res));
|
||||
}
|
||||
else {
|
||||
PQclear(res);
|
||||
}
|
||||
}
|
||||
else {
|
||||
PQexec(pd, "ROLLBACK");
|
||||
res = PQexec(pd, "ROLLBACK");
|
||||
if(PQresultStatus(res)!=PGRES_COMMAND_OK){
|
||||
qWarning(PQresultErrorMessage(res));
|
||||
}
|
||||
else {
|
||||
PQclear(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -318,12 +353,25 @@ void QgsSpit::import(){
|
||||
if(!finished){
|
||||
QMessageBox::warning(this, "Import Shapefiles",
|
||||
"Problem inserting features from file:\n"+fileList[i]->getName());
|
||||
PQexec(pd, "ROLLBACK");
|
||||
res = PQexec(pd, "ROLLBACK");
|
||||
if(PQresultStatus(res)!=PGRES_COMMAND_OK){
|
||||
qWarning(PQresultErrorMessage(res));
|
||||
}
|
||||
else {
|
||||
PQclear(res);
|
||||
}
|
||||
}
|
||||
pro->setProgress(pro->progress()+fileList[i]->getFeatureCount());
|
||||
}
|
||||
else{ // if file has been imported, remove it from the list
|
||||
PQexec(pd, "COMMIT");
|
||||
res = PQexec(pd, "COMMIT");
|
||||
if(PQresultStatus(res)!=PGRES_COMMAND_OK){
|
||||
qWarning(PQresultErrorMessage(res));
|
||||
}
|
||||
else {
|
||||
PQclear(res);
|
||||
}
|
||||
|
||||
for(int j=0; j<tblShapefiles->numRows(); j++){
|
||||
if(tblShapefiles->text(j,0)==QString(fileList[i]->getName())){
|
||||
tblShapefiles->selectRow(j);
|
||||
|
@ -5,10 +5,10 @@
|
||||
<Mainframe MaximizeMode="1" />
|
||||
<DocsAndViews NumberOfDocuments="2" >
|
||||
<Doc0 CursorPosLine="276" Type="KWriteDoc" NumberOfViews="1" CursorPosCol="120" FileName="/sav/downloads/qgis/tools/spit/qgsspit.cpp" >
|
||||
<View0 Top="0" Width="977" Attach="1" Height="582" Left="0" Focus="1" Type="KWriteView" MinMaxMode="0" />
|
||||
<View0 Top="0" Width="939" Attach="1" Height="594" Left="0" Focus="1" Type="KWriteView" MinMaxMode="0" />
|
||||
</Doc0>
|
||||
<Doc1 CursorPosLine="140" Type="KWriteDoc" NumberOfViews="1" CursorPosCol="67" FileName="/sav/downloads/qgis/tools/spit/qgsshapefile.cpp" >
|
||||
<View0 Top="0" Width="1080" Attach="1" Height="544" Left="0" Focus="0" Type="KWriteView" MinMaxMode="0" />
|
||||
<Doc1 CursorPosLine="139" Type="KWriteDoc" NumberOfViews="1" CursorPosCol="67" FileName="/sav/downloads/qgis/tools/spit/qgsshapefile.cpp" >
|
||||
<View0 Top="0" Width="939" Attach="1" Height="594" Left="0" Focus="0" Type="KWriteView" MinMaxMode="0" />
|
||||
</Doc1>
|
||||
</DocsAndViews>
|
||||
</KDevPrjSession>
|
||||
|
Loading…
x
Reference in New Issue
Block a user