#!/usr/bin/perl
use DBI;
use strict;
use conv; # to_local()
package dbops;
our $EPD_ZAYAVKA_T = 0;
our $EPD_PROBA_T = 1;
our $server = "MSSQL";
our $user = "it_men";
our $pass = "itmen712";
our $dsn = "DBI:Sybase:server=$server";
our $table = 'T$_EPD_File';
our $dbh;
our $sth;
sub connect()
{
$dbh = DBI->connect($dsn, $user, $pass) or die "unable to connect to server $DBI::errstr";
}
sub select()
{
$dbh->do("use Manager");
}
sub disconnect()
{
$dbh->disconnect();
}
sub fetch($)
{
my $file_type = shift;
my $i = 0;
my @ID;
my @win_paths;
$sth = $dbh->prepare ("SELECT ID,win_path FROM $table WHERE File_type=$file_type AND Ready=1 AND Backed_up=0")
or die("fetch");
$sth->execute( ) or die "unable to execute query! error $DBI::errstr";
while( ($ID[$i], $win_paths[$i]) = $sth->fetchrow_array() )
{
if ($win_paths[$i] ne '')
{
# reuse with real unix path
$win_paths[$i] = conv::to_local($win_paths[$i]);
# NOT checking existence of file here
}
else
{
log::stdout("fetch(): void element $win_paths[$i]\n");
}
$i++;
}
$sth->finish();
return( (\@ID, \@win_paths) );
} # fetch()
sub set($$$)
{
my $ID = shift;
my $field = shift;
my $value = shift;
$sth = $dbh->prepare ("UPDATE $table SET $field=$value WHERE ID=$ID");
$sth->execute() or die "unable to update table! error $DBI::errstr";
# Notreached if error
$sth->finish();
}
sub fixate($)
{
my $ID = shift;
$sth = $dbh->prepare ("UPDATE $table SET Backed_up=1 WHERE ID=$ID");
$sth->execute() or die "unable to update table! error $DBI::errstr";
$sth->finish();
}
sub markok($)
{
my $ID = shift;
$sth = $dbh->prepare ("UPDATE $table SET Backed_up=1 WHERE ID=$ID");
$sth->execute() or die "unable to update table! error $DBI::errstr";
$sth->finish();
}
return(1);