summaryrefslogtreecommitdiff
path: root/connectivity/source/drivers/postgresql/pq_tools.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'connectivity/source/drivers/postgresql/pq_tools.cxx')
-rw-r--r--connectivity/source/drivers/postgresql/pq_tools.cxx96
1 files changed, 47 insertions, 49 deletions
diff --git a/connectivity/source/drivers/postgresql/pq_tools.cxx b/connectivity/source/drivers/postgresql/pq_tools.cxx
index 9b75d69ba46c..fb42f864f97e 100644
--- a/connectivity/source/drivers/postgresql/pq_tools.cxx
+++ b/connectivity/source/drivers/postgresql/pq_tools.cxx
@@ -37,6 +37,7 @@
#include <sal/config.h>
#include <o3tl/any.hxx>
+#include <o3tl/string_view.hxx>
#include <rtl/strbuf.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
@@ -79,7 +80,6 @@ using com::sun::star::uno::Reference;
using com::sun::star::uno::Sequence;
using com::sun::star::uno::XInterface;
using com::sun::star::uno::Any;
-using com::sun::star::uno::makeAny;
using com::sun::star::container::XEnumeration;
using com::sun::star::container::XEnumerationAccess;
@@ -125,7 +125,7 @@ void bufferEscapeConstant( OUStringBuffer & buf, std::u16string_view value, Conn
strbuf.setLength( len );
// Previously here RTL_TEXTENCODING_ASCII_US; as we set the PostgreSQL client_encoding to UTF8,
// we get UTF8 here, too. I'm not sure why it worked well before...
- buf.append( OStringToOUString( strbuf.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ) );
+ buf.append( OStringToOUString( strbuf, RTL_TEXTENCODING_UTF8 ) );
}
static void ibufferQuoteConstant( OUStringBuffer & buf, std::u16string_view value, ConnectionSettings *settings )
@@ -315,30 +315,30 @@ bool isWhitespace( sal_Unicode c )
return ' ' == c || 9 == c || 10 == c || 13 == c;
}
-OUString extractTableFromInsert( const OUString & sql )
+OUString extractTableFromInsert( std::u16string_view sql )
{
OUString ret;
- int i = 0;
- while (i < sql.getLength() && isWhitespace(sql[i])) { i++; }
+ size_t i = 0;
+ while (i < sql.size() && isWhitespace(sql[i])) { i++; }
- if( sql.matchIgnoreAsciiCase("insert", i) )
+ if( o3tl::matchIgnoreAsciiCase(sql, u"insert", i) )
{
i += 6;
- while (i < sql.getLength() && isWhitespace(sql[i])) { i++; }
- if( sql.matchIgnoreAsciiCase("into", i) )
+ while (i < sql.size() && isWhitespace(sql[i])) { i++; }
+ if( o3tl::matchIgnoreAsciiCase(sql, u"into", i) )
{
i +=4;
- while (i < sql.getLength() && isWhitespace(sql[i])) { i++; }
+ while (i < sql.size() && isWhitespace(sql[i])) { i++; }
int start = i;
bool quote = (sql[i] == '"');
- for( i++ ; i < sql.getLength() ; i ++ )
+ for( i++ ; i < sql.size() ; i ++ )
{
if( quote && sql[i] == '"' )
{
- while (i < sql.getLength() && isWhitespace(sql[i])) { i++; }
+ while (i < sql.size() && isWhitespace(sql[i])) { i++; }
if( '.' == sql[i] )
{
- while (i < sql.getLength() && isWhitespace(sql[i])) { i++; }
+ while (i < sql.size() && isWhitespace(sql[i])) { i++; }
if( '"' == sql[i] )
{
// the second part of the table name does not use quotes
@@ -361,7 +361,7 @@ OUString extractTableFromInsert( const OUString & sql )
}
}
}
- ret = sql.copy(start, i - start ).trim();
+ ret = o3tl::trim(sql.substr(start, i - start ));
// printf( "pq_statement: parsed table name %s from insert\n" ,
// OUStringToOString( ret, RTL_TEXTENCODING_ASCII_US).getStr() );
}
@@ -416,7 +416,7 @@ void splitSQL( const OString & sql, std::vector< OString > &vec )
{
if( '"' == c )
{
- vec.push_back( OString( &sql.getStr()[start], i-start+1 ) );
+ vec.emplace_back( &sql.getStr()[start], i-start+1 );
start = i + 1;
doubleQuote = false;
}
@@ -431,7 +431,7 @@ void splitSQL( const OString & sql, std::vector< OString > &vec )
}
else if( '\'' == c )
{
- vec.push_back( OString( &sql.getStr()[start], i - start +1 ) );
+ vec.emplace_back( &sql.getStr()[start], i - start +1 );
start = i + 1; // leave single quotes !
singleQuote = false;
}
@@ -440,20 +440,20 @@ void splitSQL( const OString & sql, std::vector< OString > &vec )
{
if( '"' == c )
{
- vec.push_back( OString( &sql.getStr()[start], i - start ) );
+ vec.emplace_back( &sql.getStr()[start], i - start );
doubleQuote = true;
start = i;
}
else if( '\'' == c )
{
- vec.push_back( OString( &sql.getStr()[start], i - start ) );
+ vec.emplace_back( &sql.getStr()[start], i - start );
singleQuote = true;
start = i;
}
}
}
if( start < i )
- vec.push_back( OString( &sql.getStr()[start] , i - start ) );
+ vec.emplace_back( &sql.getStr()[start] , i - start );
// for( i = 0 ; i < vec.size() ; i ++ )
// printf( "%s!" , vec[i].getStr() );
@@ -476,7 +476,7 @@ void tokenizeSQL( const OString & sql, std::vector< OString > &vec )
{
if( '"' == c )
{
- vec.push_back( OString( &sql.getStr()[start], i-start ) );
+ vec.emplace_back( &sql.getStr()[start], i-start );
start = i + 1;
doubleQuote = false;
}
@@ -485,7 +485,7 @@ void tokenizeSQL( const OString & sql, std::vector< OString > &vec )
{
if( '\'' == c )
{
- vec.push_back( OString( &sql.getStr()[start], i - start +1 ) );
+ vec.emplace_back( &sql.getStr()[start], i - start +1 );
start = i + 1; // leave single quotes !
singleQuote = false;
}
@@ -508,15 +508,15 @@ void tokenizeSQL( const OString & sql, std::vector< OString > &vec )
start ++; // skip additional whitespace
else
{
- vec.push_back( OString( &sql.getStr()[start], i - start ) );
+ vec.emplace_back( &sql.getStr()[start], i - start );
start = i +1;
}
}
else if( ',' == c || isOperator( c ) || '(' == c || ')' == c )
{
if( i - start )
- vec.push_back( OString( &sql.getStr()[start], i - start ) );
- vec.push_back( OString( &sql.getStr()[i], 1 ) );
+ vec.emplace_back( &sql.getStr()[start], i - start );
+ vec.emplace_back( &sql.getStr()[i], 1 );
start = i + 1;
}
else if( '.' == c )
@@ -529,15 +529,15 @@ void tokenizeSQL( const OString & sql, std::vector< OString > &vec )
else
{
if( i - start )
- vec.push_back( OString( &sql.getStr()[start], i - start ) );
- vec.push_back( OString( "." ) );
+ vec.emplace_back( &sql.getStr()[start], i - start );
+ vec.emplace_back( "." );
start = i + 1;
}
}
}
}
if( start < i )
- vec.push_back( OString( &sql.getStr()[start] , i - start ) );
+ vec.emplace_back( &sql.getStr()[start] , i - start );
// for( i = 0 ; i < vec.size() ; i ++ )
// printf( "%s!" , vec[i].getStr() );
@@ -596,12 +596,12 @@ OUString array2String( const css::uno::Sequence< Any > &seq )
}
-std::vector< Any > parseArray( const OUString & str )
+std::vector< Any > parseArray( std::u16string_view str )
{
- int len = str.getLength();
+ size_t len = str.size();
bool doubleQuote = false;
int brackets = 0;
- int i = 0;
+ size_t i = 0;
OUStringBuffer current;
std::vector<Any> elements;
@@ -644,7 +644,7 @@ std::vector< Any > parseArray( const OUString & str )
if( brackets == 0 )
{
if( !current.isEmpty() || doubleQuotedValue )
- elements.push_back( makeAny( current.makeStringAndClear() ) );
+ elements.emplace_back( current.makeStringAndClear() );
}
else
{
@@ -673,7 +673,7 @@ std::vector< Any > parseArray( const OUString & str )
else if( ',' == c && brackets == 1)
{
doubleQuotedValue = false;
- elements.push_back( makeAny( current.makeStringAndClear() ) );
+ elements.emplace_back( current.makeStringAndClear() );
}
else if( isWhitespace( c ) )
{
@@ -840,17 +840,17 @@ OUString getColExprForDefaultSettingVal(ConnectionSettings const *settings)
OUString("pg_get_expr(pg_attrdef.adbin, pg_attrdef.adrelid, true)");
}
-css::uno::Sequence< sal_Int32 > string2intarray( const OUString & str )
+css::uno::Sequence< sal_Int32 > string2intarray( std::u16string_view str )
{
css::uno::Sequence< sal_Int32 > ret;
- const sal_Int32 strlen = str.getLength();
- if( str.getLength() > 1 )
+ const sal_Int32 strlen = str.size();
+ if( strlen > 1 )
{
sal_Int32 start = 0;
sal_uInt32 c;
for (;;)
{
- c = str.iterateCodePoints(&start);
+ c = o3tl::iterateCodePoints(str, &start);
if (!iswspace(c))
break;
if ( start == strlen)
@@ -860,7 +860,7 @@ css::uno::Sequence< sal_Int32 > string2intarray( const OUString & str )
return ret;
for (;;)
{
- c = str.iterateCodePoints(&start);
+ c = o3tl::iterateCodePoints(str, &start);
if ( !iswspace(c) )
break;
if ( start == strlen)
@@ -879,7 +879,7 @@ css::uno::Sequence< sal_Int32 > string2intarray( const OUString & str )
break;
if ( start == strlen)
return ret;
- c=str.iterateCodePoints(&start);
+ c = o3tl::iterateCodePoints(str, &start);
} while ( c );
do
{
@@ -888,20 +888,20 @@ css::uno::Sequence< sal_Int32 > string2intarray( const OUString & str )
if ( start == strlen)
return ret;
digits.append(OUString(&c, 1));
- c = str.iterateCodePoints(&start);
+ c = o3tl::iterateCodePoints(str, &start);
} while ( c );
- vec.push_back( digits.makeStringAndClear().toInt32() );
+ vec.push_back( o3tl::toInt32(digits) );
do
{
if(!iswspace(c))
break;
if ( start == strlen)
return ret;
- c = str.iterateCodePoints(&start);
+ c = o3tl::iterateCodePoints(str, &start);
} while ( c );
if ( c == L'}' )
break;
- if ( str.iterateCodePoints(&start) != L',' )
+ if ( o3tl::iterateCodePoints(str, &start) != L',' )
return ret;
if ( start == strlen)
return ret;
@@ -943,19 +943,17 @@ OUString sqltype2string( const Reference< XPropertySet > & desc )
case css::sdbc::DataType::VARCHAR:
case css::sdbc::DataType::CHAR:
{
- typeName.append( "(" );
- typeName.append( precision );
- typeName.append( ")" );
+ typeName.append( "(" + OUString::number(precision) + ")" );
break;
}
case css::sdbc::DataType::DECIMAL:
case css::sdbc::DataType::NUMERIC:
{
- typeName.append( "(" );
- typeName.append( precision );
- typeName.append( "," );
- typeName.append( extractIntProperty( desc, getStatics().SCALE ) );
- typeName.append( ")" );
+ typeName.append( "("
+ + OUString::number(precision)
+ + ","
+ + OUString::number(extractIntProperty( desc, getStatics().SCALE ))
+ + ")" );
break;
}
default: