#!/usr/local/Hughes/bin/lite

/*
** This script is the setup script for the bookmarks demonstration
** application.  It creates a new database called "bookmarks" on the
** mSQL server running on the local machine, sets up the required 
** database tables, and initialises the tables with some default values.
*/


echo ("Bookmarks setup program\n\n");
echo ("This script will create the database and tables required to run\n");
echo ("the bookmarks demonstration application.\n\n");


/*
** Create empty databases
*/

echo ("Creating the empty databases ...  ");

if (system("/usr/local/Hughes/bin/msqladmin create bookmarks") != 0)
{
	fatal("Error creating databases");
	exit(1);
}


/*
** Connect to the server
*/


$sock = msqlConnect();
if ($sock < 0)
{
	fatal("Error : $ERRMSG\n");
}


/*
** Now setup the bookmarks database
*/

echo("Setting up the demonstration application database\n");
echo("-------------------------------------------------\n\n");


echo ("Swapping to the bookmarks database ... ");
if (msqlSelectDB($sock,"bookmarks") < 0)
{
        fatal("Error : $ERRMSG\n");
}
echo("done.\n");


echo("Creating the bookmarks table ... ");
if (msqlQuery($sock, "CREATE TABLE bookmarks (
  			type CHAR(1),
  			parent CHAR(255),
  			path CHAR(255),
  			name CHAR(50),
  			url CHAR(100),
  			owner CHAR(20),
  			private CHAR(1))") < 0)
{
	fatal("Error : $ERRMSG\n");
}
echo("done.\n");


echo("Inserting sample data ... ");

if (msqlQuery($sock,"INSERT INTO bookmarks VALUES ('F','/Databases','/Databases/Mini SQL','Mini SQL', '',NULL,NULL)") < 0)
{
	fatal("Error : $ERRMSG\n");
}

if (msqlQuery($sock,"INSERT INTO bookmarks VALUES ('F','/','//Databases','Databases','',NULL,NULL) ") < 0)
{
	fatal("Error : $ERRMSG\n");
}

if (msqlQuery($sock,"INSERT INTO bookmarks VALUES ('F','','/Databases','Databases','',NULL,NULL) ") < 0)
{
	fatal("Error : $ERRMSG\n");
}

if (msqlQuery($sock,"INSERT INTO bookmarks VALUES ('B','/Databases/Mini
SQL','/Databases/Mini SQL/Mini SQL Home Page','Mini SQL Home Page','http://www.Hughes.com.au/',NULL,NULL)") < 0)
{
	fatal("Error : $ERRMSG\n");
}

if (msqlQuery($sock,"INSERT INTO bookmarks VALUES ('B','/Databases/Mini SQL','/Databases/Mini SQL/Mini SQL Distribution','Mini SQL Distribution','http://www.Hughes.com.au/software/',NULL,NULL)") < 0)
{
	fatal("Error : $ERRMSG\n");
}

if (msqlQuery($sock,"INSERT INTO bookmarks VALUES ('B','/Databases/Mini SQL','/Databases/Mini SQL/W3-mSQL Home Page','W3-mSQL Home Page','http://www.Hughes.com.au/', NULL,NULL)") < 0)
{
	fatal("Error : $ERRMSG\n");
}

if (msqlQuery($sock,"INSERT INTO bookmarks VALUES ('B','/Databases','/Databases/HTML Translation of SQL-86','HTML Translation of SQL-86','http://case50.ncsl.nist.gov/sql-86/',NULL,NULL)") < 0)
{
	fatal("Error : $ERRMSG\n");
}

if (msqlQuery($sock,"INSERT INTO bookmarks VALUES ('B','/Databases','/Databases/Database Systems Laboratory, Univ of Massachusetts','Database Systems Laboratory, Univ of Massachusetts','http://www-ccs.cs.umass.edu/db.html',NULL,NULL)") < 0)
{
	fatal("Error : $ERRMSG\n");
}

if (msqlQuery($sock,"INSERT INTO bookmarks VALUES ('F','/','//World-Wide Web','World-Wide Web','',NULL,NULL)") < 0)
{
	fatal("Error : $ERRMSG\n");
}

if (msqlQuery($sock,"INSERT INTO bookmarks VALUES ('F','/World-Wide Web','/World-Wide Web/HTTP Servers','HTTP Servers','',NULL,NULL)") < 0)
{
	fatal("Error : $ERRMSG\n");
}

if (msqlQuery($sock,"INSERT INTO bookmarks VALUES ('B','/World-Wide Web','/World-Wide Web/Yahoo','Yahoo','http://www.yahoo.com/',NULL,NULL)") < 0)
{
	fatal("Error : $ERRMSG\n");
}

if (msqlQuery($sock,"INSERT INTO bookmarks VALUES ('B','/World-Wide Web/HTTP Servers','/World-Wide Web/HTTP Servers/Apache HTTP Server Project','Apache HTTP Server Project','http://www.apache.org/',NULL,NULL)") < 0)
{
	fatal("Error : $ERRMSG\n");
}

if (msqlQuery($sock,"INSERT INTO bookmarks VALUES ('B','/World-Wide Web/HTTP Servers','/World-Wide Web/HTTP Servers/CERN HTTP server','CERN HTTP server','http://www.w3.org/hypertext/WWW/Daemon/Status.html',NULL,NULL)") < 0)
{
	fatal("Error : $ERRMSG\n");
}

echo ("done.\n\n");
echo ("Setup complete.\n\n");


msqlClose($sock);
