From faber at linuxnj.com Fri Mar 10 08:36:08 2006 From: faber at linuxnj.com (Faber Fedor) Date: Fri, 10 Mar 2006 11:36:08 -0500 Subject: [ABE.pm] Automatic generation of database tables In-Reply-To: <20050907023250.GL10481@manxome.org> References: <20050907023250.GL10481@manxome.org> Message-ID: <200603101136.08778.faber@linuxnj.com> Before I write my own script, does anyone know of a technique or script to automagically generate a table (well, the SQL at least) from a CSV file which contains a header in it? -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From fiedlert at gmail.com Fri Mar 10 08:50:33 2006 From: fiedlert at gmail.com (Ted Fiedler) Date: Fri, 10 Mar 2006 11:50:33 -0500 Subject: [ABE.pm] Automatic generation of database tables In-Reply-To: <200603101136.08778.faber@linuxnj.com> References: <20050907023250.GL10481@manxome.org> <200603101136.08778.faber@linuxnj.com> Message-ID: <814422ce0603100850i66a5cf4fu40847b67e55a896@mail.gmail.com> Its been a while, but Ive used http://search.cpan.org/~ezdb/Data-Table-1.43/Table.pm in the past for things like this. On 3/10/06, Faber Fedor wrote: > Before I write my own script, does anyone know of a technique or script to > automagically generate a table (well, the SQL at least) from a CSV file > which contains a header in it? > > -- > > Regards, > > Faber Fedor > President > Linux New Jersey, Inc. > 908-320-0357 > 800-706-0701 > > http://www.linuxnj.com > > > > _______________________________________________ > ABE-pm mailing list > ABE-pm at pm.org > http://mail.pm.org/mailman/listinfo/abe-pm > -- One of my most productive days was throwing away 1000 lines of code. -- Ken Thompson From faber at linuxnj.com Fri Mar 10 09:07:35 2006 From: faber at linuxnj.com (Faber Fedor) Date: Fri, 10 Mar 2006 12:07:35 -0500 Subject: [ABE.pm] Automatic generation of database tables In-Reply-To: <814422ce0603100850i66a5cf4fu40847b67e55a896@mail.gmail.com> References: <20050907023250.GL10481@manxome.org> <200603101136.08778.faber@linuxnj.com> <814422ce0603100850i66a5cf4fu40847b67e55a896@mail.gmail.com> Message-ID: <200603101207.35212.faber@linuxnj.com> On Friday 10 March 2006 11:50 am, Ted Fiedler wrote: > Its been a while, but Ive used > http://search.cpan.org/~ezdb/Data-Table-1.43/Table.pm in the past for > things like this. That will easily(?) read the file into a table object, but I don't see how to generate an SQL table from it. Am I missing something or do I do that? -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From rjbs-perl-abe at lists.manxome.org Fri Mar 10 09:22:26 2006 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Fri, 10 Mar 2006 12:22:26 -0500 Subject: [ABE.pm] Automatic generation of database tables In-Reply-To: <200603101207.35212.faber@linuxnj.com> References: <20050907023250.GL10481@manxome.org> <200603101136.08778.faber@linuxnj.com> <814422ce0603100850i66a5cf4fu40847b67e55a896@mail.gmail.com> <200603101207.35212.faber@linuxnj.com> Message-ID: <20060310172226.GL31597@manxome.org> * Faber Fedor [2006-03-10T12:07:35] > On Friday 10 March 2006 11:50 am, Ted Fiedler wrote: > > Its been a while, but Ive used > > http://search.cpan.org/~ezdb/Data-Table-1.43/Table.pm in the past for > > things like this. > > That will easily(?) read the file into a table object, but I don't see how to > generate an SQL table from it. Am I missing something or do I do that? There's http://search.cpan.org/dist/Rosetta-Utility-SQLBuilder/ It's sort of complicated, but can do anything to build any kind of SQL for any server, basically. http://search.cpan.org/dist/SQL-Builder is similar. Both are probably more than you need. They're complicated because they're all things to all people. We use something here that can transform a YAML file into a MySQL CREATE TABLE. I'll see if I can release it to you. -- rjbs -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/pipermail/abe-pm/attachments/20060310/c7b7ff4d/attachment.bin From fiedlert at gmail.com Fri Mar 10 09:27:53 2006 From: fiedlert at gmail.com (Ted Fiedler) Date: Fri, 10 Mar 2006 12:27:53 -0500 Subject: [ABE.pm] Automatic generation of database tables In-Reply-To: <200603101207.35212.faber@linuxnj.com> References: <20050907023250.GL10481@manxome.org> <200603101136.08778.faber@linuxnj.com> <814422ce0603100850i66a5cf4fu40847b67e55a896@mail.gmail.com> <200603101207.35212.faber@linuxnj.com> Message-ID: <814422ce0603100927n7509b7cp8405620858d623@mail.gmail.com> You'd have to generate the code to write out to SQL. Here is a script that takes a cvs file and creates a mysql table using DBI. Its from a set of PC inventory scripts that I wrote. You may be able to reuse some code to do what you need. I also got a lot of ideas from http://perlmonks.org/?node_id=284436. #!Perl # buildinventorydb.pl # BUilds the necessary db tables # to extract pc inventory data # # Ted Fiedler # #use warnings; use strict; #use diagnostics; use DBI; ############################### # Hardcode the dir for now... # ############################### my $DIR = "C:\\Documents and Settings\\TFIEDLER\\Desktop\\Code\\inventory\\invs"; ################# # Connect to db # ################# my $dbh = DBI->connect('DBI:mysql:Inventory:mysqlserver.mydom.com', 'username, 'pass', { RaiseError => 1, AutoCommit => 1 }); my $productQuery = qq{select ProductID from software}; my $sth = $dbh->prepare($productQuery); $sth->execute; my @PRODUCTIDs=(); while ( my ($id) = $sth->fetchrow_array ) { push @PRODUCTIDs, $id; } my $pclistQuery = qq{select pcname from pclist}; $sth = $dbh->prepare($pclistQuery); $sth->execute; my @PCs = (); while ( my ($pc) = $sth->fetchrow_array ) { push @PCs, $pc; } my %pclist = (); my $drop_query = qq{ DROP TABLE IF EXISTS pc_inventory }; $dbh->do($drop_query); my $create_query = qq{ CREATE TABLE pc_inventory (id int NOT NULL PRIMARY KEY AUTO_INCREMENT, DisplayName varchar(75), version varchar(25), ProductID varchar(75), pc varchar(20), InstallDate varchar(20) ) }; $dbh->do($create_query); my @fields = (qw(DisplayName version ProductID pc InstallDate)); my $fieldlist = join ",", @fields; my $field_placeholders = join ", ", map {'?'} @fields; my $insert_query = qq{ INSERT INTO pc_inventory ( $fieldlist ) VALUES ( $field_placeholders)}; my $new_sth = $dbh->prepare( $insert_query ); my %known = (); for my $pcname (@PCs) { my $dir; open $dir, "$DIR/$pcname\.csv" or die "unable to open $DIR/$pcname\.csv:$!\n"; for my $line (<$dir>) { chomp($line); next if ( $line =~ /^Publisher.*/ ); # Added to delete all instances of "+" $line =~ s/\++//g; my ( $Publisher, $version, $InstallDate, $DisplayName, $ProductID ) = split /,/, $line; ################################################### # One of ProductID or DisplayName must be defined # # or we'll be sorting through excess garbage # ################################################### next if ( defined ($ProductID) eq "" and defined ($DisplayName) eq "" ); for (@PRODUCTIDs) { $new_sth->execute($DisplayName, $version, $ProductID, $pcname, $InstallDate) if ( grep /$ProductID/, $_ ); } ## End of "for (@PRODUCTIDs)" ## } ## End of "for my $line (<$dir>)" ## } ## End of "for my $pcname (@PCs)" ## # __EOF__ On 3/10/06, Faber Fedor wrote: > On Friday 10 March 2006 11:50 am, Ted Fiedler wrote: > > Its been a while, but Ive used > > http://search.cpan.org/~ezdb/Data-Table-1.43/Table.pm in the past for > > things like this. > > That will easily(?) read the file into a table object, but I don't see how to > generate an SQL table from it. Am I missing something or do I do that? > > -- > > Regards, > > Faber Fedor > President > Linux New Jersey, Inc. > 908-320-0357 > 800-706-0701 > > http://www.linuxnj.com > > > > _______________________________________________ > ABE-pm mailing list > ABE-pm at pm.org > http://mail.pm.org/mailman/listinfo/abe-pm > -- One of my most productive days was throwing away 1000 lines of code. -- Ken Thompson From faber at linuxnj.com Wed Mar 22 16:21:14 2006 From: faber at linuxnj.com (Faber Fedor) Date: Wed, 22 Mar 2006 19:21:14 -0500 Subject: [ABE.pm] Perl modules with Ruby Message-ID: <200603221921.14480.faber@linuxnj.com> I want to play with Ruby, but I have several functions in a Perl module that I don't want to rewrite right away. Is there a way to use my Perl module within Ruby? I've found one Ruby module that supposedly will let me do it, but it's no longer maintained. BTW, I've written several business-date functions that I couldn't find a module for (getNextBusinessDay, getPreviousBusinessDay, getNthBusinessDayOfMonth, etc.). Did I miss a module somewhere? -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From rjbs-perl-abe at lists.manxome.org Wed Mar 22 17:03:02 2006 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Wed, 22 Mar 2006 20:03:02 -0500 Subject: [ABE.pm] Perl modules with Ruby In-Reply-To: <200603221921.14480.faber@linuxnj.com> References: <200603221921.14480.faber@linuxnj.com> Message-ID: <20060323010302.GK26272@manxome.org> * Faber Fedor [2006-03-22T19:21:14] > I want to play with Ruby, but I have several functions in a Perl module that > I don't want to rewrite right away. Is there a way to use my Perl module > within Ruby? I don't think so... you can go the other way, but I don't know of any way to use Perl in Ruby. > BTW, I've written several business-date functions that I couldn't find a > module for (getNextBusinessDay, getPreviousBusinessDay, > getNthBusinessDayOfMonth, etc.). Did I miss a module somewhere? http://search.cpan.org/dist/Date-Calc/Calc.pod That's probably the most general purpose module that does that sort of thing. There's also: http://search.cpan.org/~desiminer/Date-Business-1.2/Business.pm -- rjbs -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/pipermail/abe-pm/attachments/20060323/278ff23c/attachment.bin From rjbs-perl-abe at lists.manxome.org Wed Mar 22 17:03:02 2006 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Wed, 22 Mar 2006 20:03:02 -0500 Subject: [ABE.pm] Perl modules with Ruby In-Reply-To: <200603221921.14480.faber@linuxnj.com> References: <200603221921.14480.faber@linuxnj.com> Message-ID: <20060323010302.GK26272@manxome.org> * Faber Fedor [2006-03-22T19:21:14] > I want to play with Ruby, but I have several functions in a Perl module that > I don't want to rewrite right away. Is there a way to use my Perl module > within Ruby? I don't think so... you can go the other way, but I don't know of any way to use Perl in Ruby. > BTW, I've written several business-date functions that I couldn't find a > module for (getNextBusinessDay, getPreviousBusinessDay, > getNthBusinessDayOfMonth, etc.). Did I miss a module somewhere? http://search.cpan.org/dist/Date-Calc/Calc.pod That's probably the most general purpose module that does that sort of thing. There's also: http://search.cpan.org/~desiminer/Date-Business-1.2/Business.pm -- rjbs -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/pipermail/abe-pm/attachments/20060323/278ff23c/attachment-0001.bin From faber at linuxnj.com Wed Mar 22 18:05:27 2006 From: faber at linuxnj.com (Faber Fedor) Date: Wed, 22 Mar 2006 21:05:27 -0500 Subject: [ABE.pm] Perl modules with Ruby In-Reply-To: <20060323010302.GK26272@manxome.org> References: <200603221921.14480.faber@linuxnj.com> <20060323010302.GK26272@manxome.org> Message-ID: <200603222105.27637.faber@linuxnj.com> On Wednesday 22 March 2006 8:03 pm, Ricardo SIGNES wrote: > * Faber Fedor [2006-03-22T19:21:14] > > I want to play with Ruby, but I have several functions in a Perl module > > that I don't want to rewrite right away. Is there a way to use my Perl > > module within Ruby? > > I don't think so... you can go the other way, but I don't know of any way > to use Perl in Ruby. C'est la vie. Now to come up with a program idea that justifies writing most stuff from scratch... > > > BTW, I've written several business-date functions that I couldn't find a > > module for (getNextBusinessDay, getPreviousBusinessDay, > > getNthBusinessDayOfMonth, etc.). Did I miss a module somewhere? > > http://search.cpan.org/dist/Date-Calc/Calc.pod Date-Calc has an odd concept of business days. IIRC they're Julian. > There's also: > > http://search.cpan.org/~desiminer/Date-Business-1.2/Business.pm The looks exactly what I was looking for. How did you find it? I went googling for "perl", "business", "date" and various permutations for weeks! -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From rjbs-perl-abe at lists.manxome.org Wed Mar 22 18:15:54 2006 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Wed, 22 Mar 2006 21:15:54 -0500 Subject: [ABE.pm] Perl modules with Ruby In-Reply-To: <200603222105.27637.faber@linuxnj.com> References: <200603221921.14480.faber@linuxnj.com> <20060323010302.GK26272@manxome.org> <200603222105.27637.faber@linuxnj.com> Message-ID: <20060323021554.GL26272@manxome.org> * Faber Fedor [2006-03-22T21:05:27] > > > > http://search.cpan.org/~desiminer/Date-Business-1.2/Business.pm > > The looks exactly what I was looking for. How did you find it? I went > googling for "perl", "business", "date" and various permutations for weeks! I searched the CPAN instead of the whole internet. http://search.cpan.org/search?query=date+business&mode=all -- rjbs -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/pipermail/abe-pm/attachments/20060323/09234f8b/attachment.bin