sub DBLogin {
    $DB = &dblogin($DBUser, $DBPassword, $DBServer);
    &dbuse($DB, $DBDatabase);
}

sub DBLogoff {
    ;
}

sub DBinit {
    $ENV{"SYBASE"}   = "/usr/sybase";
    $ENV{"DSQUERY"}  = "SYBASE";
    $ENV{"DSLISTEN"} = "SYBASE";

    require "sybperl.pl";
    ;
}

sub sql {
    local($db,$sql,$sep)=@_;			# local copy parameters

    $sep = '~' unless $sep;			# provide default for sep

    @res = ();					# clear result array

    &dbcmd($db,$sql);				# pass sql to server
    &dbsqlexec($db);				# execute sql

    while(&dbresults($db) != $NO_MORE_RESULTS) {	# copy all results
	while (@data = &dbnextrow($db1)) {
	    push(@res,join($sep,@data));
	}
    }

    @res;					# return the result array
}


#----------------------------------------------------------------------
# Find a list of tables... DB specific pretty much..
#
# Takes an optional search parameter that finds tables that match
#

sub DBtableList {
    local (@tables) = ("");
    local ($search) = @_;
	
    #
    # This is for sybase
    #

    $where  =  "and o.name like \'$search\'" if ($search);
    @tables =  &sql($DB, 
		   "SELECT o.name
                    FROM $DBDatabase.dbo.sysobjects o, 
                         $DBDatabase.dbo.sysusers u
                    WHERE (o.type = 'U' or o.type = 'V') and u.uid=o.uid $where
                    order by o.name");

    return(@tables);
}


#----------------------------------------------------------------------
# Find a list of columns for a table... DB specific pretty much..
#
#

sub DBcolumnList {
    local ($table,$search) = @_;
    local ($where) ="";

    $where  =  "cols.name like \'$search\' and" if ($search);
    
    @cols = &sql($DB, 
	       "SELECT name from $DBDatabase.dbo.syscolumns cols
                WHERE $where cols.id = (
                    SELECT o.id
                    FROM $DBDatabase.dbo.sysobjects o, 
                       $DBDatabase.dbo.sysusers u
                    WHERE (o.type = 'U' or o.type = 'V')
                        and u.uid=o.uid and o.name=\'$table\'
                )
    ");

    return(@cols);
}

#--------------------------------------------------------------------
# type of the column..  (CHAR, etc..)
#

sub DBcolumnType {
    local($tablecol) = @_;
    local ($table,$column) = split(/\./, $tablecol);

    @cols = &sql($DB, 
	       "SELECT types.name
                       FROM $DBDatabase.dbo.syscolumns cols,
                            $DBDatabase.dbo.systypes types
                WHERE cols.id = (
                    SELECT o.id
                    FROM $DBDatabase.dbo.sysobjects o, 
                       $DBDatabase.dbo.sysusers u
                    WHERE (o.type = 'U' or o.type = 'V')
                        and u.uid=o.uid and o.name=\'$table\'
                ) and cols.type=types.type and cols.name=\'$column\'
    ");

    return (shift(@cols));
}

sub DBwritableTable {
    local ($table) = @_;
    
    ;
}


1;  # for require
