NAME

blx::xsdsql - stored xsd schema and xml into database the database supported are DBM (with MLDBM), oracle,postgresql and mysql see blx::xsdsql::connection for examples of connection to a specific database

VERSION

0.10.0

DESCRIPTION

this manual describe the basically use of xsdsql API

for a complete description of the api see blx::xsdsql::connection blx::xsdsql::schema_repository blx::xsdsql::schema_repository::catalog blx::xsdsql::schema_repository::catalog_xml blx::xsdsql::xsd_parser

SYNOPSYS

create the database connection

use DBI;

my $dbi=DBI->connect( #get a database connection - see the DBI manual for DBI::connect arguments 'DBI:Pg:host=127.0.0.1:dbname=mydb','user','pwd' ,{ Raise_error => 1,Autocommit => 0,pg_enable_utf8=> 1} )

another method is:

use blx::xsdsql::connection;

my $conn=blx::xsdsql::connection->new( CONNECTION_STRING => 'sql::pg:myuser/mypwd@mydb:127.0.0.1:5432;RaiseError => 1,AutoCommit => 0,pg_enable_utf8 => 1' )

my $dbi=DBI->connect($conn->get_connection_list);

create the repository

use blx::xsdsql::schema_repository;

my $repo=blx::xsdsql::schema_repository->new( #create the repository object #the repository contain the base objects for all catalogs #and must be create before create a catalog DB_CONN => $dbi ,OUTPUT_NAMESPACE => 'sql' # output namespace can be omitted - 'sql' is the default ,DB_NAMESPACE => "pg" # is a code for postgresql # see the class method blx::xsdsql::schema_repository::get_namespaces for valid namespaces );

$repo->create_repository; # create the objects on the database

$conn->commit;

create the catalog

use blx::xsdsql::xsd_parser;

my $parser= blx::xsdsql::xsd_parser->new( OUTPUT_NAMESPACE => $conn->get_output_namespace ,DB_NAMESPACE => $conn->get_db_namespace );

my $schema=$parser->parsefile( #parse a schema file 'schema001.xsd' ,TABLE_PREFIX => 'T001' ,VIEW_PREFIX => 'V001' );

my $catalog=$repo->create_catalog('catalog001',$schema); #now the catalog is create

$conn->commit; # commit the data written into the repository

store an xml file into the repository

my $catalog=$repo->get_catalog('catalog001');

my $catalog_xml=$catalog->get_catalog_xml;

open(my $fd,'<','1.xml');

my $id=$catalog_xml->store_xml( #store xml with name ,XML_NAME => 'xml001' ,FD => $fd );

or

my $id=$catalog_xml->store_xml( #store xml without name FD => $fd );

$conn->commit; # commit the data written into the repository

emit an xml to stdout

my $id=$catalog_xml->put_xml( #emit an xml from name to stdout XML_NAME => 'xml001' ,FD => *STDOUT );

or

my $id=$catalog_xml->put_xml( #emit an xml from id to stdout ID => $id );

delete an xml stored into the repository

use File::Spec;

open (my fd,'>',File::Spec->devnull());

my $id=$catalog_xml->put_xml( #emit an xml to null device XML_NAME => 'xml001' ,FD => $fd ,DELETE => 1 );

print join("\n",$repo->get_catalog_names),"\n";

for my $r($catalog->get_xml_stored) { print join(",",map { defined $_ ? $_ : '' },@$r),"\n"; }

for my $catalog($repo->get_all_catalogs) { for my $r($catalog->get_xml_stored) { next unless defined $r->[2]; print $r->[2],"\n"; } }

SEE ALSO

blx::xsdsql::schema_repository

blx::xsdsql::schema_repository::catalog

blx::xsdsql::schema_repository::catalog_xml

blx::xsdsql::xsd_parser

BUGS

Please report any bugs or feature requests to https://rt.cpan.org/Public/Bug/Report.html?Queue=XSDSQL

AUTHOR

lorenzo.bellotti, <pauseblx@gmail.com>

COPYRIGHT

Copyright (C) 2010 by lorenzo.bellotti

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

See http://www.perl.com/perl/misc/Artistic.html