Steps to create the database needed for the dialog system.

1) Log into database as root
2) Create a little security
3) Grant permissions to user named `dialog`
4) Create the `flatroute` database
5) Create the `flatroute` tables (address, route, place, campusname)
6) Verify they look as in the output section
7) Compile and execute the programs to insert data into the database

=====how to log into database as `root`
Note: Default method. This is how it will first work

shell> mysql -u root

# there is no password by default, probably want to change that so use
#
mysql> set password for 'root' = PASSWORD('passhere');
#
# note: This will change the password for 'root'@'localhost' and not the
# password for 'root'@'Chinook.msstate.edu' where chinook.* is the
# name of your computer. The password for that can be changed by using
#
mysql> set password for 'root'@'Chinook.msstate.edu' = PASSWORD('passhere');

=====how to log into database as `dialog`

# if the database is on localhost
shell> mysql -u dialog -p

# if the database is not on this host
shell> mysql -h 130.18.14.185 -u dialog -p

# note: The reason why -p is given with no password is so that mysql will
# prompt upon executing command. This will stop the password from being
# visible on the process list

=====create a little security
(AS SUPERUSER) (eg, `root`)
use mysql;
drop database test;

delete from user where user='';
delete from db where db like "test%";

flush privileges;

=====how to grant permissions to user named `dialog`
(AS SUPERUSER) (eg, `root`)
grant all on flatroute.* to 'dialog'@'%' identified by 'pass123';

# to verify this worked, type
mysql> use mysql;
mysql> select * from db;

# At this point there should be 
# +-------------------------+------------+-----------+
# | Host                    | Db         | User      |
# +-------------------------+------------+-----------+
# | %                       | flatroute  | dialog    |
# +-------------------------+------------+-----------+
# present with all 'Y's (except Grant_priv) to the right.

# And if this query is performed,
mysql> select * from user;
# there should be a 
# +-------------------------+-----------+------------------+
# | Host                    | User      | Password         |
# +-------------------------+-----------+------------------+
# | %                       | dialog    | 591051bb593d2f5b |
# +-------------------------+-----------+------------------+
# present with all 'N's to the right. The '%' in Host means that this
# user may connect from any host.


=====how to create the `flatroute` database
(AS ANY LOGIN WITH PERMISSIONS) (eg, `root` or `dialog`)
create database flatroute;

=====how to create the `flatroute` tables
(AS ANY LOGIN WITH PERMISSIONS) (eg, `root` or `dialog`)
use flatroute;

# These commands are only here to drop anything that is currently there.
# By dropping this will remove any tables already named this in the
# current database;
#
drop table address;
drop table route;
drop table place;
drop table campusname;

# These commands will create the expected layout tables
# Copy and paste them into mysql and it'll work just fine
#
CREATE TABLE address (
   id int(11) auto_increment primary key, 
   name char(120), 
   specification char(120), 
   type char(120), 
   address char(120), 
   telephone char(15), 
   distance double(16, 2) DEFAULT '0.00' NOT NULL, 
   city char(120), 
   state char(40), 
   zip char(5), 
   startname char(120), 
   startaddress char(120), 
   vreme timestamp);

CREATE TABLE campusname (
   id int(11) auto_increment primary key, 
   building char(120), 
   name char(120), 
   refname char(120), 
   notes char(120), 
   vreme timestamp);

CREATE TABLE place (
   id int(11) auto_increment primary key, 
   name char(120), 
   specification char(120), 
   type char(120), 
   address char(120), 
   telephone char(15), 
   distance double(16, 2) DEFAULT '0.00' NOT NULL, 
   city char(120), 
   state char(40), 
   zip char(5), 
   startname char(120), 
   startaddress char(120), 
   vreme timestamp);

 CREATE TABLE route (
   sid int(11) not NULL REFERENCES place(id),  
   did int(11) not NULL REFERENCES place(id), 
   routeindex int(5) not NULL, 
   distance double(16, 2) DEFAULT '0.00' NOT NULL,
   time CHAR(120), 
   directions longtext, 
   totaldistance double(16, 2) DEFAULT '0.00' NOT NULL, 
   vreme timestamp, 
   PRIMARY KEY (sid, did, routeindex));

=====output
The tables should look like

