---------------------------------------------------------------------------

Useful command for building the local database

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 drop table address;
 drop table route;
 drop table place;
 drop table campusname;

 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));

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)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#set up environment
source start.sh

#building the program
make

#use data file to populate the database table address
# Starkville business names and campus name
./address allname.text
./address campus_name.text
===========================================================================


# campus direction data from GIS 
campus_direction_1.text
campus_direction_2.text

# populate the campus direction data to tables PLACE and ROUTE in the
  local database

./campus_direction campus_direction_1.text 
./campus_direction campus_direction_2.text 

===========================================================================
How to prepare the campus data

#get the indexcampus.html from site: 
http://msuinfo.ur.msstate.edu/where/building/

#remove the html format symbol
perl web_campus.perl indexcampus.html >campus_name.temp
#NOTE. Below is the perl script used
#-----begin------
##!/usr/bin/perl
#while (<>) {
#    s/<BR>/\n/gis;
#    s/<(?:[^>'"]*|(['"]).*?\1)*>//gs;
#    print $_;
#}
#-----end--------

#leave a copy
 cp campus_name.temp campus_name.text 

#"replace &amp; with &" in file camps_name.text
#"replace \" with " "in file camps_name.text

#build the program
 g++ campus_01.cc -o campus_01

#prepare data file for building local database
./campus_01 campus_name.text out.text

#modify the out.text to campus_ref.text by adding ref_name for each buiding
#manually

#use data file to populate the data to local database table campusname
./campus campus_ref.text
===========================================================================

useful commands:

Using myisamchk for Crash Recovery

myisamchk -i ../var/flatroute/*.MYI
myisamchk -e ../var/flatroute/*.MYI
myisamchk ../var/flatroute/*.MYI
myisamchk -e ../var/flatroute/*.MYI
myisamchk --update  ../var/flatroute/*.MYI
myisamchk -r  ../var/flatroute/*.MYI

===========================================================================
start mysql database server:
safe_mysqld &

to access database:
mysql -u dialog -p

list all tables:
show tables;

select flatroute - eg, select correct database
use flatroute;

delete records\entries:
delete from <table> where <expression>;
  <expression := <column> = <val>, etc
  example: delete from place where id=1000;

compile clear_tables.c:
gcc -I/usr/local/mysql/include clear_tables.c  -L/usr/local/mysql/lib -lmysqlclient -lz -lcrypt -lm -o clear_tables

===========================================================================
grant privileges

set password for gao@localhost=password('abc1234');
set password for gao@localhost=password('qaz1234');

set password for root@localhost=password('abc1234');
grant all PRIVILEGES ON *.* TO gao@isip220.isip.msstate.edu
identified by 'qaz1234';

grant all PRIVILEGES ON *.* TO gao@%.isip.msstate.edu
identified by 'qaz1234';
