head	1.1;
access;
symbols
	TIGRIS_1_1_0RC2:1.1
	TIGRIS_1_1_0RC1:1.1
	TIGRIS_1_1:1.1.0.4
	TIGRIS_1_0_8:1.1
	TIGRIS_1_0_8RC3:1.1
	TIGRIS_1_0_8RC2:1.1
	TIGRIS_1_0_8RC1:1.1
	TIGRIS_1_0_7:1.1
	TIGRIS_1_0_7RC3:1.1
	TIGRIS_1_0_7RC2:1.1
	TIGRIS_1_0_7RC1:1.1
	TIGRIS_1_0_6:1.1
	TIGRIS_1_0_6RC5:1.1
	TIGRIS_1_0_6RC4:1.1
	TIGRIS_1_0_6RC3:1.1
	TIGRIS_1_0_6RC2:1.1
	TIGRIS_1_0_6RC1:1.1
	TIGRIS_1_0_5:1.1
	TIGRIS_1_0_5RC6:1.1
	TIGRIS_1_0_5RC5:1.1
	TIGRIS_1_0_5RC4:1.1
	TIGRIS_1_0_5RC3:1.1
	TIGRIS_1_0_5RC2:1.1
	TIGRIS_1_0_5RC1:1.1
	TIGRIS_1_0_4:1.1
	TIGRIS_1_0_3:1.1
	TIGRIS_1_0_2:1.1
	TIGRIS_1_0_1:1.1
	TIGRIS_1_0:1.1.0.6
	TIGRIS_1_0_0:1.1
	TIGRIS_1_0_0_RC1:1.1.0.2;
locks; strict;
comment	@# @;


1.1
date	2001.03.26.21.41.51;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.1
log
@Added script to remove actions from the database.
@
text
@#!/usr/bin/perl -w
# -*- Perl -*- script which will delete actions from the database.
#
# $Id: removeRoleActions.pl,v 1.1 2001/03/26 21:17:25 leonardr Exp $

my @@actions = ("Project News - Add");

use DBI;
use strict;

my $dbh = dbConnection($ENV{DATABASE_NAME}, $ENV{DATABASE_ADMIN_USER},
                         $ENV{DATABASE_ADMIN_PASSWORD});

foreach my $action(@@actions)
{
  my $getActionIDQuery = "select ACTION_ID from HELM_ACTION where NAME='$action'";
  my $something = runSelect($dbh, $getActionIDQuery);
  my $actionID = $something->{ACTION_ID};
  deleteAction($dbh, $actionID);
}

$dbh->disconnect();

sub deleteAction()
  {
    my ($dbh, $actionID) = (@@_);

    if (defined($actionID))
      {
	print "Deleting action $actionID from roles\n";
	my $rarQuery = "delete from HELM_ROLE_ACTION_RESOURCE where ACTION_ID = '$actionID'";
	runStatement($dbh, $rarQuery);

	print "Deleting action $actionID from action table.\n";
	my $actQuery = "delete from HELM_ACTION where ACTION_ID = '$actionID'";
	runStatement($dbh, $actQuery);

      }
  }

####################################################################

# Creates and returns a handle to the database (i.e. connection reference).
#
# ex. my $conn = dbConnection('tigris', 'user', 'passwd');
sub dbConnection($$$)
{
    my ($dbName, $dbUser, $dbPasswd) = @@_;
    return DBI->connect
        ("DBI:mysql:$dbName:$ENV{DATABASE_HOST}:$ENV{DATABASE_PORT}",
         $dbUser, $dbPasswd,
        { RaiseError => 1, AutoCommit => 1 });
}

# Runs a SQL statement.
#
# ex. my $rv = runStatement($dbh, 'delete from bar where baz');
sub runStatement($$)
{
    my ($dbh, $sql) = @@_;
    #print "sql=$sql\n";  # debug
    $sql =~ s/(.*)\;\s*$/$1/s;
    my $sth = $dbh->prepare($sql);
    my $rv = $sth->execute();
    $sth->finish();
    return $rv;
}

# Runs a SQL SELECT statement.
#
# ex. my $rv = runSelect($dbh, 'select foo from bar where baz');
sub runSelect($$)
{
  my ($dbh, $sql) = @@_;
  #print "sql=$sql\n";  # debug
  $sql =~ s/(.*)\;\s*$/$1/s;
  my $sth = $dbh->prepare($sql);

  my $rv = $sth->execute();
  my $hashref=$sth->fetchrow_hashref();
  $sth->finish();
  return $hashref;
}


@
