1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Update of contrib stuff from massimo.

This commit is contained in:
Bruce Momjian
1997-11-05 21:38:25 +00:00
parent 5aaf00f3f3
commit 951986c550
33 changed files with 2547 additions and 578 deletions

62
contrib/sequence/Makefile Normal file
View File

@ -0,0 +1,62 @@
#-------------------------------------------------------------------------
#
# Makefile--
# Makefile for new sequence functions.
#
#-------------------------------------------------------------------------
PGDIR = ../..
SRCDIR = $(PGDIR)/src
include $(SRCDIR)/Makefile.global
INCLUDE_OPT = -I ./ \
-I $(SRCDIR)/ \
-I $(SRCDIR)/include \
-I $(SRCDIR)/port/$(PORTNAME)
CFLAGS += $(INCLUDE_OPT)
ifeq ($(PORTNAME), linux)
ifdef LINUX_ELF
ifeq ($(CC), gcc)
CFLAGS += -fPIC
endif
endif
endif
ifeq ($(PORTNAME), i386_solaris)
CFLAGS+= -fPIC
endif
MODNAME = set_sequence
MODULE = $(MODNAME)$(DLSUFFIX)
all: module sql
module: $(MODULE)
sql: $(MODNAME).sql
install: $(MODULE)
cp -p $(MODULE) $(LIBDIR)
cd $(LIBDIR); strip $(MODULE)
%.sql: %.sql.in
sed "s|MODULE_PATHNAME|$(LIBDIR)/$(MODULE)|" < $< > $@
.SUFFIXES: $(DLSUFFIX)
%$(DLSUFFIX): %.c
cc $(CFLAGS) -shared -o $@ $<
depend dep:
$(CC) -MM $(INCLUDE_OPT) *.c >depend
clean:
rm -f $(MODULE) $(MODNAME).sql
ifeq (depend,$(wildcard depend))
include depend
endif

View File

@ -0,0 +1,41 @@
/*
* set_sequence.c --
*
* Set a new sequence value.
*
* Copyright (c) 1996, Massimo Dal Zotto <dz@cs.unitn.it>
*/
#include "postgres.h"
#include "nodes/parsenodes.h"
#include "commands/sequence.h"
#include "set_sequence.h"
extern int setval(struct varlena *seqin, int4 val);
int
set_currval(struct varlena *sequence, int4 nextval)
{
return setval(sequence, nextval);
}
int
next_id(struct varlena *sequence)
{
return nextval(sequence);
}
int
last_id(struct varlena *sequence)
{
return currval(sequence);
}
int
set_last_id(struct varlena *sequence, int4 nextval)
{
return setval(sequence, nextval);
}
/* end of file */

View File

@ -0,0 +1,9 @@
#ifndef SET_SEQUENCE_H
#define SET_SEQUENCE_H
int set_currval(struct varlena *sequence, int4 nextval);
int next_id(struct varlena *sequence);
int last_id(struct varlena *sequence);
int set_last_id(struct varlena *sequence, int4 nextval);
#endif

View File

@ -0,0 +1,33 @@
-- SQL code to define new sequence utilities
-- Set a new sequence value
--
create function set_currval(text, int4) returns int4
as 'MODULE_PATHNAME'
language 'C';
-- Increment the value of sequence
--
-- select next_id('sequence_name');
--
create function next_id(text) returns int4
as 'MODULE_PATHNAME'
language 'C';
-- Return the last value set for a sequence
--
-- select last_id('sequence_name');
--
create function last_id(text) returns int4
as 'MODULE_PATHNAME'
language 'C';
-- Set the current value of a sequence
--
-- select set_last_id('sequence_name', 1);
--
create function set_last_id(text,int4) returns int4
as 'MODULE_PATHNAME'
language 'C';
-- end of file