[BACK]Return to dbops.pm CVS log [TXT][DIR] Up to [local] / wpscripts / epickup

Annotation of wpscripts/epickup/dbops.pm, Revision 1.1

1.1     ! yason       1: #!/usr/bin/perl
        !             2: use DBI;
        !             3: use strict;
        !             4: use conv; # to_local()
        !             5: package dbops;
        !             6:
        !             7: our $EPD_ZAYAVKA_T = 0;
        !             8: our $EPD_PROBA_T = 1;
        !             9:
        !            10: our $server = "MSSQL";
        !            11: our $user = "it_men";
        !            12: our $pass = "itmen712";
        !            13: our $dsn = "DBI:Sybase:server=$server";
        !            14: our $table = 'T$_EPD_File';
        !            15: our $dbh;
        !            16: our $sth;
        !            17:
        !            18: sub connect()
        !            19: {
        !            20:     $dbh = DBI->connect($dsn, $user, $pass) or die "unable to connect to server $DBI::errstr";
        !            21: }
        !            22:
        !            23:
        !            24: sub select()
        !            25: {
        !            26:     $dbh->do("use Manager");
        !            27: }
        !            28:
        !            29:
        !            30: sub disconnect()
        !            31: {
        !            32:     $dbh->disconnect();
        !            33: }
        !            34:
        !            35:
        !            36: sub fetch($)
        !            37: {
        !            38:     my $file_type = shift;
        !            39:     my $i = 0;
        !            40:     my @ID;
        !            41:     my @win_paths;
        !            42:
        !            43:
        !            44:     $sth = $dbh->prepare ("SELECT ID,win_path FROM $table WHERE File_type=$file_type AND Ready=1 AND Backed_up=0")
        !            45:        or die("fetch");
        !            46:
        !            47:     $sth->execute( ) or die "unable to execute query! error $DBI::errstr";
        !            48:
        !            49:     while( ($ID[$i], $win_paths[$i]) = $sth->fetchrow_array() )
        !            50:     {
        !            51:        if ($win_paths[$i] ne '')
        !            52:        {
        !            53:            # reuse with real unix path
        !            54:            $win_paths[$i] = conv::to_local($win_paths[$i]);
        !            55:
        !            56:            # NOT checking existence of file here
        !            57:        }
        !            58:        else
        !            59:        {
        !            60:            log::stdout("fetch(): void element $win_paths[$i]\n");
        !            61:        }
        !            62:
        !            63:        $i++;
        !            64:     }
        !            65:
        !            66:     $sth->finish();
        !            67:
        !            68:     return( (\@ID, \@win_paths) );
        !            69:
        !            70: } # fetch()
        !            71:
        !            72:
        !            73: sub set($$$)
        !            74: {
        !            75:     my $ID = shift;
        !            76:     my $field = shift;
        !            77:     my $value = shift;
        !            78:
        !            79:     $sth = $dbh->prepare ("UPDATE $table SET $field=$value WHERE ID=$ID");
        !            80:     $sth->execute() or die "unable to update table! error $DBI::errstr";
        !            81:
        !            82:     # Notreached if error
        !            83:
        !            84:     $sth->finish();
        !            85:
        !            86: }
        !            87:
        !            88:
        !            89: sub fixate($)
        !            90: {
        !            91:     my $ID = shift;
        !            92:
        !            93:
        !            94:     $sth = $dbh->prepare ("UPDATE $table SET Backed_up=1 WHERE ID=$ID");
        !            95:     $sth->execute() or die "unable to update table! error $DBI::errstr";
        !            96:
        !            97:     $sth->finish();
        !            98: }
        !            99:
        !           100:
        !           101: sub markok($)
        !           102: {
        !           103:     my $ID = shift;
        !           104:
        !           105:
        !           106:     $sth = $dbh->prepare ("UPDATE $table SET Backed_up=1 WHERE ID=$ID");
        !           107:     $sth->execute() or die "unable to update table! error $DBI::errstr";
        !           108:
        !           109:     $sth->finish();
        !           110: }
        !           111:
        !           112: return(1);

CVSweb