Tja. conclusie: alleen doen als we allerlei matrix ops introduceren, anders
niet goed te doen met redelijke code.

# Invocations should pass one str on REQ containing a list of attribute names
# to be associated with the newly created state attribute.

str="insert into state (atr0, atr1, atr2, atr3, atr4, atr5, atr6, atr7,
                   val0, val1, val2, val3, val4, val5, val6, val7)
	    values ('Calling-Station-Id', 'REP-MD5-Challenge', '','','','')"
str="Calling-Station-Id,REP-MD5-Challenge",



		   atr1, val1,
		   atr2, val2, ...)
values ('

function NEWSTATE (
	Sql(F:str = "insert into state (val0, val1, val2, val3, 
				        val4, val5, val6, val7)
		     values (?, ?, ?, ?, ?, ?, ?, ?)",
	    str := REQ:str . "/str=state_id_seq"),
	delall str,
	del REP:int,
	str := random 8 . str,
	State := str . str hmacmd5 Process-Secret,
	del REP:str
),


# Invocations should pass one State on REQ; the function will retrieve a 
# list of attributes. How can we make that list variable? We'd like to make
# it dependent on whatever's stored (ie. names in DB, either in separate
# columns or by storing vertically). Problem with vertical is that it can't
# be done with one insert. 

function GETSTATE (

	State exists or return 0,

	str = -16 firstof State,
	16 lastof State == REQ:str hmacmd5 Process-Secret or (
		Log-Line := REP:Log-Line . " - State signature mismatch!",
		ABORT
	),
	REQ:State := -8 lastof REQ:str, del REQ:str,

	Sql(str = "select atr0 as attribute, val0, 
			  atr1 as attribute, val1,
			  atr2 as attribute, val2,
			  atr3 as attribute, val3,
			  atr4 as attribute, val4,
			  atr5 as attribute, val5,
			  atr6 as attribute, val6,
			  atr7 as attribute, val7 from state where id=?",
	    str = "State"),
	del int,
),



1

-- State table for postgres

create table state (
	id serial primary key,
	val0 varchar(4096),
	val1 varchar(4096),
	val2 varchar(4096),
	val3 varchar(4096),
	val4 varchar(4096),
	val5 varchar(4096),
	val6 varchar(4096),
	val7 varchar(4096)
);
