Bio-MAGE-Utils

 view release on metacpan or  search on metacpan

MAGE/XML/Handler/ObjectHandler/SQL.pm  view on Meta::CPAN

}

sub indent_increment {
  my $self = shift;
  if (@_) {
    $self->{__INDENT_INCREMENT} = shift;
  }
  return $self->{__INDENT_INCREMENT};
}

sub indent_level {
  my $self = shift;
  if (@_) {
    $self->{__INDENT_LEVEL} = shift;
  }
  return $self->{__INDENT_LEVEL};
}

sub write_start_tag {
  my ($self,$tag,$empty,%attrs) = @_;
  my $indent = ' ' x $self->indent_level();
  my $fh = $self->fh();
  my (@attrs);
  foreach my $attribute_name (keys %attrs) {
    push(@attrs,qq[$attribute_name="$attrs{$attribute_name}"]);
  }
  my ($attrs,$attr_indent);
  if ($self->attrs_on_one_line()) {
    $attrs = join(' ',@attrs);
  } else {
    $attr_indent = $self->attr_indent();
    $attr_indent = length($tag) + 2
      unless defined $attr_indent;
    $attr_indent = ' ' x $attr_indent . $indent;
    $attrs = join("\n$attr_indent",@attrs);
  }
  if ($attrs) {   
    print $fh "$indent<$tag $attrs";
  } else {
    # don't print the space after the tag because Eric said so
    print $fh "$indent<$tag";
  }
  if ($empty) {
    print $fh '/>';
  } else {
    print $fh '>';
  }
  print $fh "\n" unless $self->collapse_tag();
  $self->incr_indent()
    unless $empty;
}
  
sub write_end_tag {
  my ($self,$tag) = @_;  
  $self->decr_indent();
  my $indent = ' ' x $self->indent_level();
  my $fh = $self->fh();
  print $fh "$indent</$tag>\n";
}     

sub update_or_insert_row {
  my $self = shift || croak("parameter self not passed");
  my %args = @_;

  #### Decode the argument list
  my $table_name         = $args{'table_name'}         || die "ERROR: table_name not passed";
  my $rowdata_ref        = $args{'rowdata_ref'}        || die "ERROR: rowdata_ref not passed";
  my $database_name      = $args{'database_name'}      || "";
  my $return_PK          = $args{'return_PK'}          || 0;
  my $verbose            = $args{'verbose'}            || 0;
  my $print_SQL          = $args{'print_SQL'}          || 0;
  my $testonly           = $args{'testonly'}           || 0;
  my $insert             = $args{'insert'}             || 0;
  my $update             = $args{'update'}             || 0;
  my $PK                 = $args{'PK'}                 || "";
  my $PK_value           = $args{'PK_value'}           || "";
  my $quoted_identifiers = $args{'quoted_identifiers'} || "ON";


  #### Make sure either INSERT or UPDATE was selected
  unless ( ($insert or $update) and (!($insert and $update)) ) {
    croak "ERROR: Need to specify either 'insert' or 'update'\n\n";
  }

  #### If this is an UPDATE operation, make sure that we got the PK and value
  if ($update) {
    unless (defined($PK) and defined($PK_value)) {
      croak "ERROR: Need both PK and PK_value if operation is UPDATE.  PK: $PK ; PK_value: $PK_value\n\n";
    }
  }

  #### Initialize some variables
  my ($column_list,$value_list,$columnvalue_list) = ("","","");
  my ($key,$value,$value_ref);


  #### Loops over each passed rowdata element, building the query
  while ( ($key,$value) = each %{$rowdata_ref} ) {

    #### If quoted identifiers is set, then quote the key
    $key = '"'.$key.'"';

    #### If $value is a reference, assume it's a reference to a hash and
    #### extract the {value} key value.  This is because of Xerces.
    $value = $value->{value} if (ref($value));

    print "	$key = $value\n" if ($verbose > 0);

    #### Add the key as the column name
    $column_list .= "$key,";

    #### Enquote and add the value as the column value
    $value = $self->convertSingletoTwoQuotes($value);
    if (uc($value) eq "CURRENT_TIMESTAMP") {
      $value_list .= "$value,";
      $columnvalue_list .= "$key = $value,\n";
    } else {
      $value_list .= "'$value',";
      $columnvalue_list .= "$key = '$value',\n";
    }



( run in 0.765 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )