
use vars qw(@lDbTimestampScanFormats @lDbTimeScanFormats);

@lDbTimestampScanFormats = ("%d-%b-%Y %H:%M:%S");
@lDbTimeScanFormats      = ("%H:%M:%S");

# --- Oracle -----------------------------------------------------------------
sub DbSession::Oracle::_CreateDataSource
# ----------------------------------------------------------------------------
{
   my $hSelfPI   = shift;

   $hSelfPI->{"DataSource"} =
       sprintf("dbi:%s" .
               "(RaiseError=>%d, PrintError=>%d, AutoCommit=>%d)" .
               ":host=%s;sid=%s",
               $hSelfPI->{"DbDriver"},
               $hSelfPI->{"RaiseError"},
               $hSelfPI->{"PrintError"},
               $hSelfPI->{"AutoCommit"},
               $hSelfPI->{"DbHost"},
               $hSelfPI->{"DbName"});

   $ENV{"ORACLE_SID"}  = $hSelfPI->{"DbName"};
   $ENV{"ORACLE_HOME"} = "/home/oracle";
   $ENV{"TWO_TASK"}    = sprintf("T:%s:%s",
                                 $hSelfPI->{"DbHost"},
                                 $hSelfPI->{"DbName"});

   return $hSelfPI->{"DataSource"};
}


sub DateFromDb($$)
# ----------------------------------------------------------------------------
{
   my $hSelfPI  = shift;
   my $cFieldPI = shift;

   my $cResult = &DbSession::PrintDate
       ($hSelfPI->getDatePrintFormat(),
        &DbSession::ScanDate($cFieldPI, @lDbTimestampScanFormats)) ||
            $cFieldPI;

   return $cResult;

}


sub DateToDb($$)
# ----------------------------------------------------------------------------
{
   my $hSelfPI  = shift;
   my $cFieldPI = shift;

   my $cResult = &DbSession::PrintDate
       ($lDbTimestampScanFormats[0],
        &DbSession::ScanDate($cFieldPI,
                             @{$hSelfPI->getDateScanFormats()})) ||
                                 $cFieldPI;

   return $cResult;

}



# --- Convert datetime-fields from form to db ---------------------------------
sub TIMESTAMP_Form2Db ($$)
{
   return &DateToDb(shift, shift);

}

# --- Convert datetime-fields from db to form ---------------------------------
sub TIMESTAMP_Db2Form ($$)
{
   return &DateFromDb(shift, shift);
}




# --- Convert float4-fields from form to db ---------------------------------
sub FLOAT_Form2Db ($)
{
   my $hSelfPI  = shift;
   my $cFieldPI = shift;

   my $cResult;

   ($cResult = $cFieldPI) =~ s/,/./g;

   return $cResult;
}


# --- Convert float4-fields from db to form ---------------------------------
sub FLOAT_Db2Form ($)
{
   my $hSelfPI  = shift;
   my $cFieldPI = shift;

   my $cResult;

   ($cResult = $cFieldPI) =~ s/\./,/g;

   return $cResult;
}

# :-(   :-(   :-(   :-(   :-(   :-(   :-(   :-(   :-(   :-(   :-(   :-(   :-(
# OK, this is horrible!!!!!!
#
# But I found no other way to insert an 'empty' string without getting
# converted to a NULL-value
#
# If anyone has a good idea, how to fix this 'feature' I like to hear from!
#
# :-(   :-(   :-(   :-(   :-(   :-(   :-(   :-(   :-(   :-(   :-(   :-(   :-(

# --- Convert varchar2-fields from form to db ---------------------------------
sub VARCHAR2_Form2Db ($)
{
   my $hSelfPI  = shift;
   my $cFieldPI = shift;

   my $cResult;

   $cResult = $cFieldPI? $cFieldPI: " ";

   return $cResult;
}


# --- Convert varchar2-fields from db to form ---------------------------------
sub VARCHAR2_Db2Form ($)
{
   my $hSelfPI  = shift;
   my $cFieldPI = shift;

   my $cResult;

   $cResult = ($cFieldPI eq " ")? "": $cFieldPI;

   return $cResult;
}

1;
