ePages 6.17.48 - DE_EPAGES/ShopTransfer/API/BCP.pm

Package DE_EPAGES::ShopTransfer::API::BCP

Helper functions for the shop transfer script. These functions export shop data from the database into text files, one file per database table. The file format is similar to CSV, but without quoting - therefore the field separator and record separator must never be included in the actual data. NULL values are represented by empty strings.

@EXPORT_OK
BCPInCommand
BCPInIterator
BCPOutStatement
BCPOutMapper
GetBcpParameter
CreateBCPFileIterator

Functions

BCPInCommand
BCPInIterator
BCPOutMapper
BCPOutStatement
CreateBCPFileIterator
GetBcpParameter

BCPInCommand

Imports a file to database, the $Parameter can be build via GetBcpParameter.

Syntax
$BcpExitCode = BCPInCommand($FileName, $DBName, $Table, $Parameter);
Example
$BcpExitCode = BCPInCommand($FileName, $DBName, $Table,
       GetBcpParameter($Server, $User, $Password, $FilePath, $Encoding));
Input
$FileName (string)
file name
$DBName (string)
database name (includes owner)
$Table (string)
table name
$Parameter (string)
special bcp parameter
Return
$BcpExitCode (integer)
exit code of bcp

BCPInIterator

Reads a bcp file and executes $Sub->(@Values) on each row.

Syntax
BCPInIterator($FileName, $Sub, $Encoding);
Example
BCPInIterator($FileName, sub { my @Row = @_; }, $Encoding));
Input
$FileName (string)
file name
$Sub (ref.code)
perl function
$Encoding (string)
encoding of bcp file (default utf8)

BCPOutMapper

Read and Writes bcp files, all lines are converted via mapping. Calls @NewValues = $Sub->(@Values) for each row. Deletes the row if the result of $Sub is an empty array.

Syntax
BCPOutMapper($SourceFileName, $TargetFileName, $Sub, $Encoding);
Input
$SourceFileName (string)
source file name
$TargetFileName (string)
source file name
$Sub (ref.code)
mapping function, returns the values of the new row. IF the
$Encoding (string)
encoding of bcp file (default utf8)

BCPOutStatement

Writes a bcp file, lines are rows of the result of statement.

Syntax
BCPOutStatement($FileName, $sth, $Encoding);
Example
my $dbi = GetCurrentDBHandle();
 my $dbh = $dbi->dbh;
 my $sth = $dbh->prepare('select * from object');
 $sth->execute();
 BCPOutStatement($FileName, $sth, $Encoding);
 $sth->finish();
Input
$FileName (string)
file name
$sth (object)
DBD statement handle
$Encoding (string)
encoding of bcp file (default utf8)

CreateBCPFileIterator

Creates an iterator for reading a bcp file line by line.

Syntax
$Iterator = CreateBCPFileIterator($FileName, $Encoding);
Example
$Iterator = CreateBCPFileIterator('table.txt');
print Dumper( $_ ) while <$Iterator>;
Input
$FileName (string)
file name
$Encoding (string)
(optional; default=utf8) encoding of bcp file
Return
$Iterator (DE_EPAGES::Core::API::Iterator)
iterator of table rows. Each row is an array ref with the columns.

GetBcpParameter

Read and Writes bcp files, all lines are converted via mapping.

Syntax
$Parameter = GetBcpParameter($Server, $User, $Password, $FilePath, $Encoding);
Input
$Server (string)
database server name
$User (string)
user name
$Password (string)
password to access the database
$FilePath (string)
path for debug and error log
$Encoding (string)
encoding of bcp file (default utf8)
Return
$Parameter (out} [filename]
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n] [-c] [-t field_terminator] [-r row_terminator]
[-U username] [-P password] [-I interfaces_file] [-S server]
[-a display_charset] [-z language] [-v]
[-A packet size] [-J client character set]
[-T text or image size] [-E] [-g id_start_value] [-N] [-W] [-X]
[-M LabelName LabelValue] [-labeled]
[-K keytab_file] [-R remote_server_principal] [-C]
[-V [security_options]] [-Z security_mechanism] [-Q] [-Y]
[-x trusted.txt_file]
[--maxconn maximum_connections] [--show-fi] [--hide-vcc]
[--colpasswd [[[db_name.[owner].]table_name.]column_name [password]]]
[--keypasswd [[db_name.[owner].]key_name [password]]]
[--initstring ASE initialization string])
bcp parameter | string
usage: bcp [[db_name.]owner.]table_name[:slice_num] [partition pname] {in