switcherswitcherswitcherswitcher

User login

Who's online

There are currently 0 users and 3 guests online.

Who's new

  • gish_85
  • vsn3480
  • fengzhixuan
  • caseybergman
  • tomas81

RSS Feeds

Technorati

trouble with perl module

hi all.

need some expertise once again. i'm trying to use this module i found on cpan:

http://search.cpan.org/~metzzo/XML-RDB-1.1/RDB.pm

its supposed to convert an xml file or shema into an sql schema using mysql or postgresql.

i've tried it a couple of times but i keep getting the following error:

Illegal primary key: >'id'; at /usr/local/share/perl/5.8.7/DBIx/DBSchema/Table.pm line 288.

i've had a look at the relevant line in 'Table.pm' which looks like:

sub primary_key {
my($self,$value)=@_;
if ( defined($value) ) {
$self->{primary_key} = $value;
} else {
#$self->{primary_key};
#hmm. maybe should untaint the entire structure when it comes off disk
# cause if you don't trust that, ?
$self->{primary_key} =~ /^(w*)$/ # this is problem line 288!
#aah!
or die \"Illegal primary key: \", $self->{primary_key};
$1;
}
}

bearing in mind that i have not altered any of this file and have followed their instructions (at least i think i have!) i don't quite understand why i get such an error. :|

does anyone mind having a look? am i being silly again? do you know any other means to accomplish such a task? it would shave weeks off my project & allow me to do more interesting stuff.

i'll attach my script ('xml_rdb.pl' - which is more or less the same as on cpan). i recommend you download the perl module (XML::RDB) from cpan, and see if u get the same error.

as usuall i much appreciate your help! :mrgreen:

thanks

nelo

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Submitted by dan on September 2, 2008 - 1:43pm.

Two years later and the Perl module is still broken!

I also had trouble installing this using CPAN...

Anyway, my question is this, Why does this module need to contact the database if all I want to do is generate the schema?

Also tab delimited files of data would be fine (great actually) - seems a shame to force the fancy DBI stuff.

Submitted by Daz on June 23, 2006 - 8:32pm.

Hi Nelo,

Can you post the XML file that you are trying to convert please. I think you might be getting the errors from there (modules on CPAN normally aren't broken as soon as you get them).

Ta,

Daz

Submitted by j1n3l0 on June 26, 2006 - 8:44am.

sorry again

sooooooooooooooo sorry :oops:

Submitted by Daz on June 26, 2006 - 11:33am.

j1n3l0 wrote:

sorry again

sooooooooooooooo sorry :oops:

No worries boss,

Sorry but I really can't figure that one out! :oops:

I've tried everything that I can think of... It seems that there is something wrong with the DBIx::DBSchema::Table module (that you pasted in your first cry for help) - i've tried doctoring that so it stops throwing 'die' statements, but things just don't seem to work... You could try emailing the author (Ivan Kohler <ivan>) - he might be able to shed some light on your issues. :x

What is is you're trying to do? I know you want to convert an XML schema to a SQL schema - but are you trying to do this for lots of different XML schemas? If not (i.e. you just have one XML schema, but LOTS of files to import into a database), it could be easier to write your own import script. All you then have to do is produce a relevant database schema (they explain the conversion process they use in the Perl module on the page that you linked to).

Sorry I couldn't be much more use. Anyone else tried and had any more luck?!?!?

Submitted by j1n3l0 on June 26, 2006 - 12:18pm.

thanks darren at least i know i'm not crazy!

i am doing just that ... designing my own database and preparing a script to parse alot of xml files and populate the database. this module would have just saved alot of time in the entire process. i'll look at their explanation a bit more but at the moment i'm just doing it manually :cry:

thanks. if anyone else has other ideas or suggestions i would still be interested ;)

nelo

Submitted by stevo on June 26, 2006 - 10:57pm.

Hi Nelo,

