@@ -200,64 +200,58 @@ void QgsNewSpatialiteLayerDialog::pbnFindSRID_clicked()
200200{
201201 // first get list of supported SRID from the selected SpatiaLite database
202202 // to build filter for projection selector
203- sqlite3 *db = nullptr ;
203+ sqlite3_database_unique_ptr database ;
204204 bool status = true ;
205- int rc = sqlite3_open_v2 ( mDatabaseComboBox ->currentText (). toUtf8 (), &db , SQLITE_OPEN_READONLY, nullptr );
205+ int rc = database. open_v2 ( mDatabaseComboBox ->currentText (), SQLITE_OPEN_READONLY, nullptr );
206206 if ( rc != SQLITE_OK )
207207 {
208208 QMessageBox::warning ( this , tr ( " SpatiaLite Database" ), tr ( " Unable to open the database" ) );
209209 return ;
210210 }
211211
212212 // load up the srid table
213- const char *pzTail = nullptr ;
214- sqlite3_stmt *ppStmt = nullptr ;
213+ sqlite3_statement_unique_ptr statement;
215214 QString sql = QStringLiteral ( " select auth_name || ':' || auth_srid from spatial_ref_sys order by srid asc" );
216215
217216 QSet<QString> myCRSs;
218217
219- rc = sqlite3_prepare ( db, sql. toUtf8 (), sql. toUtf8 (). length (), &ppStmt, &pzTail );
218+ statement = database. prepare ( sql, rc );
220219 // XXX Need to free memory from the error msg if one is set
221220 if ( rc == SQLITE_OK )
222221 {
223222 // get the first row of the result set
224- while ( sqlite3_step ( ppStmt ) == SQLITE_ROW )
223+ while ( sqlite3_step ( statement. get () ) == SQLITE_ROW )
225224 {
226- myCRSs.insert ( QString::fromUtf8 ( ( const char * )sqlite3_column_text ( ppStmt , 0 ) ) );
225+ myCRSs.insert ( QString::fromUtf8 ( ( const char * )sqlite3_column_text ( statement. get () , 0 ) ) );
227226 }
228227 }
229228 else
230229 {
231230 // XXX query failed -- warn the user some how
232- QMessageBox::warning ( nullptr , tr ( " Error" ), tr ( " Failed to load SRIDS: %1" ).arg ( sqlite3_errmsg ( db ) ) );
231+ QMessageBox::warning ( nullptr , tr ( " Error" ), tr ( " Failed to load SRIDS: %1" ).arg ( database. errorMessage ( ) ) );
233232 status = false ;
234233 }
235- // close the statement
236- sqlite3_finalize ( ppStmt );
237- sqlite3_close ( db );
238234
239- if ( ! status )
235+ if ( status )
240236 {
241- return ;
242- }
243-
244- // prepare projection selector
245- QgsProjectionSelectionDialog *mySelector = new QgsProjectionSelectionDialog ( this );
246- mySelector->setMessage ( QString () );
247- mySelector->setOgcWmsCrsFilter ( myCRSs );
248- mySelector->setCrs ( QgsCoordinateReferenceSystem::fromOgcWmsCrs ( mCrsId ) );
237+ // prepare projection selector
238+ QgsProjectionSelectionDialog *mySelector = new QgsProjectionSelectionDialog ( this );
239+ mySelector->setMessage ( QString () );
240+ mySelector->setOgcWmsCrsFilter ( myCRSs );
241+ mySelector->setCrs ( QgsCoordinateReferenceSystem::fromOgcWmsCrs ( mCrsId ) );
249242
250- if ( mySelector->exec () )
251- {
252- QgsCoordinateReferenceSystem srs = mySelector->crs ();
253- QString crsId = srs.authid ();
254- if ( crsId != mCrsId )
243+ if ( mySelector->exec () )
255244 {
256- mCrsId = crsId;
257- leSRID->setText ( srs.authid () + " - " + srs.description () );
245+ QgsCoordinateReferenceSystem srs = mySelector->crs ();
246+ QString crsId = srs.authid ();
247+ if ( crsId != mCrsId )
248+ {
249+ mCrsId = crsId;
250+ leSRID->setText ( srs.authid () + " - " + srs.description () );
251+ }
258252 }
253+ delete mySelector;
259254 }
260- delete mySelector;
261255}
262256
263257void QgsNewSpatialiteLayerDialog::nameChanged ( const QString &name )
0 commit comments