#!/usr/bin/mumps

	set t=""
	open 1:"MumpsView.sql,new"
	for  do
	. set t=$zglobal(t)
	. if $l(t)=0 break
	. if t="mumps" quit
	. s cx=@("^"_t)
	. use 5 write "table ",t,": "
	. set ref="^"_t
	. set ref=$query(@ref)
	. use 5 write ref," "
	. set cols=$qlength(ref)
	. use 5 write "cols=",cols,!
	. use 1 write "   drop view if exists mumps_",t,";",!
	. set sql="   create view mumps_"_t_" ("
	. for i=1:1:cols-2 set sql=sql_$p(cx,",",i)_","
	. set sql=sql_$p(cx,",",cols-1)_") as select "
	. for i=2:1:cols-1 set sql=sql_"a"_i_","
	. set sql=sql_"a"_cols_" from mumps "
	. set sql=sql_"where a1='"_t_"' and a2 != '';"
	. use 5 write sql,!
	. use 1 write sql,!
	. use 5 write !

	close 1
	s %=$zsystem("sqlite3 mumps.sqlite < MumpsView.sql")


