Groups | Search | Server Info | Login | Register


Groups > perl.dbd.pg.changes > #18

[DBD::Pg 2/5] Use lookup table for placeholder string

Newsgroups perl.dbd.pg.changes
Subject [DBD::Pg 2/5] Use lookup table for placeholder string
Date 2016-04-18 17:10 +0000
Message-ID <1460999425-22634-2-git-send-email-dbdpg-commits@bucardo.org> (permalink)
References <1460999425-22634-1-git-send-email-dbdpg-commits@bucardo.org>
From dbdpg-commits@bucardo.org

Show all headers | View raw


Committed by =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>

Subject: [DBD::Pg 2/5] Use lookup table for placeholder string

---
 dbdimp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/dbdimp.c b/dbdimp.c
index a8959fc..9e97701 100644
--- a/dbdimp.c
+++ b/dbdimp.c
@@ -1698,6 +1698,10 @@ int dbd_st_prepare_sv (SV * sth, imp_sth_t * imp_sth, SV * statement_sv, SV * at
 } /* end of dbd_st_prepare */
 
 
+static const char *placeholder_string[4] = {
+	"", "?", "$1", ":foo"
+};
+
 /* ================================================================== */
 static void pg_st_split_statement (pTHX_ imp_sth_t * imp_sth, int version, char * statement)
 {
@@ -2066,8 +2070,8 @@ static void pg_st_split_statement (pTHX_ imp_sth_t * imp_sth, int version, char
 		if (placeholder_type!=0) {
 			if (imp_sth->placeholder_type && placeholder_type != imp_sth->placeholder_type)
 				croak("Cannot mix placeholder styles \"%s\" and \"%s\"",
-					  1==imp_sth->placeholder_type ? "?" : 2==imp_sth->placeholder_type ? "$1" : ":foo",
-					  1==placeholder_type ? "?" : 2==placeholder_type ? "$1" : ":foo");
+					  placeholder_string[imp_sth->placeholder_type],
+					  placeholder_string[placeholder_type]);
 		}
 		
 		/* Move on to the next letter unless we found a placeholder, or we are at the end of the string */
-- 
1.8.4

Back to perl.dbd.pg.changes | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

[DBD::Pg 1/5] Factor placeholder key creation into function dbdpg-commits@bucardo.org - 2016-04-18 17:10 +0000
  [DBD::Pg 5/5] Use PG_ASYNC constant for pg_async & test dbdpg-commits@bucardo.org - 2016-04-18 17:10 +0000
  [DBD::Pg 2/5] Use lookup table for placeholder string dbdpg-commits@bucardo.org - 2016-04-18 17:10 +0000
  [DBD::Pg 3/5] Use named enum values for placeholder_type dbdpg-commits@bucardo.org - 2016-04-18 17:10 +0000
  [DBD::Pg 4/5] Use named enum values for pqtype dbdpg-commits@bucardo.org - 2016-04-18 17:10 +0000

csiph-web