Name

import — import records into database

ATTRIBUTES

Attribute Pos. Req. Default Description
[ table | base | database ] Yes Yes   .
type Yes    
continue      
separator      
file       .
interpolate     0 interpolate input?
reparse     1 interpolate output?

DESCRIPTION

The [import] tag is used to import records into a database.

The table (database) must already be registered with Interchange using the Database directive; tables cannot be created on the fly.

BEHAVIOR

This tag does not appear to be affected by, or affect, the rest of Interchange.

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

import is available in Interchange versions:

4.6.0-5.7.0 (git-head)

SOURCE

Interchange 5.7.0:

Source: code/SystemTag/import.coretag
Lines: 18


# Copyright 2002-2007 Interchange Development Group and others
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  See the LICENSE file for details.
# 
# $Id: import.coretag,v 1.5 2007-03-30 23:40:49 pajamian Exp $

UserTag import              Order        table type
UserTag import              addAttr
UserTag import              attrAlias    base table
UserTag import              attrAlias    database table
UserTag import              hasEndTag
UserTag import              Interpolate
UserTag import              PosNumber    2
UserTag import              Version      $Revision: 1.5 $
UserTag import              MapRoutine   Vend::Data::import_text

Source: lib/Vend/Data.pm
Lines: 325

sub import_text {
my ($table, $type, $options, $text) = @_;
#::logDebug("Called import_text: table=$table type=$type opt=" . Data::Dumper::Dumper \
($options) . " text=$text");
my ($delimiter, $record_delim) = find_delimiter($type);
my $db = $Vend::Database{$table}
  or die ("Non-existent table '$table'.\n");
$db = $db->ref();

my @columns;
@columns = ($db->columns());

if($options->{'continue'}) {
  $options->{CONTINUE} = uc $options->{'continue'};
  $options->{NOTES_SEPARATOR} = uc $options->{separator}
    if defined $options->{separator};
}

my $sub = sub { return $db };
my $now = time();
my $fn = $Vend::Cfg->{ScratchDir} . "/import.$$.$now";
$text =~ s/^\s+//;
$text =~ s/\s+$//;

if($delimiter eq 'CSV') {
  my $add = '"';
  $add .= join '","', @columns;
  $add .= '"';
  $text = "$add\n$text";
}
else {
  $options->{field_names} = \@columns;
  $options->{delimiter} = $options->{DELIMITER} = $delimiter;
}

if($options->{file}) {
  $fn = $options->{file};
  Vend::File::allowed_file($fn)
    or die ::errmsg("No absolute file names like '%s' allowed.\n", $fn);
}
else {
  # data is already in memory, do not create a temporary file
  $options->{scalar_ref} = 1;
  $fn = \$text;
}

my $save = $/;
local($/) = $record_delim if defined $record_delim;

$options->{Object} = $db;

## This is where the actual import happens
Vend::Table::Common::import_ascii_delimited($fn, $options);

$/ = $save;
unlink $fn unless $options->{'file'} or $options->{scalar_ref};
return 1;
}

AUTHORS

Interchange Development Group

SEE ALSO

export(7ic)

DocBook! Interchange!