一千萬個為什麽

搜索

在DBD :: CSV中,f_ext屬性中的/ r是什麽意思?

為什麽只有第二個示例將擴展名附加到文件名,“。c/r”中的“/ r”是什麽。

#!/usr/bin/env perl
use warnings; use strict;
use 5.012;
use DBI;

my $dbh = DBI->connect( "DBI:CSV:f_dir=/home/mm", { RaiseError => 1, f_ext => ".csv/r"} );

my $table = 'new_1';
$dbh->do( "DROP TABLE IF EXISTS $table" );
$dbh->do( "CREATE TABLE $table ( id INT, name CHAR, city CHAR )" );

my $sth_new = $dbh->prepare( "INSERT INTO $table( id, name, city ) VALUES ( ?, ?, ?, )" );
$sth_new->execute( 1, 'Smith', 'Greenville' );
$dbh->disconnect();

# --------------------------------------------------------

$dbh = DBI->connect( "DBI:CSV:f_dir=/home/mm", { RaiseError => 1 } );
$dbh->{f_ext} = ".csv/r";

$table = 'new_2';
$dbh->do( "DROP TABLE IF EXISTS $table" );
$dbh->do( "CREATE TABLE $table ( id INT, name CHAR, city CHAR )" );

$sth_new = $dbh->prepare( "INSERT INTO $table( id, name, city ) VALUES ( ?, ?, ?, )" );
$sth_new->execute( 1, 'Smith', 'Greenville' );
$dbh->disconnect();

最佳答案

它強制要求擴展(而不是可選)。它來自 DBD :: FileDBD :: CSV 的基類):

   f_ext
       This attribute is used for setting the file extension where (CSV)
       files are opened. There are several possibilities.

           DBI:CSV:f_dir=data;f_ext=.csv

       In this case, DBD::File will open only "table.csv" if both
       "table.csv" and "table" exist in the datadir. The table will still
       be named "table". If your datadir has files with extensions, and
       you do not pass this attribute, your table is named "table.csv",
       which is probably not what you wanted. The extension is always
       case-insensitive. The table names are not.

           DBI:CSV:f_dir=data;f_ext=.csv/r

       In this case the extension is required, and all filenames that do
       not match are ignored.

轉載註明原文: 在DBD :: CSV中,f_ext屬性中的/ r是什麽意思?