#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package RPS::DB::Item::SaleImportFieldMapping;
use strict;
use warnings;
use lib '/app/tools/common/lib';
use Common::DB::Item;
use Common::RSApp;
use Common::Assert;
use Common::Log;

use base 'Common::DB::Item';

use constant kTable => 'sale_import_field_mapping';
use constant kDB    => Common::DB::Item::kClientDB();

sub GetAllByFileID {
    my ( $class, $fileID, $dataType ) = @_;

    my $sql = "SELECT * FROM " . kTable . " WHERE file_id = " . $class->quote($fileID) . " ORDER BY field";

    if ( $dataType && $dataType eq 'ARRAY' ) {
        my $dbo = Common::RSApp::GetClientDB();
        return $dbo->DoCmd($sql)->fetchall_arrayref({});
    }

    return $class->SUPER::GetAll($sql);
}

sub DeleteByFileID {
    my ( $class, $fileID ) = @_;

    my $dbo = Common::RSApp::GetClientDB();
    my $sql = "DELETE FROM " . kTable . " WHERE file_id = ?";
    $dbo->DoCmdWithPlaceholders($sql, [$fileID]);

    return 1;
}

1;
