#!/bin/bash

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+
#+     Mumps Bioinformatics Software Library
#+     Copyright (C) 2015 - 2026 by Kevin C. O'Kane
#+
#+     Kevin C. O'Kane
#+     kc.okane@gmail.com
#+     https://threadsafebooks.com/
#+     https://www.cs.uni.edu/~okane
#+
#+ This program is free software; you can redistribute it and/or modify
#+ it under the terms of the GNU General Public License as published by
#+ the Free Software Foundation; either version 2 of the License, or
#+ (at your option) any later version.
#+
#+ This program is distributed in the hope that it will be useful,
#+ but WITHOUT ANY WARRANTY; without even the implied warranty of
#+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#+ GNU General Public License for more details.
#+
#+ You should have received a copy of the GNU General Public License
#+ along with this program; if not, write to the Free Software
#+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#+
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

# Jan 8, 2026 Kevin C. O'Kane

# create mumps database for sqlite3

echo
echo "--------------------------------------------------------"
echo "Mumps Sqlite3 mumps table creation for file mumps.sqlite"
 while true; do
	read -p "This will delete any prior contents of the database. Proceed? y/n " yn
        case $yn in
             [Yy]* ) 	break;;
             [Nn]* ) 	echo "exiting..."
			exit
			;;
             * ) 	echo "Please answer yes or no.";;
             esac
	done

# echo "pragma page_size=1024;" > tmp

echo "drop table if exists mumps;" > tmp

echo "pragma journal_mode=MEMORY;" >> tmp

if [ 7 -gt 32 ]; then
	echo "*** Too many index levels (index_max) requested."
	echo "*** Database not created."
	exit
	fi

echo -n "create table mumps (a1 varchar(64), a2 varchar(64), " >> tmp

for ((i = 3; i < 7; i++ ));
	do
	echo -n "a$i varchar(64), " >> tmp 
	done

echo "a7 varchar(128));" >> tmp

echo "create index MI on mumps (a1, a2);" >> tmp

#echo ".save mumps.sqlite" >> tmp
echo ".schema" >> tmp

echo ".quit" > tmp1

sqlite3 mumps.sqlite -cmd ".read tmp" < tmp1

rm -f tmp
rm -f tmp1
echo "-------- mumps table created in mumps.sqlite ---------------"