I haven't looked at the module at all, and you've prob sussed this, but the regexp will throw your error if the primary keyin your table (which I guess should be an autoincrement id) contains non-word characters. So does the error suggest that you have *exactly* 'id'; in the db ? What does the xml_rdb_schema.sql look like ?

Something i find very usefull when working with Perl objects is the module Data::Dumper - in this case I'd add a 'warn Dumper($self)' to check if the above idea is right.

Also your xml in simple_example.txt id not closed correctly

Just some random late night thoughts,

Cheers,

Steve

Submitted by j1n3l0 on June 27, 2006 - 9:03am.

thanks steve

the trouble i'm having with this module arises in places i'm not meant to (and don't) alter :-o

i never supply an 'id' to it. the way it works it generates its own primary key for you which should be 'id'. it then interpretes the xml nodes into sql schema statements (create table xml_tag and so on) and saves them in a file supplied by you (in this case xml_rdb_schema.sql).

but its not happening for me :tickedoff:

thanks for the tip on data::dumper. i'm trying to use it in another method. and as for 'simple_example.txt' not being closed well ... how do you mean? its got a root element right? i cant see a problem ... but then again i am blind these days :-D

thanks though

nelo

Submitted by TimHunt on October 25, 2006 - 3:29am.

Long post - bottom line, comment out the PRIMARY_KEY line in config file; DBIx::DBSchema::Table is your friend.

I've just downloaded and installed this module (XML::RDB) from CPAN. I get exactly the same error (invalid ID). If you poke around in the DBIx::DBSchema::Table code you see the regex captures any word / numeric / underscore characters to $1 and sends this to the primary key value. The regex had anchors at the start and end, which means that the *whole* string passed in as a primary key must be in [A-Za-z0-9_] . It seems that there's a spurious '>' being injected somewhere. This is at the start of the pk string, so removing the ^ anchor will skip this and only take the [A-Za-z0-9_] characters that anchor to the end of the string.

I'm guessing (after an hour's work) that the problem is in XML::RDB's handling of its config file. If you comment out the PRIMARY_KEY field in the config file :
# Name appended to primary key of every generated table
#PK_NAME => 'id';

then the default constant defined in RDB.pm is used instead:
tjh@oeb-isg-webdev:/usr/local/share/perl/5.8.7/XML$ grep PK_ RDB.pm
use constant PK_NAME => 'id';
PK_NAME => $config->{PK_NAME} || PK_NAME,

and running the standard script:

#!/usr/bin/perl -w
use strict;
use warnings;

use Data::Dumper;
use XML::RDB;

#Give our DB's DSN & username/password
my $rdb = new XML::RDB(config_file => 'db_config');

