connectivity/source/drivers/postgresql/pq_xkeys.cxx: compareToAscii -> operator== sound?
Lionel Elie Mamane
lionel at mamane.lu
Tue Mar 19 10:29:18 PDT 2013
On Tue, Mar 19, 2013 at 03:13:02PM +0100, Stephan Bergmann wrote:
> >diff --git a/connectivity/source/drivers/postgresql/pq_xkeys.cxx b/connectivity/source/drivers/postgresql/pq_xkeys.cxx
> >index 314924d..2a8d521 100644
> >--- a/connectivity/source/drivers/postgresql/pq_xkeys.cxx
> >+++ b/connectivity/source/drivers/postgresql/pq_xkeys.cxx
> >@@ -127,58 +126,17 @@ static sal_Int32 string2keytype( const rtl::OUString &type )
> > static sal_Int32 string2keyrule( const rtl::OUString & rule )
> > {
> > sal_Int32 ret = com::sun::star::sdbc::KeyRule::NO_ACTION;
> >- if( rule.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "r" ) ) == 0 )
> >+ if( rule == "r" )
> > ret = com::sun::star::sdbc::KeyRule::RESTRICT;
> >- else if( rule.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "c" ) ) == 0 )
> >+ else if( rule == "c" )
> > ret = com::sun::star::sdbc::KeyRule::CASCADE;
> >- else if( rule.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "n" ) ) == 0 )
> >+ else if( rule == "n" )
> > ret = com::sun::star::sdbc::KeyRule::SET_NULL;
> >- else if( rule.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "d" ) ) == 0 )
> >+ else if( rule == "d" )
> > ret = com::sun::star::sdbc::KeyRule::SET_DEFAULT;
> > return ret;
> > }
> smells like an incorrect conversion from
> rtl::OUString::compareToAscii(asciiStr,maxLength) to operator==
> rather than rtl::OUString::startsWith,
Thanks for checking.
The string passed in argument is always of length 1, so in practise
the two will have the same behaviour. In the abstract, operator== is
"more correct" (and possibly future-proof against changes in
PostgreSQL internals) than startsWith.
The same holds for string2keytype.
--
Lionel
More information about the LibreOffice
mailing list