[PATCH] Rewrite as a static table of keywords and loop over these ke...

Anthony Youngman (via Code Review) gerrit at gerrit.libreoffice.org
Fri Apr 26 01:20:49 PDT 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3614

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/14/3614/1

Rewrite as a static table of keywords and loop over these keywords

This patch creates a static list of keywords which can easily be added
to.
It currently contains a compile error - the call the matchIgnoreAsciiCaseAsciiL
fails.
It also needs testing as I don't have PostgreSQL on this machine.

Change-Id: Ib581b3e834a57e0dfa9d139bcb4ae7a0a52a5472
---
M connectivity/source/drivers/postgresql/pq_connection.cxx
1 file changed, 25 insertions(+), 33 deletions(-)



diff --git a/connectivity/source/drivers/postgresql/pq_connection.cxx b/connectivity/source/drivers/postgresql/pq_connection.cxx
index 4bc15e4..b17ad9f 100644
--- a/connectivity/source/drivers/postgresql/pq_connection.cxx
+++ b/connectivity/source/drivers/postgresql/pq_connection.cxx
@@ -482,44 +482,31 @@
     // 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" ) ) )
+        bool append = false;
+        for( int j = 0; j < (int) ( sizeof( keyword_list ) / sizeof( char * )); j++)
         {
-            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" ) ) )
-        {
-            keywords.push_back( "requiressl", SAL_NO_ACQUIRE );
-        }
-        else
-        {
+            if( args[i].Name.matchIgnoreAsciiCaseAsciiL( keyword_list[j] ))
+            {
+                keywords.push_back( keyword_list[j], SAL_NO_ACQUIRE );
+                append = true;
+                break;
+            }
             append = false;
-            // ignore for now
-            OSL_TRACE("sdbc-postgresql: unknown argument '%s'", OUStringToOString( args[i].Name, RTL_TEXTENCODING_UTF8 ).getStr() );
         }
+
         if( append )
         {
             OUString value;
@@ -527,6 +514,11 @@
             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() );
+        }
     }
 }
 

-- 
To view, visit https://gerrit.libreoffice.org/3614
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib581b3e834a57e0dfa9d139bcb4ae7a0a52a5472
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Anthony Youngman <anthony at youngman.org.uk>



More information about the LibreOffice mailing list