# That's all fine & dandy but what if you've got an XML Schema???
#
# the first 2 calls are the same:
$rdb->make_tables(\"my_xsd_file.xsd\");

gives me the following output:
perl schema_insert.pl
Use of uninitialized value in scalar chomp at /usr/local/share/perl/5.8.7/XML/RDB.pm line 81, <C> line 5.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.8.7/XML/RDB.pm line 83, <C> line 5.
Use of uninitialized value in scalar chomp at /usr/local/share/perl/5.8.7/XML/RDB.pm line 81, <C> line 6.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.8.7/XML/RDB.pm line 83, <C> line 6.
Use of uninitialized value in scalar chomp at /usr/local/share/perl/5.8.7/XML/RDB.pm line 81, <C> line 9.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.8.7/XML/RDB.pm line 83, <C> line 9.
Use of uninitialized value in scalar chomp at /usr/local/share/perl/5.8.7/XML/RDB.pm line 81, <C> line 12.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.8.7/XML/RDB.pm line 83, <C> line 12.
Use of uninitialized value in scalar chomp at /usr/local/share/perl/5.8.7/XML/RDB.pm line 81, <C> line 15.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.8.7/XML/RDB.pm line 83, <C> line 15.
Use of uninitialized value in scalar chomp at /usr/local/share/perl/5.8.7/XML/RDB.pm line 81, <C> line 18.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.8.7/XML/RDB.pm line 83, <C> line 18.
Use of uninitialized value in scalar chomp at /usr/local/share/perl/5.8.7/XML/RDB.pm line 81, <C> line 22.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.8.7/XML/RDB.pm line 83, <C> line 22.
Use of uninitialized value in scalar chomp at /usr/local/share/perl/5.8.7/XML/RDB.pm line 81, <C> line 23.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.8.7/XML/RDB.pm line 83, <C> line 23.
-- xs:complexType -> xs:attribute
-- xs:sequence -> xs:element
-- xs:schema -> xs:element
-- xs:choice -> xs:element
Use of uninitialized value in pattern match (m//) at /usr/local/share/perl/5.8.7/DBIx/DBSchema/Table.pm line 288.
Use of uninitialized value in pattern match (m//) at /usr/local/share/perl/5.8.7/DBIx/DBSchema/Table.pm line 288.
Use of uninitialized value in pattern match (m//) at /usr/local/share/perl/5.8.7/DBIx/DBSchema/Table.pm line 288.
Use of uninitialized value in join or string at /usr/local/share/perl/5.8.7/XML/RDB/MakeTables.pm line 317.
CREATE TABLE >'gen';_xs_attribute (
>'gen';_xs_complextype_>'fk'; integer ,
>'gen';_xs_attribute_type_attribute >'varchar('.TEXT_WIDTH.')'; NULL ,
>'gen';_xs_attribute_value >'varchar('.TEXT_WIDTH.')'; NULL ,
>'gen';_xs_attribute_name_attribute >'varchar('.TEXT_WIDTH.')'; NULL ,
>'gen';_xs_attribute_use_attribute >'varchar('.TEXT_WIDTH.')'; NULL ,
id integer ,
PRIMARY KEY (id)
);

CREATE TABLE >'gen';_link_tables (
one_table >'varchar('.TEXT_WIDTH.')'; ,
many_table >'varchar('.TEXT_WIDTH.')';
);

CREATE TABLE >'gen';_element_names (
db_name >'varchar('.TEXT_WIDTH.')'; ,
xml_name >'varchar('.TEXT_WIDTH.')';
);

CREATE TABLE dbix_sequence_state (
state_id integer NULL ,
dataset >'varchar('.TEXT_WIDTH.')'; NULL
);

CREATE TABLE >'gen';_xs_choice (
>'gen';_xs_choice_value >'varchar('.TEXT_WIDTH.')'; NULL ,
>'gen';_xs_choice_maxoccurs_attribute >'varchar('.TEXT_WIDTH.')'; NULL ,
id integer ,
PRIMARY KEY (id)
);

CREATE TABLE >'gen';_xs_schema (
>'gen';_xs_schema_xmlns_xdb_attribute >'varchar('.TEXT_WIDTH.')'; NULL ,
>'gen';_xs_schema_xmlns_xs_attribute >'varchar('.TEXT_WIDTH.')'; NULL ,
>'gen';_xs_schema_elementformdefault_attribute >'varchar('.TEXT_WIDTH.')'; NULL ,
>'gen';_xs_schema_value >'varchar('.TEXT_WIDTH.')'; NULL ,
>'gen';_xs_schema_xdb_storevarrayastable_attribute >'varchar('.TEXT_WIDTH.')'; NULL ,
id integer ,
PRIMARY KEY (id)
);

CREATE TABLE dbix_sequence_release (
released_id integer NULL ,
dataset >'varchar('.TEXT_WIDTH.')'; NULL ,
id integer ,
PRIMARY KEY (id)
);

CREATE TABLE >'gen';_xs_complextype (
>'gen';_xs_complextype_value >'varchar('.TEXT_WIDTH.')'; NULL ,
>'gen';_xs_complextype_mixed_attribute >'varchar('.TEXT_WIDTH.')'; NULL ,
>'gen';_xs_sequence_id integer NULL ,
id integer ,
PRIMARY KEY (id)
);

CREATE TABLE >'gen';_xs_element (
>'gen';_xs_choice_>'fk'; integer ,
>'gen';_xs_element_name_attribute >'varchar('.TEXT_WIDTH.')'; NULL ,
>'gen';_xs_sequence_>'fk'; integer ,
>'gen';_xs_element_ref_attribute >'varchar('.TEXT_WIDTH.')'; NULL ,
>'gen';_xs_schema_>'fk'; integer ,
>'gen';_xs_complextype_id integer NULL ,
>'gen';_xs_element_maxoccurs_attribute >'varchar('.TEXT_WIDTH.')'; NULL ,
>'gen';_xs_element_value >'varchar('.TEXT_WIDTH.')'; NULL ,
id integer ,
PRIMARY KEY (id)
);

CREATE TABLE >'gen';_xs_sequence (
>'gen';_xs_choice_id integer NULL ,
>'gen';_xs_sequence_value >'varchar('.TEXT_WIDTH.')'; NULL ,
id integer ,
PRIMARY KEY (id)
);

INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_attribute','xs:attribute');
INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_element_name_attribute','name');
INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_schema_elementformdefault_attribute','elementFormDefault');
INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_schema_xdb_storevarrayastable_attribute','xdb:storeVarrayAsTable');
INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_attribute_type_attribute','type');
INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_choice','xs:choice');
INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_schema','xs:schema');
INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_complextype','xs:complexType');
INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_element','xs:element');
INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_attribute_name_attribute','name');
INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_element_ref_attribute','ref');
INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_element_maxoccurs_attribute','maxOccurs');
INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_schema_xmlns_xdb_attribute','xmlns:xdb');
INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_choice_maxoccurs_attribute','maxOccurs');
INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_schema_xmlns_xs_attribute','xmlns:xs');
INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_complextype_mixed_attribute','mixed');
INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_sequence','xs:sequence');
INSERT INTO >'gen';_element_names VALUES ('>'gen';_xs_attribute_use_attribute','use');
INSERT INTO >'gen';_link_tables VALUES ('>'gen';_xs_complextype','xs_attribute');
INSERT INTO >'gen';_link_tables VALUES ('>'gen';_xs_sequence','xs_element');
INSERT INTO >'gen';_link_tables VALUES ('>'gen';_xs_schema','xs_element');
INSERT INTO >'gen';_link_tables VALUES ('>'gen';_xs_choice','xs_element');

Which is far mor than you wanted to see, but I'm going ot point the module's author to this post ;)

NOTE that there are lots of '>' in there - a quick burst of vim (or sed/ awk) can fix this at the file level, but it confirms suspicions

Hope this helps.
Tim.

Submitted by Anonymous (not verified) on May 2, 2007 - 7:25pm.

The "Use of uninitialized value in scalar chomp" occurs when there is a blank line at the end of the config file, remove that and that error goes away.

When using postgres the config file fails to parse because of a second '=' in the DSN= line of the config file.
----
"my" variable $base masks earlier declaration in same scope at /root/.cpan/build/XML-RDB-1.1/blib/lib/XML/RDB/UnpopulateSchema.pm line 298

change $base within the elseif to $base2
----
Use of uninitialized value in pattern match (m//) at /usr/local/share/perl/5.8.8/DBIx/DBSchema/Table.pm line 288.

is due to commenting out the PK_NAME => 'id' if you put it back in then you'll be back with the Illegal primary key: 'id' error from above.

Submitted by TimHunt on October 25, 2006 - 3:38am.

And the even shorter answer is that in XML::RDB he parses the config file splitting on \"=\" but has fat commas '=>' in the file itself.
Thus the split takes '>' plus any following text....

Get rid of the '>' from the config file and all will be well:
s{=>}{=}

Tim.

Submitted by j1n3l0 on November 5, 2006 - 9:58pm.

thanks a lot!

i shall go over it some time (seeing as i don't need that module anymore). it looks a very useful module if it works!

nelo