mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Fixed #2346 - allow quoting of column references using double quotes.
Quoting is done in both search query builder and search from attribute table. git-svn-id: http://svn.osgeo.org/qgis/trunk@13754 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
0490af72b3
commit
e48766e5ec
@ -115,6 +115,10 @@ class QgsSearchTreeNode
|
||||
//! @note added in 1.5
|
||||
bool needsGeometry();
|
||||
|
||||
//! return quoted column reference (in double quotes)
|
||||
//! @note added in 1.5
|
||||
static QString quotedColumnRef( QString name );
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
@ -615,20 +615,16 @@ void QgsAttributeTableDialog::doSearch( QString searchString )
|
||||
void QgsAttributeTableDialog::search()
|
||||
{
|
||||
|
||||
QString str = mColumnBox->currentText();
|
||||
|
||||
QString fieldName = mColumnBox->currentText();
|
||||
const QgsFieldMap& flds = mLayer->pendingFields();
|
||||
int fldIndex = mLayer->fieldNameIndex( str );
|
||||
int fldIndex = mLayer->fieldNameIndex( fieldName );
|
||||
QVariant::Type fldType = flds[fldIndex].type();
|
||||
bool numeric = ( fldType == QVariant::Int || fldType == QVariant::Double );
|
||||
|
||||
if ( numeric )
|
||||
str += " = '";
|
||||
else
|
||||
str += " ~ '";
|
||||
|
||||
str += mQuery->displayText().replace( "'", "''" ); // escape quotes
|
||||
str += "'";
|
||||
QString str = QString( "%1 %2 '%3'" )
|
||||
.arg( QgsSearchTreeNode::quotedColumnRef( fieldName ) )
|
||||
.arg( numeric ? "=" : "~" )
|
||||
.arg( mQuery->displayText().replace( "'", "''" ) ); // escape quotes
|
||||
|
||||
doSearch( str );
|
||||
}
|
||||
|
@ -80,11 +80,14 @@ QgsSearchQueryBuilder::~QgsSearchQueryBuilder()
|
||||
void QgsSearchQueryBuilder::populateFields()
|
||||
{
|
||||
QgsDebugMsg( "entering." );
|
||||
QRegExp reQuote( "[A-Za-z_][A-Za-z0-9_]*" );
|
||||
const QgsFieldMap& fields = mLayer->pendingFields();
|
||||
for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it )
|
||||
{
|
||||
QString fieldName = it->name();
|
||||
mFieldMap[fieldName] = it.key();
|
||||
if ( !reQuote.exactMatch( fieldName ) ) // quote if necessary
|
||||
fieldName = QgsSearchTreeNode::quotedColumnRef( fieldName );
|
||||
QStandardItem *myItem = new QStandardItem( fieldName );
|
||||
myItem->setEditable( false );
|
||||
mModelFields->insertRow( mModelFields->rowCount(), myItem );
|
||||
|
@ -49,6 +49,9 @@ col_first [A-Za-z_]|{non_ascii}
|
||||
col_next [A-Za-z0-9_]|{non_ascii}
|
||||
column_ref {col_first}{col_next}*
|
||||
|
||||
col_str_char "\"\""|[^\"]
|
||||
column_ref_quoted "\""{col_str_char}*"\""
|
||||
|
||||
dig [0-9]
|
||||
num1 {dig}+\.?([eE][-+]?{dig}+)?
|
||||
num2 {dig}*\.{dig}+([eE][-+]?{dig}+)?
|
||||
@ -101,6 +104,7 @@ string "'"{str_char}*"'"
|
||||
"$length" { return LENGTH; }
|
||||
|
||||
{column_ref} { return COLUMN_REF; }
|
||||
{column_ref_quoted} { return COLUMN_REF; }
|
||||
|
||||
{white} /* skip blanks and tabs */
|
||||
|
||||
|
@ -70,6 +70,11 @@ QgsSearchTreeNode::QgsSearchTreeNode( QString text, bool isColumnRef )
|
||||
{
|
||||
mType = tColumnRef;
|
||||
mText = text;
|
||||
if ( text.at( 0 ) == '\"' )
|
||||
{
|
||||
// column reference is quoted
|
||||
stripColRef();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -162,6 +167,21 @@ void QgsSearchTreeNode::stripText()
|
||||
|
||||
}
|
||||
|
||||
void QgsSearchTreeNode::stripColRef()
|
||||
{
|
||||
// strip double quotes on start,end
|
||||
mText = mText.mid( 1, mText.length() - 2 );
|
||||
|
||||
// make single "double quotes" from double "double quotes"
|
||||
mText.replace( QRegExp( "\"\"" ), "\"" );
|
||||
}
|
||||
|
||||
QString QgsSearchTreeNode::quotedColumnRef( QString name )
|
||||
{
|
||||
return QString( "\"%1\"" ).arg( name.replace( "\"", "\"\"" ) );
|
||||
}
|
||||
|
||||
|
||||
QString QgsSearchTreeNode::makeSearchString()
|
||||
{
|
||||
QString str;
|
||||
|
@ -153,6 +153,10 @@ class CORE_EXPORT QgsSearchTreeNode
|
||||
//! @note added in 1.5
|
||||
bool needsGeometry();
|
||||
|
||||
//! return quoted column reference (in double quotes)
|
||||
//! @note added in 1.5
|
||||
static QString quotedColumnRef( QString name );
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@ -162,6 +166,9 @@ class CORE_EXPORT QgsSearchTreeNode
|
||||
//! strips mText when node is of string type
|
||||
void stripText();
|
||||
|
||||
//! strip mText when column reference is quoted
|
||||
void stripColRef();
|
||||
|
||||
//! initialize node's internals
|
||||
void init();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user