DBIx::SQLEngine::do_create_table

ContextThe Perl module DBIx::SQLEngine
Purpose of this documentTo document the method do_create_table()
DeveloperM. Simon Cavalletto, simonm@cavalletto.org
ContributorPiglet / EJ Evans, piglet@piglet.org
ContributorEric Schneider, roark@evolution.com
Home pagehttp://www.evoscript.org
Syntaxdo_create_table(table => $table_name, [{column definition}...])

The following tables define 'column definition'
Each column definition is a hash ref of the form...
SyntaxInterpretationNote
name => $nameThe name of the columnMandatory
type => $typeThe type of the columnMandatory
length => $lengthThe length (width) of text fieldsDefault: 255
required => $requiredThe null/not null flagDefault: undef

NoteIn the following table...
1In the first 3 columns, '-' means: N/A (Not Applicable)
2In the remaining columns, '-' means: See the Default column
ColumnInterpretation
TypeValues for the $type field
ContextContext in which $type has some effect
DefaultEffect of $type within DBIx::SQLEngine::Default
CSVEffect of $type within DBIx::SQLEngine::CSV
MySQLEffect of $type within DBIx::SQLEngine::Mysql
MSSQLEffect of $type within DBIx::SQLEngine::MSSQL
PgEffect of $type within DBIx::SQLEngine::Pg

TypeContextDefaultCSVMySQLMSSQLPg
primary-PRIMARY KEY ($name)(Ignored)---
textif ($length < 256)varchar($length)----
textif ($length >= 256)confess(...)----
requiredif (! $required)-----
requiredif ($required)not null----
sequential---int auto_increment primary key-serial
binary---blob-bytea

A tested example

#!/usr/bin/perl

use strict;
use warnings;

use DBIx::SQLEngine;
use Error qw/:try/;

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

try
{
	my($engine) = DBIx::SQLEngine -> new
	(
		'DBI:mysql:test:127.0.0.1', 'route', 'bier',
		{
			AutoCommit          => 1,
			HandleError         => sub {Error::Simple -> record($_[0]); 0},
			PrintError          => 0,
			RaiseError          => 1,
			ShowErrorStatement  => 1,
		}
	);
	my($table_name) = 'sqle';
	my($column) =
	[
		{
			name   => 'sqle_id',
			type   => 'sequential',
		},
		{
			name   => 'sqle_name',
			type   => 'text',
			length => 255,
		},
	];
	$engine -> do_drop_table($table_name);
	$engine -> do_create_table($table_name, $column);
	$engine -> do_insert(table => $table_name, values => {sqle_name => 'One'});
	$engine -> do_insert(table => $table_name, values => {sqle_name => 'Two'});
	$engine -> do_insert(table => $table_name, values => {sqle_name => 'Three'});

	my($dataset) = $engine -> fetch_select(table => $table_name);
	my($count)   = 0;

	for my $data (@$dataset)
	{
		$count++;
		print "Row: $count.", (map{"\t$_ => " . ($$data{$_} ? $$data{$_} : 'NULL')} sort keys %$data), "\n";
	}
}
catch Error::Simple with
{
	my($error) = $_[0] -> text();
	chomp $error;
	print $error;
};
		

Author

Ron Savage.

Home page: http://savage.net.au/index.html

Licence

Australian Copyright © 2002 Ron Savage. All rights reserved.

	All Programs of mine are 'OSI Certified Open Source Software';
	you can redistribute them and/or modify them under the terms of
	The Artistic License, a copy of which is available at:
	http://www.opensource.org/licenses/index.html