From 2d76622c655294b2e6b54fab606ab9c1501c17f0 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Thu, 4 Dec 2014 16:48:22 +0900
Subject: [PATCH 2/2] rename PGConn variable

---
 contrib/postgres_fdw/connection.c   | 46 ++++++++++++++++++-------------------
 contrib/postgres_fdw/postgres_fdw.c | 40 ++++++++++++++++----------------
 contrib/postgres_fdw/postgres_fdw.h |  2 +-
 3 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 8b1c738..3d5c8dc 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -167,12 +167,12 @@ GetConnection(ForeignServer *server, UserMapping *user,
 												 sizeof(PgFdwConn));
 		
 		elog(DEBUG3, "new postgres_fdw connection %p for server \"%s\"",
-			 entry->conn->conn, server->servername);
+			 entry->conn->pgconn, server->servername);
 	}
 
-	if (entry->conn->conn == NULL)
+	if (entry->conn->pgconn == NULL)
 	{
-		entry->conn->conn = connect_pg_server(server, user);
+		entry->conn->pgconn = connect_pg_server(server, user);
 		entry->conn->nscans = 0;
 		entry->conn->async_state = PGFDW_CONN_IDLE;
 		entry->conn->async_scan = NULL;
@@ -378,7 +378,7 @@ do_sql_command(PGconn *conn, const char *sql)
 	{
 		PgFdwConn tmpfdwconn;
 
-		tmpfdwconn.conn = conn;
+		tmpfdwconn.pgconn = conn;
 		pgfdw_report_error(ERROR, res, &tmpfdwconn, true, sql);
 	}
 	PQclear(res);
@@ -411,7 +411,7 @@ begin_remote_xact(ConnCacheEntry *entry)
 			sql = "START TRANSACTION ISOLATION LEVEL SERIALIZABLE";
 		else
 			sql = "START TRANSACTION ISOLATION LEVEL REPEATABLE READ";
-		do_sql_command(entry->conn->conn, sql);
+		do_sql_command(entry->conn->pgconn, sql);
 		entry->xact_depth = 1;
 	}
 
@@ -425,7 +425,7 @@ begin_remote_xact(ConnCacheEntry *entry)
 		char		sql[64];
 
 		snprintf(sql, sizeof(sql), "SAVEPOINT s%d", entry->xact_depth + 1);
-		do_sql_command(entry->conn->conn, sql);
+		do_sql_command(entry->conn->pgconn, sql);
 		entry->xact_depth++;
 	}
 }
@@ -516,7 +516,7 @@ pgfdw_report_error(int elevel, PGresult *res, PgFdwConn *conn,
 		 * return NULL, not a PGresult at all.
 		 */
 		if (message_primary == NULL)
-			message_primary = PQerrorMessage(conn->conn);
+			message_primary = PQerrorMessage(conn->pgconn);
 
 		ereport(elevel,
 				(errcode(sqlstate),
@@ -561,20 +561,20 @@ pgfdw_xact_callback(XactEvent event, void *arg)
 		PGresult   *res;
 
 		/* Ignore cache entry if no open connection right now */
-		if (entry->conn->conn == NULL)
+		if (entry->conn->pgconn == NULL)
 			continue;
 
 		/* If it has an open remote transaction, try to close it */
 		if (entry->xact_depth > 0)
 		{
 			elog(DEBUG3, "closing remote transaction on connection %p",
-				 entry->conn->conn);
+				 entry->conn->pgconn);
 
 			switch (event)
 			{
 				case XACT_EVENT_PRE_COMMIT:
 					/* Commit all remote transactions during pre-commit */
-					do_sql_command(entry->conn->conn, "COMMIT TRANSACTION");
+					do_sql_command(entry->conn->pgconn, "COMMIT TRANSACTION");
 
 					/*
 					 * If there were any errors in subtransactions, and we
@@ -593,7 +593,7 @@ pgfdw_xact_callback(XactEvent event, void *arg)
 					 */
 					if (entry->have_prep_stmt && entry->have_error)
 					{
-						res = PQexec(entry->conn->conn, "DEALLOCATE ALL");
+						res = PQexec(entry->conn->pgconn, "DEALLOCATE ALL");
 						PQclear(res);
 					}
 					entry->have_prep_stmt = false;
@@ -623,7 +623,7 @@ pgfdw_xact_callback(XactEvent event, void *arg)
 					/* Assume we might have lost track of prepared statements */
 					entry->have_error = true;
 					/* If we're aborting, abort all remote transactions too */
-					res = PQexec(entry->conn->conn, "ABORT TRANSACTION");
+					res = PQexec(entry->conn->pgconn, "ABORT TRANSACTION");
 					/* Note: can't throw ERROR, it would be infinite loop */
 					if (PQresultStatus(res) != PGRES_COMMAND_OK)
 						pgfdw_report_error(WARNING, res, entry->conn, true,
@@ -634,7 +634,7 @@ pgfdw_xact_callback(XactEvent event, void *arg)
 						/* As above, make sure to clear any prepared stmts */
 						if (entry->have_prep_stmt && entry->have_error)
 						{
-							res = PQexec(entry->conn->conn, "DEALLOCATE ALL");
+							res = PQexec(entry->conn->pgconn, "DEALLOCATE ALL");
 							PQclear(res);
 						}
 						entry->have_prep_stmt = false;
@@ -653,12 +653,12 @@ pgfdw_xact_callback(XactEvent event, void *arg)
 		 * If the connection isn't in a good idle state, discard it to
 		 * recover. Next GetConnection will open a new connection.
 		 */
-		if (PQstatus(entry->conn->conn) != CONNECTION_OK ||
-			PQtransactionStatus(entry->conn->conn) != PQTRANS_IDLE)
+		if (PQstatus(entry->conn->pgconn) != CONNECTION_OK ||
+			PQtransactionStatus(entry->conn->pgconn) != PQTRANS_IDLE)
 		{
-			elog(DEBUG3, "discarding connection %p", entry->conn->conn);
-			PQfinish(entry->conn->conn);
-			entry->conn->conn = NULL;
+			elog(DEBUG3, "discarding connection %p", entry->conn->pgconn);
+			PQfinish(entry->conn->pgconn);
+			entry->conn->pgconn = NULL;
 		}
 	}
 
@@ -705,8 +705,8 @@ pgfdw_subxact_callback(SubXactEvent event, SubTransactionId mySubid,
 		char		sql[100];
 
 		/* Shut down asynchronous scan if running */
-		if (entry->conn->async_scan && PQisBusy(entry->conn->conn))
-			PQconsumeInput(entry->conn->conn);
+		if (entry->conn->async_scan && PQisBusy(entry->conn->pgconn))
+			PQconsumeInput(entry->conn->pgconn);
 		entry->conn->async_scan = NULL;
 		entry->conn->async_state = PGFDW_CONN_IDLE;
 		entry->conn->nscans = 0;
@@ -715,7 +715,7 @@ pgfdw_subxact_callback(SubXactEvent event, SubTransactionId mySubid,
 		 * We only care about connections with open remote subtransactions of
 		 * the current level.
 		 */
-		if (entry->conn->conn == NULL || entry->xact_depth < curlevel)
+		if (entry->conn->pgconn == NULL || entry->xact_depth < curlevel)
 			continue;
 
 		if (entry->xact_depth > curlevel)
@@ -726,7 +726,7 @@ pgfdw_subxact_callback(SubXactEvent event, SubTransactionId mySubid,
 		{
 			/* Commit all remote subtransactions during pre-commit */
 			snprintf(sql, sizeof(sql), "RELEASE SAVEPOINT s%d", curlevel);
-			do_sql_command(entry->conn->conn, sql);
+			do_sql_command(entry->conn->pgconn, sql);
 		}
 		else
 		{
@@ -736,7 +736,7 @@ pgfdw_subxact_callback(SubXactEvent event, SubTransactionId mySubid,
 			snprintf(sql, sizeof(sql),
 					 "ROLLBACK TO SAVEPOINT s%d; RELEASE SAVEPOINT s%d",
 					 curlevel, curlevel);
-			res = PQexec(entry->conn->conn, sql);
+			res = PQexec(entry->conn->pgconn, sql);
 			if (PQresultStatus(res) != PGRES_COMMAND_OK)
 				pgfdw_report_error(WARNING, res, entry->conn, true, sql);
 			else
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index b912091..e82ec82 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -1077,7 +1077,7 @@ postgresReScanForeignScan(ForeignScanState *node)
 	 * We don't use a PG_TRY block here, so be careful not to throw error
 	 * without releasing the PGresult.
 	 */
-	res = PQexec(fsstate->conn->conn, sql);
+	res = PQexec(fsstate->conn->pgconn, sql);
 	if (PQresultStatus(res) != PGRES_COMMAND_OK)
 		pgfdw_report_error(ERROR, res, fsstate->conn, true, sql);
 	PQclear(res);
@@ -1406,7 +1406,7 @@ postgresExecForeignInsert(EState *estate,
 	 * We don't use a PG_TRY block here, so be careful not to throw error
 	 * without releasing the PGresult.
 	 */
-	res = PQexecPrepared(fmstate->conn->conn,
+	res = PQexecPrepared(fmstate->conn->pgconn,
 						 fmstate->p_name,
 						 fmstate->p_nums,
 						 p_values,
@@ -1476,7 +1476,7 @@ postgresExecForeignUpdate(EState *estate,
 	 * We don't use a PG_TRY block here, so be careful not to throw error
 	 * without releasing the PGresult.
 	 */
-	res = PQexecPrepared(fmstate->conn->conn,
+	res = PQexecPrepared(fmstate->conn->pgconn,
 						 fmstate->p_name,
 						 fmstate->p_nums,
 						 p_values,
@@ -1546,7 +1546,7 @@ postgresExecForeignDelete(EState *estate,
 	 * We don't use a PG_TRY block here, so be careful not to throw error
 	 * without releasing the PGresult.
 	 */
-	res = PQexecPrepared(fmstate->conn->conn,
+	res = PQexecPrepared(fmstate->conn->pgconn,
 						 fmstate->p_name,
 						 fmstate->p_nums,
 						 p_values,
@@ -1602,7 +1602,7 @@ postgresEndForeignModify(EState *estate,
 		 * We don't use a PG_TRY block here, so be careful not to throw error
 		 * without releasing the PGresult.
 		 */
-		res = PQexec(fmstate->conn->conn, sql);
+		res = PQexec(fmstate->conn->pgconn, sql);
 		if (PQresultStatus(res) != PGRES_COMMAND_OK)
 			pgfdw_report_error(ERROR, res, fmstate->conn, true, sql);
 		PQclear(res);
@@ -1860,7 +1860,7 @@ get_remote_estimate(const char *sql, PgFdwConn *conn,
 		/*
 		 * Execute EXPLAIN remotely.
 		 */
-		res = PQexec(conn->conn, sql);
+		res = PQexec(conn->pgconn, sql);
 		if (PQresultStatus(res) != PGRES_TUPLES_OK)
 			pgfdw_report_error(ERROR, res, conn, false, sql);
 
@@ -1992,7 +1992,7 @@ create_cursor(PgFdwScanState *fsstate)
 	 * We don't use a PG_TRY block here, so be careful not to throw error
 	 * without releasing the PGresult.
 	 */
-	res = PQexecParams(conn->conn, buf.data, numParams, NULL, values,
+	res = PQexecParams(conn->pgconn, buf.data, numParams, NULL, values,
 					   NULL, NULL, 0);
 	if (PQresultStatus(res) != PGRES_COMMAND_OK)
 		pgfdw_report_error(ERROR, res, conn, true, fsstate->query);
@@ -2055,7 +2055,7 @@ fetch_more_data(PgFdwScanState *fsstate)
 			{
 				conn->async_scan = fsstate;
 
-				if (!PQsendQuery(conn->conn, sql))
+				if (!PQsendQuery(conn->pgconn, sql))
 					pgfdw_report_error(ERROR, res, conn, false,
 									   fsstate->query);
 
@@ -2065,13 +2065,13 @@ fetch_more_data(PgFdwScanState *fsstate)
 
 			/* Synchronous query execution */
 			conn->async_state = PGFDW_CONN_SYNC_RUNNING;
-			res = PQexec(conn->conn, sql);
+			res = PQexec(conn->pgconn, sql);
 			break;
 
 		case PGFDW_CONN_ASYNC_RUNNING:
 			Assert(conn->async_scan != NULL);
 
-			res = PQgetResult(conn->conn);
+			res = PQgetResult(conn->pgconn);
 			if (PQntuples(res) == fetch_size)
 			{
 				/*
@@ -2080,7 +2080,7 @@ fetch_more_data(PgFdwScanState *fsstate)
 				 * more PQgetResult() is needed to reset the state to
 				 * IDLE.  See PQexecFinish() for details.
 				 */
-				if (PQgetResult(conn->conn) != NULL)
+				if (PQgetResult(conn->pgconn) != NULL)
 					elog(ERROR, "Connection status error.");
 			}
 
@@ -2140,7 +2140,7 @@ fetch_more_data(PgFdwScanState *fsstate)
 				 * We can immediately request the next bunch of tuples if
 				 * we're on asynchronous connection.
 				 */
-				if (!PQsendQuery(conn->conn, sql))
+				if (!PQsendQuery(conn->pgconn, sql))
 					pgfdw_report_error(ERROR, res, conn, false, fsstate->query);
 			}
 			else
@@ -2254,7 +2254,7 @@ close_cursor(PgFdwConn *conn, unsigned int cursor_number)
 	 * We don't use a PG_TRY block here, so be careful not to throw error
 	 * without releasing the PGresult.
 	 */
-	res = PQexec(conn->conn, sql);
+	res = PQexec(conn->pgconn, sql);
 	if (PQresultStatus(res) != PGRES_COMMAND_OK)
 		pgfdw_report_error(ERROR, res, conn, true, sql);
 	PQclear(res);
@@ -2286,7 +2286,7 @@ prepare_foreign_modify(PgFdwModifyState *fmstate)
 	 * We don't use a PG_TRY block here, so be careful not to throw error
 	 * without releasing the PGresult.
 	 */
-	res = PQprepare(fmstate->conn->conn,
+	res = PQprepare(fmstate->conn->pgconn,
 					p_name,
 					fmstate->query,
 					0,
@@ -2440,7 +2440,7 @@ postgresAnalyzeForeignTable(Relation relation,
 	/* In what follows, do not risk leaking any PGresults. */
 	PG_TRY();
 	{
-		res = PQexec(conn->conn, sql.data);
+		res = PQexec(conn->pgconn, sql.data);
 		if (PQresultStatus(res) != PGRES_TUPLES_OK)
 			pgfdw_report_error(ERROR, res, conn, false, sql.data);
 
@@ -2534,7 +2534,7 @@ postgresAcquireSampleRowsFunc(Relation relation, int elevel,
 	/* In what follows, do not risk leaking any PGresults. */
 	PG_TRY();
 	{
-		res = PQexec(conn->conn, sql.data);
+		res = PQexec(conn->pgconn, sql.data);
 		if (PQresultStatus(res) != PGRES_COMMAND_OK)
 			pgfdw_report_error(ERROR, res, conn, false, sql.data);
 		PQclear(res);
@@ -2564,7 +2564,7 @@ postgresAcquireSampleRowsFunc(Relation relation, int elevel,
 			snprintf(fetch_sql, sizeof(fetch_sql), "FETCH %d FROM c%u",
 					 fetch_size, cursor_number);
 
-			res = PQexec(conn->conn, fetch_sql);
+			res = PQexec(conn->pgconn, fetch_sql);
 			/* On error, report the original query, not the FETCH. */
 			if (PQresultStatus(res) != PGRES_TUPLES_OK)
 				pgfdw_report_error(ERROR, res, conn, false, sql.data);
@@ -2726,7 +2726,7 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
 	conn = GetConnection(server, mapping, false);
 
 	/* Don't attempt to import collation if remote server hasn't got it */
-	if (PQserverVersion(conn->conn) < 90100)
+	if (PQserverVersion(conn->pgconn) < 90100)
 		import_collate = false;
 
 	/* Create workspace for strings */
@@ -2739,7 +2739,7 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
 		appendStringInfoString(&buf, "SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname = ");
 		deparseStringLiteral(&buf, stmt->remote_schema);
 
-		res = PQexec(conn->conn, buf.data);
+		res = PQexec(conn->pgconn, buf.data);
 		if (PQresultStatus(res) != PGRES_TUPLES_OK)
 			pgfdw_report_error(ERROR, res, conn, false, buf.data);
 
@@ -2834,7 +2834,7 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
 		appendStringInfo(&buf, " ORDER BY c.relname, a.attnum");
 
 		/* Fetch the data */
-		res = PQexec(conn->conn, buf.data);
+		res = PQexec(conn->pgconn, buf.data);
 		if (PQresultStatus(res) != PGRES_TUPLES_OK)
 			pgfdw_report_error(ERROR, res, conn, false, buf.data);
 
diff --git a/contrib/postgres_fdw/postgres_fdw.h b/contrib/postgres_fdw/postgres_fdw.h
index 2472451..5dfc04a 100644
--- a/contrib/postgres_fdw/postgres_fdw.h
+++ b/contrib/postgres_fdw/postgres_fdw.h
@@ -29,7 +29,7 @@ typedef enum PgFdwConnState
 
 typedef struct PgFdwConn
 {
-	PGconn *conn;
+	PGconn *pgconn;
 	int		nscans;
 	PgFdwConnState	async_state;
 	struct PgFdwScanState *async_scan;
-- 
2.1.0.GIT

