Skip to content
Permalink
Browse files

improve database uri quoting (eg. for table names with quotes)

git-svn-id: http://svn.osgeo.org/qgis/trunk@13336 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Apr 20, 2010
1 parent b2051a8 commit 9e93c6e9ae18ed5929e54cd38da6e729359d66bf
Showing with 11 additions and 8 deletions.
  1. +9 −6 src/core/qgsdatasourceuri.cpp
  2. +2 −2 src/core/qgsdatasourceuri.h
@@ -306,12 +306,12 @@ void QgsDataSourceURI::clearSchema()
mSchema = "";
}

QString QgsDataSourceURI::escape( const QString &theVal ) const
QString QgsDataSourceURI::escape( const QString &theVal, QChar delim = '\'' ) const
{
QString val = theVal;

val.replace( "\\", "\\\\" );
val.replace( "\'", "\\'" );
val.replace( delim, QString( "\\%1" ).arg( delim ) );

return val;
}
@@ -349,7 +349,7 @@ QString QgsDataSourceURI::getValue( const QString &uri, int &i )
i++;
if ( i == uri.length() )
continue;
if ( uri[i] != '\'' && uri[i] != '\\' )
if ( uri[i] != delim && uri[i] != '\\' )
i--;
}
else if ( uri[i] == delim )
@@ -449,10 +449,13 @@ QString QgsDataSourceURI::uri() const

QString QgsDataSourceURI::quotedTablename() const
{
if ( mSchema != "" )
return QString( "\"%1\".\"%2\"" ).arg( mSchema ).arg( mTable );
if ( !mSchema.isEmpty() )
return QString( "\"%1\".\"%2\"" )
.arg( escape( mSchema, '"' ) )
.arg( escape( mTable, '"' ) );
else
return QString( "\"%1\"" ).arg( mTable );
return QString( "\"%1\"" )
.arg( escape( mTable, '"' ) );
}

void QgsDataSourceURI::setConnection( const QString &host,
@@ -107,7 +107,7 @@ class CORE_EXPORT QgsDataSourceURI
private:
void skipBlanks( const QString &uri, int &i );
QString getValue( const QString &uri, int &i );
QString escape( const QString &uri ) const;
QString escape( const QString &uri, QChar delim ) const;

/* data */

@@ -123,7 +123,7 @@ class CORE_EXPORT QgsDataSourceURI
QString mTable;
//! geometry column
QString mGeometryColumn;
//! SQL where clause used to limit features returned from the layer
//! SQL query or where clause used to limit features returned from the layer
QString mSql;
//! username
QString mUsername;

0 comments on commit 9e93c6e

Please sign in to comment.
You can’t perform that action at this time.