? .deps
? current.diff
? dblink.sql
? libdblink.so.0.0
? reproduce-bug.sql
? results
Index: README.dblink
===================================================================
RCS file: /cvsroot/pgsql/contrib/dblink/README.dblink,v
retrieving revision 1.12
diff -c -r1.12 README.dblink
*** README.dblink	1 Jan 2005 20:44:11 -0000	1.12
--- README.dblink	3 Jan 2006 18:14:55 -0000
***************
*** 8,14 ****
   * Darko Prenosil <Darko.Prenosil@finteh.hr>
   * Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
   *
!  * Copyright (c) 2001-2005, PostgreSQL Global Development Group
   * ALL RIGHTS RESERVED;
   * 
   * Permission to use, copy, modify, and distribute this software and its
--- 8,14 ----
   * Darko Prenosil <Darko.Prenosil@finteh.hr>
   * Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
   *
!  * Copyright (c) 2001-2006, PostgreSQL Global Development Group
   * ALL RIGHTS RESERVED;
   * 
   * Permission to use, copy, modify, and distribute this software and its
Index: dblink.c
===================================================================
RCS file: /cvsroot/pgsql/contrib/dblink/dblink.c,v
retrieving revision 1.50
diff -c -r1.50 dblink.c
*** dblink.c	22 Nov 2005 18:17:04 -0000	1.50
--- dblink.c	3 Jan 2006 18:14:56 -0000
***************
*** 8,14 ****
   * Darko Prenosil <Darko.Prenosil@finteh.hr>
   * Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
   *
!  * Copyright (c) 2001-2005, PostgreSQL Global Development Group
   * ALL RIGHTS RESERVED;
   *
   * Permission to use, copy, modify, and distribute this software and its
--- 8,14 ----
   * Darko Prenosil <Darko.Prenosil@finteh.hr>
   * Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
   *
!  * Copyright (c) 2001-2006, PostgreSQL Global Development Group
   * ALL RIGHTS RESERVED;
   *
   * Permission to use, copy, modify, and distribute this software and its
***************
*** 579,592 ****
  		/* got results, keep track of them */
  		funcctx->user_fctx = res;
  
- 		/* fast track when no results */
- 		if (funcctx->max_calls < 1)
- 		{
- 			if (res)
- 				PQclear(res);
- 			SRF_RETURN_DONE(funcctx);
- 		}
- 
  		/* get a tuple descriptor for our result type */
  		switch (get_call_result_type(fcinfo, NULL, &tupdesc))
  		{
--- 579,584 ----
***************
*** 609,614 ****
--- 601,647 ----
  		/* make sure we have a persistent copy of the tupdesc */
  		tupdesc = CreateTupleDescCopy(tupdesc);
  
+ 		/* check result and tuple descriptor have the same number of columns */
+ 		if (PQnfields(res) != tupdesc->natts)
+ 		{
+ 			if (funcctx->max_calls > 0)
+ 			{
+ 				StringInfo	movestr = makeStringInfo();
+ 				int		moveback;
+ 
+ 				if (howmany == funcctx->max_calls)
+ 					moveback = funcctx->max_calls;
+ 				else
+ 					moveback = funcctx->max_calls + 1;
+ 	
+ 				appendStringInfo(movestr, "MOVE BACKWARD %d FROM %s", moveback, curname);
+ 				res = PQexec(conn, movestr->data);
+ 				if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
+ 				{
+ 					if (fail)
+ 						DBLINK_RES_ERROR("sql error");
+ 					else
+ 					{
+ 						DBLINK_RES_ERROR_AS_NOTICE("sql error");
+ 						SRF_RETURN_DONE(funcctx);
+ 					}
+ 				}
+ 			}
+ 
+ 			ereport(ERROR,
+ 					(errcode(ERRCODE_DATATYPE_MISMATCH),
+ 				errmsg("remote query result rowtype does not match "
+ 						"the specified FROM clause rowtype")));
+ 		}
+ 
+ 		/* fast track when no results */
+ 		if (funcctx->max_calls < 1)
+ 		{
+ 			if (res)
+ 				PQclear(res);
+ 			SRF_RETURN_DONE(funcctx);
+ 		}
+ 
  		/* store needed metadata for subsequent calls */
  		attinmeta = TupleDescGetAttInMetadata(tupdesc);
  		funcctx->attinmeta = attinmeta;
***************
*** 778,791 ****
  		if (freeconn)
  			PQfinish(conn);
  
- 		/* fast track when no results */
- 		if (funcctx->max_calls < 1)
- 		{
- 			if (res)
- 				PQclear(res);
- 			SRF_RETURN_DONE(funcctx);
- 		}
- 
  		if (!is_sql_cmd)
  		{
  			/* get a tuple descriptor for our result type */
--- 811,816 ----
***************
*** 811,816 ****
--- 836,856 ----
  			tupdesc = CreateTupleDescCopy(tupdesc);
  		}
  
+ 		/* check result and tuple descriptor have the same number of columns */
+ 		if (PQnfields(res) != tupdesc->natts)
+ 			ereport(ERROR,
+ 					(errcode(ERRCODE_DATATYPE_MISMATCH),
+ 				errmsg("remote query result rowtype does not match "
+ 						"the specified FROM clause rowtype")));
+ 
+ 		/* fast track when no results */
+ 		if (funcctx->max_calls < 1)
+ 		{
+ 			if (res)
+ 				PQclear(res);
+ 			SRF_RETURN_DONE(funcctx);
+ 		}
+ 
  		/* store needed metadata for subsequent calls */
  		attinmeta = TupleDescGetAttInMetadata(tupdesc);
  		funcctx->attinmeta = attinmeta;
Index: dblink.h
===================================================================
RCS file: /cvsroot/pgsql/contrib/dblink/dblink.h,v
retrieving revision 1.13
diff -c -r1.13 dblink.h
*** dblink.h	1 Jan 2005 05:43:05 -0000	1.13
--- dblink.h	3 Jan 2006 18:14:56 -0000
***************
*** 8,14 ****
   * Darko Prenosil <Darko.Prenosil@finteh.hr>
   * Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
   *
!  * Copyright (c) 2001-2005, PostgreSQL Global Development Group
   * ALL RIGHTS RESERVED;
   *
   * Permission to use, copy, modify, and distribute this software and its
--- 8,14 ----
   * Darko Prenosil <Darko.Prenosil@finteh.hr>
   * Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
   *
!  * Copyright (c) 2001-2006, PostgreSQL Global Development Group
   * ALL RIGHTS RESERVED;
   *
   * Permission to use, copy, modify, and distribute this software and its
