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

2013-04-26 Thread Anthony Youngman (via Code Review)
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 anth...@youngman.org.uk

___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


[PATCH] Rewrite as a static table of keywords and loop over them

2013-04-26 Thread Anthony Youngman (via Code Review)
Hi,

I have submitted a patch for review:

https://gerrit.libreoffice.org/3615

To pull it, you can do:

git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/15/3615/1

Rewrite as a static table of keywords and loop over them

This patch implements a TODO so that new keywords can simply be added to
a static array rather than new else if blocks being added one per
keyword

Change-Id: I8aa4ff0f39166014c299783203eb646817b1399c
---
M connectivity/source/drivers/postgresql/pq_connection.cxx
1 file changed, 3 insertions(+), 2 deletions(-)



diff --git a/connectivity/source/drivers/postgresql/pq_connection.cxx 
b/connectivity/source/drivers/postgresql/pq_connection.cxx
index b17ad9f..f0d9e03 100644
--- a/connectivity/source/drivers/postgresql/pq_connection.cxx
+++ b/connectivity/source/drivers/postgresql/pq_connection.cxx
@@ -496,9 +496,10 @@
 for( int i = 0; i  args.getLength() ; ++i )
 {
 bool append = false;
-for( int j = 0; j  (int) ( sizeof( keyword_list ) / sizeof( char * 
)); j++)
+//for( int j = 0; j  (int) ( sizeof( keyword_list ) / sizeof( char * 
)); j++)
+for( int j = 0; j  (int) SAL_N_ELEMENTS( keyword_list ); j++)
 {
-if( args[i].Name.matchIgnoreAsciiCaseAsciiL( keyword_list[j] ))
+if( args[i].Name.equalsIgnoreAsciiCaseAscii( keyword_list[j] ))
 {
 keywords.push_back( keyword_list[j], SAL_NO_ACQUIRE );
 append = true;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8aa4ff0f39166014c299783203eb646817b1399c
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Anthony Youngman anth...@youngman.org.uk

___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


[PATCH] Change j type to size_t

2013-04-26 Thread Anthony Youngman (via Code Review)
Hi,

I have submitted a patch for review:

https://gerrit.libreoffice.org/3616

To pull it, you can do:

git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/16/3616/1

Change j type to size_t

Change-Id: If04e33228162baab392906903a574f1a6e7a6110
---
M connectivity/source/drivers/postgresql/pq_connection.cxx
1 file changed, 1 insertion(+), 3 deletions(-)



diff --git a/connectivity/source/drivers/postgresql/pq_connection.cxx 
b/connectivity/source/drivers/postgresql/pq_connection.cxx
index f0d9e03..4f830a1 100644
--- a/connectivity/source/drivers/postgresql/pq_connection.cxx
+++ b/connectivity/source/drivers/postgresql/pq_connection.cxx
@@ -496,8 +496,7 @@
 for( int i = 0; i  args.getLength() ; ++i )
 {
 bool append = false;
-//for( int j = 0; j  (int) ( sizeof( keyword_list ) / sizeof( char * 
)); j++)
-for( int j = 0; j  (int) SAL_N_ELEMENTS( keyword_list ); j++)
+for( size_t j = 0; j  SAL_N_ELEMENTS( keyword_list ); j++)
 {
 if( args[i].Name.equalsIgnoreAsciiCaseAscii( keyword_list[j] ))
 {
@@ -505,7 +504,6 @@
 append = true;
 break;
 }
-append = false;
 }
 
 if( append )

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If04e33228162baab392906903a574f1a6e7a6110
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Anthony Youngman anth...@youngman.org.uk

___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice