Example #1
0
static int luaP_cursormove (lua_State *L) {
  luaP_Cursor *c = (luaP_Cursor *) luaP_checkudata(L, 1, PLLUA_CURSORMT);
  luaP_TRY {
    SPI_cursor_move(c->cursor, 1, luaL_optlong(L, 2, 0));
  } luaP_CATCH;
  return 0;
}
Example #2
0
void
plr_SPI_cursor_move(SEXP cursor_in,SEXP forward_in, SEXP rows_in)
{
	Portal				portal=NULL;
	MemoryContext		oldcontext;
	int					forward;
	int					rows;
	PREPARE_PG_TRY;
	PUSH_PLERRCONTEXT(rsupport_error_callback, "pg.spi.cursor_move");

	portal = R_ExternalPtrAddr(cursor_in);
	if(!IS_LOGICAL(forward_in))
	{
		error("pg.spi.cursor_move arg2 must be boolean");
		return;
	}
	if(!IS_INTEGER(rows_in))
	{
		error("pg.spi.cursor_move arg3 must be an integer");
		return;
	}
	forward = LOGICAL(forward_in)[0];
	rows  = INTEGER(rows_in)[0];

	/* switch to SPI memory context */
	oldcontext = MemoryContextSwitchTo(plr_SPI_context);
	PG_TRY();
	{
		/* Open the cursor */
		SPI_cursor_move(portal, forward, rows);
	}
	PLR_PG_CATCH();
	PLR_PG_END_TRY();

	/* back to caller's	 memory context */
	MemoryContextSwitchTo(oldcontext);
}