<?
	#---------------------------------------------------------------------#
	# This source code is (c)2000 White Pajamas, Inc                      #
	# see http://www.stonekeep.com/license.html for licensing information #
	#---------------------------------------------------------------------#

	#--------------------------------------------------------------------
	# $Id: db.php3,v 1.17 2000/12/14 19:13:46 shevett Exp $
	#--------------------------------------------------------------------
	#
	#	database abstraction functions.  This
	#		module figures out which subset to call, and 
	#		loads the appropriate routines.
	#
	# The defaults for these options are set in 'conf/keystone.conf'
	
	$dbhost = "$sys_dbhost";
	$dbname = "$sys_dbname";
	$dbuser = "$sys_dbuser";
	$dbpasswd = "$sys_dbpasswd";
	$server = "$sys_server";

	$port    = "$sys_pg_port";
	$options = "$sys_pg_options";
	$tty     = "$sys_pg_tty";
	$conn    = "$sys_pg_conn";
	$rowid   = "$sys_pg_rowid";
	$last_table   = "$sys_pg_last_table";

	$oracle_home	=	"$sys_oracle_home";

	#--------------------------------------------------------------------
	#	This switch statement points to all the Db dependant implementaions.
	# Each of these must implement to following functions:

	#--------------------------------------------------------------------
	# function db_connect $target
	# 	args: $target = String host name of database server
	# 	returns nothing
	# 	comment: Connects to the database server
	# 
	# function db_query $qstring
	# 	args: $qstring = String, SQL query
	# 	returns: result handle
	# 	comment: Executes SQL query on server 
	# 
	# function db_numrows $qhandle
	# 	args: $qhandle = result handle from db_query function call
	# 	returns: number of rows in result set
	# 	comment:
	# 
	# function db_result $qhandle,$row,$field
	# 	args: 	$qhandle = result handle from db_query function call
	# 		$row = integer containing row index to be viewed
	# 		$field = string field name to be viewed
	# 	returns: result set data specified by args.
	# 	comment: Gets a single field of data.
	# 
	# function db_listfields $tname 
	# 	args:	$tname = String containing table name
	# 	returns: result handle containing field names
	# 	comment: Used to get field names for table
	# 
	# function db_numfields $lhandle
	# 	args:	$lhandle = result handle from db_query function call
	# 	returns: number of fields in result set
	# 	comment:
	# 
	# function db_fieldname $lhandle,$fnumber
	# 	args:	$lhandle = result handle from db_query function call
	# 		$fnumber = index of a result set field
	# 	returns: field name as specified by args
	# 	comment:
	# 
	# function db_fieldtype $lhandle,$which
	# 	args: 	$lhandle = result handle from db_query function call
	# 		$which = index of a result set field
	# 	returns: data type of field specified by args
	# 	comment: same as db_fieldname except returns type not name
	# 
	# function db_fieldlen $lhandle,$which
	#         args:   $lhandle = result handle from db_query function call
	#                 $which = index of a result set field
	# 	returns: length of specified field
	# 	comment: same as db_fieldname except returns length not name
	#
	# function db_seek $lhandle,$rows
	#					args:		$lhandle = result handle from db_query function call
	#									$rows = how many rows to skip.
	#		returns: 1 = success, 0 = failure.
	#		comment: moves the row pointer in the result to the '$rows'th 
	#							position.  next fetch_row will return the next row in 
	#							the result.  Note: not implemented in postgres.
	#--------------------------------------------------------------------

	function report_error($e_func,$e_number,$e_msg) {
		global $flagged;
		if (! $flagged) {
			LogIt("ERR","$e_func","Error $e_number: $e_msg");
		?>
			<SCRIPT LANGUAGE="JavaScript">
			alert("MySQL Error # <? echo $e_number ?> in function <? echo $e_func ?>\n<? echo $e_msg ?>");
			</SCRIPT>
		<?
			$flagged=1;
		}
	}

	switch ("$server") {
		case "msql" : {
			include("./msql.php3");
			break;;
		}
		case "mysql" : {
			include("./mysql.php3");
			break;;
		}
		case "postgresql" : {
			include("./postgres.php3");
			break;;
		}
		case "sybase" : {
			include("./sybase.php3");
			break;;
		}
		case "oracle" : {
			include("./oracle.php3");
			break;;
		}
	}
?>
