GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
SPOPS::Import::DBI::Table(3) User Contributed Perl Documentation SPOPS::Import::DBI::Table(3)

SPOPS::Import::DBI::Table - Import a DBI table structure

 #!/usr/bin/perl
 
 use strict;
 use SPOPS::Import;
 
 {
     my $table_import = SPOPS::Import->new( 'table' );
     $table_import->database_type( 'sybase' );
     $table_import->read_table_from_fh( \*DATA );
     $table_import->print_only( 1 );
     $table_import->transforms([ \&table_login ]);
     $table_import->run;
 }
 
 sub table_login {
    my ( $transformer, $sql, $importer ) = @_;
    $$sql =~ s/%%LOGIN%%/varchar(25)/g;
 }
 
 __DATA__
 CREATE TABLE sys_user (
  user_id       %%INCREMENT%%,
  login_name    %%LOGIN%% not null,
  password      varchar(30) not null,
  last_login    datetime null,
  num_logins    int null,
  theme_id      %%INCREMENT_TYPE%% default 1,
  first_name    varchar(50) null,
  last_name     varchar(50) null,
  title         varchar(50) null,
  email         varchar(100) not null,
  language      char(2) default 'en',
  notes         text null,
  removal_date  %%DATETIME%% null,
  primary key   ( user_id ),
  unique        ( login_name )
 )

 Output:
 
 CREATE TABLE sys_user (
  user_id       NUMERIC( 10, 0 ) IDENTITY NOT NULL,
  login_name    varchar(25) not null,
  password      varchar(30) not null,
  last_login    datetime null,
  num_logins    int null,
  theme_id      NUMERIC( 10, 0 ) default 1,
  first_name    varchar(50) null,
  last_name     varchar(50) null,
  title         varchar(50) null,
  email         varchar(100) not null,
  language      char(2) default 'en',
  notes         text null,
  removal_date  datetime null,
  primary key   ( user_id ),
  unique        ( login_name )
 )

This class allows you to transform and import (or simply display) a DBI table structure.

Transformations are done via two means. The first is the database-specific classes and the standard modifications provided by SPOPS::Import::DBI::TableTransform. The second is custom code that you can write.

database_type ($)

Type of database to generate a table for. See SPOPS::Import::DBI::TableTransform for the listing and types to use.

transforms (\@ of \&, or \&)

Register with the import object one or more code references that will get called to modify a SQL statement. See "CUSTOM TRANSFORMATIONS" below.

print_only (boolean)

If set to true, the final table will be printed to STDOUT rather than sent to a database.

return_only (boolean)

If set to true, the final table will be returned from "run()" rather than sent to a database.

As the example in SYNOPSIS indicates, you can register perl code to modify the contents of a table before it is displayed or sent to a database. When called the code will get three arguments:
1. an object that is a subclass of SPOPS::Import::DBI::TableTransform for the database type specified
2. a scalar reference to the SQL statement to be transformed
3. the SPOPS::Import::DBI::Table object being currently used.

Most of the transformation code will be very simple, along the lines of:

 sub my_transform {
    my ( $self, $sql, $importer ) = @_;
    $$sql =~ s/%%THIS_KEY%%/THAT SQL EXPRESSION/g;
 }

These are the built-in transformations:

increment

Key: %%INCREMENT%%

Replaces the key with an expression to generate a unique ID value with every INSERT. Some databases accomplish this with a sequence, others with an auto-incrementing value.

increment_type

Key: %%INCREMENT_TYPE%%

Datatype of the increment field specified by %%INCREMENT%%. This is necessary when you are creating foreign keys (logical or enforced) and need to know the datatype of the ID you are referencing.

datetime

Key: %%DATETIME%%

Datatype of the field that holds a date and time value. This should not be automatically set with every insert/update (as it is with MySQL).

None known.

Nothing known.

SPOPS::Manual::ImportExport

SPOPS::Import::DBI::TableTransform

Copyright (c) 2001-2004 intes.net, inc.. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Chris Winters <chris@cwinters.com>
2004-06-02 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.