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::TableTransform(3) User Contributed Perl Documentation SPOPS::Import::DBI::TableTransform(3)

SPOPS::Import::DBI::TableTransform - Factory class for database-specific transformations

 my $table = qq/ CREATE TABLE blah ( id %%INCREMENT%% primary key,
                                     name varchar(50) ) /;
 my $transformer = SPOPS::Import::DBI::TableTransform->new( 'sybase' );
 $transformer->increment( \$table );
 print $table;

This class is a factory class for database-specific transformations. This means that SPOPS::Import::DBI::Table supports certain keys that can be replaced by database-specific values. This class is a factory for objects that take SQL data and do the replacements.

new( $database_type )

Create a new transformer using the database type $database_type.

Available database types are:

asany: Sybase Adaptive Server Anywhere
interbase: InterBase family (also: 'firebird')
mssql: Microsoft SQL Server
mysql: MySQL
oracle: Oracle
postgres: PostgreSQL (also: 'pg')
sybase: Sybase SQL Server/ASE

register_factory_type( $database_type, $transform_class )

Registers a new database type for a transformation class. You will need to run this every time you run the program.

If you develop a transformation class for a database not represented here, please email the author so it can be included with future distributions.

Creating a new subclass is extremely easy. You just need to subclass this class, then create a subroutine for each of the built-in transformations specified in SPOPS::Import::DBI::Table.

Each transformation takes two arguments: $self and a scalar reference to the SQL to be transformed. For example, here is a subclass for a made-up database:

 package SPOPS::Import::DBI::TableTransform::SavMor;

 use strict;
 use base qw( SPOPS::Import::DBI::TableTransform );

 sub increment {
    my ( $self, $sql ) = @_;
    $$sql =~ s/%%INCREMENT%%/UNIQUE_VALUE/g;
 }

 sub increment_type {
    my ( $self, $sql ) = @_;
    $$sql =~ s/%%INCREMENT_TYPE%%/INT/g;
 }

 sub datetime {
    my ( $self, $sql ) = @_;
    $$sql =~ s/%%DATETIME%%/timestamp/g;
 }

 1;

And then we could register the transformation agent with every run:

 SPOPS::Import::DBI::TableTransform->register_factory_type(
          'savmor', 'SPOPS::Import::DBI::TableTransform::SavMor' );
 my $transformer = SPOPS::Import::DBI::TableTransform->new( 'savmor' );
 my $sql = qq/ CREATE TABLE ( id %%INCREMENT%% primary key ) /;
 $transformer->increment( \$sql );
 print $sql;

Output:

 CREATE TABLE ( id UNIQUE_VALUE primary key )

None known.

Nothing known.

SPOPS::Import::DBI::Table

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.