/***************************************************************

Demonstration code from 'Professional Linux Programming'

Written by Neil Matthew, Rick Stones et. al.

Copyright (C) 2000 Wrox Press.

http://www.wrox.com

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.

***************************************************************/

There are two implementations in this directory, a flatfile
'demonstration' implementation, and a PostgreSQL based SQL
implementation.

The principal files that other applications will need to use are:
dvd.h    - the header definition file for externally visible functions
dvd_pg.a - the static library that implements the PostgreSQL version.


In addition there is a test harness, dvdstore.c, which allows the API
to be driven 'by hand'. It is used to create dvdstore, a standalone
executable for accessing the data in the PostgreSQL implementation, and
flatstore, a standalone executable for accessing the data in the 
flatfile version. In these programs type 'help' for some initial
help. They both use GNU readline, so command line editing may be used.

Type 'make' to build 
1) dvd_pg.a - the library that implements DVD store against PostgreSQL
2) flatfile.o - a file that implements DVD store using only faltfiles
3) dvdstore and flatstore, standalone programs that provide command line 
access to the PostgreSQL database and flatfile implementations respectivly.

Depending on your Linux distribution you may need to make
minor adjustments to the Makefile. For swapping between Red Hat 6.1
and SuSE6.3 a single line change to the include path is required, just
adjust the commenting as appropriate.

Before you can run the flatfile test harness you must run
init-flat.sh to initialize the files.

Before you can run the dvdstore test harness you must create your dvdstore
database and then run init-pg.sh to initialize the tables. Instructions for
creating an initial dvdstore PostgreSQL database are below.



Additional files

init-flat.sh  - a shell script for boot strapping the flatfile implementation
init-pg.sh - a shell script for boot strapping the PostgreSQL implementation


create_tables.sql - used by init-pg.sh to create the required tables
drop_tables.sql -  used by init-pg.sh to remove all the dvd tables and associated crud from the dvdstore PostgreSQL database
insert_data.sql -  used by init-pg.sh to insert some base data, such a Genre's error text etc. that is required to get you started. It does not create any members, titles, disks etc., only the pseudo static data.


Before you can run init-pg.sh, you must have PostgreSQL installed, running,
and an empty dvdstore database created, on which you have administration
permissions on.


Creating a dvdstore PostgreSQL database.

If you have never run PostgreSQL before you may need to inspect the 
services that are started when your machine starts, and ensure that
PostgreSQL is both installed and started automatically.

Have a look for a 'postmaster' process running, which usually indicates that
the PostgreSQL database server is running. If it is, try the command
psql template1
to connect to the PostgreSQL server. You will probably see an error about
pg_shadow. This means the service is running, even though you are not yet
configured as a user of the service. See below.
Type '\q' to quit the psql program if required.

Modern distributions initialize the PostgreSQL storage area automatically.
If this has not happened, please consult the HOWTO or your distro web site.

Once the PostgreSQL server is running, you need to create yourself as a user,
ed then create a database called 'dvdstore' which is administered by you. 

Login as root, then su to postgres
type 'psql template1' to connect to the initial database
type 'create user <yourlogin> CREATEDB;' - create yourself with the right privaledge. NOTICE THE ; 
type '\q' to exit psql
exit the current login.
Login as yourself,  and type 'psql template1'.
Type 'CREATE DATABASE dvdstore;' which creates the dvdstore database.
type '\connect dvdstore' and you should be connected to the dvdstore database
type '\q' to exit psql
type 'psql dvdstore' and you should connect directly to the dvdstore database.
type '\q' to exit psql

You should now be able to run init-pg.sh to create the database. Be aware
that this script deletes all the data and tables in dvdstore - it's a complete
restart each time you run it.

To check all is well once init-pg.sh has completed, run up psql again and...
type '\d' to see the tables.
type 'select * from genre;' to check some data is loaded.

All the S/W is distributed under the GNU General Public License, but is
copyright Wrox Press.

Good luck.

Neil and Rick.






