use POSIX qw(strftime);

use vars qw(@lDbTimestampScanFormats @lDbTimeScanFormats);

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

# --- MySql ------------------------------------------------------------------
sub _CreateDataSource()
# ----------------------------------------------------------------------------
{
   my $hSelfPI   = shift;

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

   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 SQL_TIMESTAMP_Form2Db ($$)
{
   return &DateToDb(shift, shift);

}

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

# --- only dummy at the moment --------------------------------------
sub MapDatatype($)
{
    my $iDatatypePI = shift;
   
    return $iDatatypePI;
}


1;