mysql>  desc address;
+---------------+---------------+------+-----+---------+----------------+
| Field         | Type          | Null | Key | Default | Extra          |
+---------------+---------------+------+-----+---------+----------------+
| id            | int(11)       |      | PRI | NULL    | auto_increment |
| name          | char(120)     | YES  |     | NULL    |                |
| specification | char(120)     | YES  |     | NULL    |                |
| type          | char(120)     | YES  |     | NULL    |                |
| address       | char(120)     | YES  |     | NULL    |                |
| telephone     | char(15)      | YES  |     | NULL    |                |
| distance      | double(16,2)  |      |     | 0.00    |                |
| city          | char(120)     | YES  |     | NULL    |                |
| state         | char(40)      | YES  |     | NULL    |                |
| zip           | char(5)       | YES  |     | NULL    |                |
| startname     | char(120)     | YES  |     | NULL    |                |
| startaddress  | char(120)     | YES  |     | NULL    |                |
| vreme         | timestamp(14) | YES  |     | NULL    |                |
+---------------+---------------+------+-----+---------+----------------+
13 rows in set (0.01 sec)

mysql> desc route;
+---------------+---------------+------+-----+---------+-------+
| Field         | Type          | Null | Key | Default | Extra |
+---------------+---------------+------+-----+---------+-------+
| sid           | int(11)       |      | PRI | 0       |       |
| did           | int(11)       |      | PRI | 0       |       |
| routeindex    | int(5)        |      | PRI | 0       |       |
| distance      | double(16,2)  |      |     | 0.00    |       |
| time          | varchar(120)  | YES  |     | NULL    |       |
| directions    | longtext      | YES  |     | NULL    |       |
| totaldistance | double(16,2)  |      |     | 0.00    |       |
| vreme         | timestamp(14) | YES  |     | NULL    |       |
+---------------+---------------+------+-----+---------+-------+
8 rows in set (0.00 sec)

mysql> desc campusname;
+----------+---------------+------+-----+---------+----------------+
| Field    | Type          | Null | Key | Default | Extra          |
+----------+---------------+------+-----+---------+----------------+
| id       | int(11)       |      | PRI | NULL    | auto_increment |
| building | char(120)     | YES  |     | NULL    |                |
| name     | char(120)     | YES  |     | NULL    |                |
| refname  | char(120)     | YES  |     | NULL    |                |
| notes    | char(120)     | YES  |     | NULL    |                |
| vreme    | timestamp(14) | YES  |     | NULL    |                |
+----------+---------------+------+-----+---------+----------------+
6 rows in set (0.01 sec)

mysql> desc place;
+---------------+---------------+------+-----+---------+----------------+
| Field         | Type          | Null | Key | Default | Extra          |
+---------------+---------------+------+-----+---------+----------------+
| id            | int(11)       |      | PRI | NULL    | auto_increment |
| name          | char(120)     | YES  |     | NULL    |                |
| specification | char(120)     | YES  |     | NULL    |                |
| type          | char(120)     | YES  |     | NULL    |                |
| address       | char(120)     | YES  |     | NULL    |                |
| telephone     | char(15)      | YES  |     | NULL    |                |
| distance      | double(16,2)  |      |     | 0.00    |                |
| city          | char(120)     | YES  |     | NULL    |                |
| state         | char(40)      | YES  |     | NULL    |                |
| zip           | char(5)       | YES  |     | NULL    |                |
| startname     | char(120)     | YES  |     | NULL    |                |
| startaddress  | char(120)     | YES  |     | NULL    |                |
| vreme         | timestamp(14) | YES  |     | NULL    |                |
+---------------+---------------+------+-----+---------+----------------+
13 rows in set (0.00 sec)

=====Compile and execute the programs to insert data into the database

Included in $ISIP/util/demo/isip_demo_dialog_makedb/ are 4 problems to populate
and clear the database.

The following programs insert data (in a known format) into the database.
makedb_address/
makedb_campus/
makedb_campus_direction/

The following program remove data from the database.
makedb_clear_tables/

See each directory's index.html for more information. The steps for the
automation is
1) make all programs using $ISIP/util/demo/isip_demo_dialog_makedb/GNUmakefile
2) open insert_all_data.sh with text editor
   a) change user, pass, host
3) execute ./insert_all_data.sh



