mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-04 00:04:03 -04:00
Avoid warnings about unsecure functions
and modernize code
This commit is contained in:
parent
5ed3275ada
commit
e8e751ca3a
@ -563,38 +563,34 @@ bool QgsSpatiaLiteConnection::isRasterlite1Datasource( sqlite3 *handle, const ch
|
|||||||
int rows;
|
int rows;
|
||||||
int columns;
|
int columns;
|
||||||
bool exists = false;
|
bool exists = false;
|
||||||
char table_raster[4192];
|
|
||||||
char sql[4258];
|
|
||||||
|
|
||||||
strncpy( table_raster, table, sizeof table_raster );
|
QString tableRaster = QString::fromUtf8( table );
|
||||||
table_raster[sizeof table_raster - 1] = '\0';
|
if ( tableRaster.size() < 9 )
|
||||||
|
|
||||||
const size_t len = strlen( table_raster );
|
|
||||||
if ( strlen( table_raster ) < 9 )
|
|
||||||
return false;
|
return false;
|
||||||
if ( strcmp( table_raster + len - 9, "_metadata" ) != 0 )
|
if ( !tableRaster.endsWith( QLatin1String( "_metadata" ) ) )
|
||||||
return false;
|
return false;
|
||||||
// OK, possible candidate
|
|
||||||
strcpy( table_raster + len - 9, "_rasters" );
|
|
||||||
|
|
||||||
// checking if the related "_RASTERS table exists
|
// OK, possible candidate → replace suffix
|
||||||
sprintf( sql, "SELECT name FROM sqlite_master WHERE type = 'table' AND name = '%s'", table_raster );
|
tableRaster.chop( 9 );
|
||||||
|
tableRaster += QLatin1String( "_rasters" );
|
||||||
|
|
||||||
ret = sqlite3_get_table( handle, sql, &results, &rows, &columns, nullptr );
|
// checking if the related "_RASTERS" table exists
|
||||||
|
QString sqlStr = QStringLiteral(
|
||||||
|
"SELECT name FROM sqlite_master WHERE type = 'table' AND name = '%1'"
|
||||||
|
)
|
||||||
|
.arg( tableRaster.replace( '\'', QLatin1String( "''" ) ) );
|
||||||
|
|
||||||
|
ret = sqlite3_get_table( handle, sql.toUtf8().constData(), &results, &rows, &columns, nullptr );
|
||||||
if ( ret != SQLITE_OK )
|
if ( ret != SQLITE_OK )
|
||||||
return false;
|
return false;
|
||||||
if ( rows < 1 )
|
|
||||||
;
|
for ( i = 1; i <= rows; i++ )
|
||||||
else
|
|
||||||
{
|
{
|
||||||
for ( i = 1; i <= rows; i++ )
|
const char *name = results[( i * columns ) + 0];
|
||||||
|
if ( name )
|
||||||
{
|
{
|
||||||
if ( results[( i * columns ) + 0] )
|
exists = true;
|
||||||
{
|
break;
|
||||||
const char *name = results[( i * columns ) + 0];
|
|
||||||
if ( name )
|
|
||||||
exists = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sqlite3_free_table( results );
|
sqlite3_free_table( results );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user