diff options
author | Wol <anthony@youngman.org.uk> | 2013-04-16 13:30:30 +0100 |
---|---|---|
committer | Lionel Elie Mamane <lionel@mamane.lu> | 2013-04-29 10:20:32 +0200 |
commit | 8ad743ca8d45e094e433627cf0cf70d11a56084e (patch) | |
tree | b2db32cb42f28e02fac3263b6828aad8a659bdc7 /connectivity | |
parent | 13a0477250793d1ab06329b244f26fffbebb0bab (diff) |
pgsql-sdbc: conninfo keywords as static table instead of series of "else if"
New keywords can now simply be added to a static array rather than
adding a new "else if" blocks for each keyword.
Change-Id: Ib581b3e834a57e0dfa9d139bcb4ae7a0a52a5472
Diffstat (limited to 'connectivity')
-rw-r--r-- | connectivity/source/drivers/postgresql/pq_connection.cxx | 59 |
1 files changed, 25 insertions, 34 deletions
diff --git a/connectivity/source/drivers/postgresql/pq_connection.cxx b/connectivity/source/drivers/postgresql/pq_connection.cxx index 4bc15e4d0646..4f830a1459ea 100644 --- a/connectivity/source/drivers/postgresql/pq_connection.cxx +++ b/connectivity/source/drivers/postgresql/pq_connection.cxx @@ -482,44 +482,30 @@ static void properties2arrays( const Sequence< PropertyValue > & args, // I.e. they are prefiltered to have only relevant ones? // Else, at least support all keywords from // http://www.postgresql.org/docs/9.0/interactive/libpq-connect.html + + static const char* keyword_list[] = { + "password", + "user", + "port", + "dbname", + "connect_timeout", + "options", + "requiressl" + }; + for( int i = 0; i < args.getLength() ; ++i ) { - bool append = true; - // TODO: rewrite this as a static table of keywords, and a loop over these keywords. - if( args[i].Name.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "password" ) ) ) - { - keywords.push_back( "password", SAL_NO_ACQUIRE ); - } - else if( args[i].Name.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "user" ) ) ) - { - keywords.push_back( "user", SAL_NO_ACQUIRE ); - } - else if( args[i].Name.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "port" ) ) ) - { - keywords.push_back( "port", SAL_NO_ACQUIRE ); - } - else if( args[i].Name.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "dbname" ) ) ) - { - keywords.push_back( "dbname", SAL_NO_ACQUIRE ); - } - else if( args[i].Name.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "connect_timeout" ) ) ) - { - keywords.push_back( "connect_timeout", SAL_NO_ACQUIRE ); - } - else if( args[i].Name.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "options" ) ) ) - { - keywords.push_back( "options", SAL_NO_ACQUIRE ); - } - else if( args[i].Name.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "requiressl" ) ) ) + bool append = false; + for( size_t j = 0; j < SAL_N_ELEMENTS( keyword_list ); j++) { - keywords.push_back( "requiressl", SAL_NO_ACQUIRE ); - } - else - { - append = false; - // ignore for now - OSL_TRACE("sdbc-postgresql: unknown argument '%s'", OUStringToOString( args[i].Name, RTL_TEXTENCODING_UTF8 ).getStr() ); + if( args[i].Name.equalsIgnoreAsciiCaseAscii( keyword_list[j] )) + { + keywords.push_back( keyword_list[j], SAL_NO_ACQUIRE ); + append = true; + break; + } } + if( append ) { OUString value; @@ -527,6 +513,11 @@ static void properties2arrays( const Sequence< PropertyValue > & args, char *v = strdup(OUStringToOString(value, enc).getStr()); values.push_back ( v ); } + else + { + // ignore for now + OSL_TRACE("sdbc-postgresql: unknown argument '%s'", OUStringToOString( args[i].Name, RTL_TEXTENCODING_UTF8 ).getStr() ); + } } } |