Skip Menu |
 

This queue is for tickets about the DBIx-Class-Schema-Loader CPAN distribution.

Report information
The Basics
Id: 91764
Status: patched
Priority: 0/
Queue: DBIx-Class-Schema-Loader

People
Owner: Nobody in particular
Requestors: guidugli [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: DB2 Tables not being loaded
Date: Tue, 31 Dec 2013 15:20:51 -0200
To: bug-DBIx-Class-Schema-Loader [...] rt.cpan.org
From: Carlos Eduardo Panazzolo Guidugli <guidugli [...] gmail.com>
Download (untitled) / with headers
text/plain 779b
I have the following module version installed: DBD::DB2 (1.85) DBIx::Class::Schema::Loader (0.07038) DBIx::Class (0.08250) Trying to load tables from DB2 10.1 FP3 into DBIx, but result always empty. Tried to use db_schema and other flags without success. After taking a look at the code I found the problem. On /usr/local/share/perl5/DBIx/Class/Schema/Loader/DBI/DB2.pm, had to change line 159 from: return $self->dbh->tables($schema ? { TABLE_SCHEM => $schema } : undef); to return $self->dbh->tables($schema ? { TABLE_SCHEM => $schema,'TABLE_NAME' => '%' } : undef); It seems that on DBD::DB2 1.85 it is mandatory to gave TABLE_NAME => '%' . On my tests I could only fetch something with both table name and schema. Hope this helps. Thank you for these great modules!
Subject: Re: [rt.cpan.org #91764] DB2 Tables not being loaded
Date: Thu, 02 Jan 2014 14:47:18 +0100
To: bug-DBIx-Class-Schema-Loader [...] rt.cpan.org
From: ilmari [...] ilmari.org (Dagfinn Ilmari Mannsåker)
Download (untitled) / with headers
text/plain 609b
"Carlos Eduardo Panazzolo Guidugli via RT" <bug-DBIx-Class-Schema-Loader@rt.cpan.org> writes: Show quoted text
> It seems that on DBD::DB2 1.85 it is mandatory to gave TABLE_NAME => '%' . > On my tests I could only fetch something with both table name and schema.
Thanks for the report. Before I change it, could you confirm that TABLE_NAME => '%' also works on older versions of DBD::DB2 (and DB2 itself, if possible)? -- "I use RMS as a guide in the same way that a boat captain would use a lighthouse. It's good to know where it is, but you generally don't want to find yourself in the same spot." - Tollef Fog Heen
Subject: Re: [rt.cpan.org #91764] DB2 Tables not being loaded
Date: Thu, 2 Jan 2014 18:58:33 -0200
To: bug-DBIx-Class-Schema-Loader [...] rt.cpan.org
From: Carlos Eduardo Panazzolo Guidugli <guidugli [...] gmail.com>
Download (untitled) / with headers
text/plain 926b
Tested with 1.84,1.83 and 1.81. All of them performed successfully with TABLE_NAME => '%' . Thank you On Thu, Jan 2, 2014 at 11:47 AM, (Dagfinn Ilmari Mannsåker) via RT < bug-DBIx-Class-Schema-Loader@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=91764 > > > "Carlos Eduardo Panazzolo Guidugli via RT" > <bug-DBIx-Class-Schema-Loader@rt.cpan.org> writes: >
> > It seems that on DBD::DB2 1.85 it is mandatory to gave TABLE_NAME => '%'
> .
> > On my tests I could only fetch something with both table name and schema.
> > Thanks for the report. Before I change it, could you confirm that > TABLE_NAME => '%' also works on older versions of DBD::DB2 (and DB2 > itself, if possible)? > > -- > "I use RMS as a guide in the same way that a boat captain would use > a lighthouse. It's good to know where it is, but you generally > don't want to find yourself in the same spot." - Tollef Fog Heen > >
Download (untitled) / with headers
text/plain 153b
Thank you for testing. It turns out there was already a fix for this by Matt Phillips on a branch, so I've merged that and it'll be in the next release.
Subject: Re: [rt.cpan.org #91764] DB2 Tables not being loaded
Date: Mon, 6 Jan 2014 15:47:39 -0200
To: bug-DBIx-Class-Schema-Loader [...] rt.cpan.org
From: Carlos Eduardo Panazzolo Guidugli <guidugli [...] gmail.com>
Download (untitled) / with headers
text/plain 491b
Thank you. Do you of any bug regarding relationships? Somehow the loader detects the primary keys but is not building the has_many, belongs_to, etc methods. On Jan 2, 2014 8:07 PM, "Dagfinn Ilmari Mannsaker via RT" < bug-DBIx-Class-Schema-Loader@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=91764 > > > Thank you for testing. > > It turns out there was already a fix for this by Matt Phillips on a > branch, so I've merged that and it'll be in the next release. >
Subject: Re: [rt.cpan.org #91764] DB2 Tables not being loaded
Date: Mon, 6 Jan 2014 20:46:39 -0200
To: bug-DBIx-Class-Schema-Loader [...] rt.cpan.org
From: Carlos Eduardo Panazzolo Guidugli <guidugli [...] gmail.com>
Download (untitled) / with headers
text/plain 2.7k
Hi, found the problem that prevented DBIx-Class-Schema-Loader from getting the relationships. On the file /usr/local/share/perl5/DBIx/Class/Schema/Loader/DBI/DB2.pm, method _table_fk_info, the query is currently: my $sth = $self->{_cache}->{db2_fk} ||= $self->dbh->prepare(<<'EOF'); SELECT tc.constname, sr.reftabschema, sr.reftabname, kcu.colname, rkcu.colname, kcu.colseq, sr.deleterule, sr.updaterule FROM ........ The problem is that DB2 retrieves some columns preserving spaces at its end. So, the sr.reftabschema was bringing 'MYSCHEMA ' instead of 'MYSCHEMA'. To solve this problem I changed the query to: my $sth = $self->{_cache}->{db2_fk} ||= $self->dbh->prepare(<<'EOF'); SELECT trim(tc.constname), trim(sr.reftabschema), trim(sr.reftabname), trim(kcu.colname), trim(rkcu.colname), kcu.colseq, sr.deleterule, sr.updaterule FROM ......... With this change I was able to retrieve relation information. Another point that I'd like to show is about UNIQUE constraint in method _table_uniq_info. In DB2, it is possible to create a UNIQUE constraint, or a UNIQUE index with exactly the same effect. I was using unique indexes, so none appeared on the model. In order to make it work I created the unique constraints as well. I am new to DBIx, but what would happen if there are two unique constraints in the resulting class, as shown in the example below. __PACKAGE__->add_unique_constraint("SERVICELINE_SLNAME_UN", ["slname"]); __PACKAGE__->add_unique_constraint("SERVICELINE_SLNAME_IDX", ["slname"]); If this is not a problem, maybe the query could be changed to retrieve unique indexes as well: SELECT sc.colname, si.name, sc.colseq FROM sysibm.sysindexes si, sysibm.sysindexcoluse sc WHERE si.tbcreator=? and si.name=sc.indname and si.tbname=? AND si.uniquerule = 'U' UNION SELECT kcu.colname, kcu.constname, kcu.colseq FROM syscat.tabconst as tc JOIN syscat.keycoluse as kcu ON tc.constname = kcu.constname AND tc.tabschema = kcu.tabschema AND tc.tabname = kcu.tabname WHERE tc.tabschema = ? and tc.tabname = ? and tc.type = 'U' What do you think? Also, it may be a safe bet to add TRIM to char, varchar columns that have strings with variable length. Thank you On Mon, Jan 6, 2014 at 3:47 PM, Carlos Eduardo Panazzolo Guidugli < guidugli@gmail.com> wrote: Show quoted text
> Thank you. Do you of any bug regarding relationships? Somehow the loader > detects the primary keys but is not building the has_many, belongs_to, etc > methods. > On Jan 2, 2014 8:07 PM, "Dagfinn Ilmari Mannsaker via RT" < > bug-DBIx-Class-Schema-Loader@rt.cpan.org> wrote: >
>> <URL: https://rt.cpan.org/Ticket/Display.html?id=91764 > >> >> Thank you for testing. >> >> It turns out there was already a fix for this by Matt Phillips on a >> branch, so I've merged that and it'll be in the next release. >>
>
Subject: Re: [rt.cpan.org #91764] DB2 Tables not being loaded
Date: Tue, 7 Jan 2014 10:22:18 -0200
To: bug-DBIx-Class-Schema-Loader [...] rt.cpan.org
From: Carlos Eduardo Panazzolo Guidugli <guidugli [...] gmail.com>
Download (untitled) / with headers
text/plain 4.9k
Hi, About the unique constraints, here is the modified method that also include unique indexes. I put first the original query to get the unique constraints and then the query to get unique indexes. After, I check if there is already another constraint having the same columns. If yes, skip, otherwise store as result. In my tests the program below brought the unique constraints ignoring its duplicated indexes that I had created previously. When there isn't a constraint but only unique index, the program added that to the result. Hope this helps. sub _table_uniq_info { my ($self, $table) = @_; my @uniqs; my $sth = $self->{_cache}->{db2_uniq} ||= $self->dbh->prepare(<<'EOF'); SELECT trim(kcu.colname), trim(kcu.constname), kcu.colseq FROM syscat.tabconst as tc JOIN syscat.keycoluse as kcu ON tc.constname = kcu.constname AND tc.tabschema = kcu.tabschema AND tc.tabname = kcu.tabname WHERE tc.tabschema = ? and tc.tabname = ? and tc.type = 'U' UNION SELECT trim(sc.colname), trim(si.name), sc.colseq FROM sysibm.sysindexes si, sysibm.sysindexcoluse sc WHERE si.tbcreator=? and si.name=sc.indname and si.tbname=? AND si.uniquerule = 'U' EOF $sth->execute($table->schema, $table->name, $table->schema, $table->name); my %keydata; my %cache; while(my $row = $sth->fetchrow_arrayref) { my ($col, $constname, $seq) = @$row; push(@{$keydata{$constname}}, [ $seq, $self->_lc($col) ]); } foreach my $keyname (keys %keydata) { my @ordered_cols = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @{$keydata{$keyname}}; if ($cache{join '+', @ordered_cols}){ #print "Skipping $keyname since another constraint exists with the same columns\n"; next; } else { $cache{join '+', @ordered_cols}=1; } push(@uniqs, [ $keyname => \@ordered_cols ]); } $sth->finish; return \@uniqs; } On Mon, Jan 6, 2014 at 8:46 PM, Carlos Eduardo Panazzolo Guidugli < guidugli@gmail.com> wrote: Show quoted text
> Hi, found the problem that prevented DBIx-Class-Schema-Loader from getting > the relationships. > > On the file /usr/local/share/perl5/DBIx/Class/Schema/Loader/DBI/DB2.pm, > method _table_fk_info, the query is currently: > my $sth = $self->{_cache}->{db2_fk} ||= $self->dbh->prepare(<<'EOF'); > SELECT tc.constname, sr.reftabschema, sr.reftabname, > kcu.colname, rkcu.colname, kcu.colseq, > sr.deleterule, sr.updaterule > FROM ........ > > The problem is that DB2 retrieves some columns preserving spaces at its > end. So, the sr.reftabschema was bringing 'MYSCHEMA ' instead of > 'MYSCHEMA'. > > To solve this problem I changed the query to: > my $sth = $self->{_cache}->{db2_fk} ||= $self->dbh->prepare(<<'EOF'); > SELECT trim(tc.constname), trim(sr.reftabschema), trim(sr.reftabname), > trim(kcu.colname), trim(rkcu.colname), kcu.colseq, > sr.deleterule, sr.updaterule > FROM ......... > > With this change I was able to retrieve relation information. > > Another point that I'd like to show is about UNIQUE constraint in method > _table_uniq_info. In DB2, it is possible to create a UNIQUE constraint, or > a UNIQUE index with exactly the same effect. I was using unique indexes, so > none appeared on the model. In order to make it work I created the unique > constraints as well. I am new to DBIx, but what would happen if there are > two unique constraints in the resulting class, as shown in the example > below. > > __PACKAGE__->add_unique_constraint("SERVICELINE_SLNAME_UN", ["slname"]); > __PACKAGE__->add_unique_constraint("SERVICELINE_SLNAME_IDX", ["slname"]); > > If this is not a problem, maybe the query could be changed to retrieve > unique indexes as well: > > SELECT sc.colname, si.name, sc.colseq > FROM sysibm.sysindexes si, sysibm.sysindexcoluse sc > WHERE si.tbcreator=? and si.name=sc.indname and si.tbname=? AND > si.uniquerule = 'U' > > UNION > > SELECT kcu.colname, kcu.constname, kcu.colseq > FROM syscat.tabconst as tc > JOIN syscat.keycoluse as kcu > ON tc.constname = kcu.constname > AND tc.tabschema = kcu.tabschema > AND tc.tabname = kcu.tabname > WHERE tc.tabschema = ? and tc.tabname = ? and tc.type = 'U' > > What do you think? Also, it may be a safe bet to add TRIM to char, varchar > columns that have strings with variable length. > > Thank you > > > On Mon, Jan 6, 2014 at 3:47 PM, Carlos Eduardo Panazzolo Guidugli < > guidugli@gmail.com> wrote: >
>> Thank you. Do you of any bug regarding relationships? Somehow the loader >> detects the primary keys but is not building the has_many, belongs_to, etc >> methods. >> On Jan 2, 2014 8:07 PM, "Dagfinn Ilmari Mannsaker via RT" < >> bug-DBIx-Class-Schema-Loader@rt.cpan.org> wrote: >>
>>> <URL: https://rt.cpan.org/Ticket/Display.html?id=91764 > >>> >>> Thank you for testing. >>> >>> It turns out there was already a fix for this by Matt Phillips on a >>> branch, so I've merged that and it'll be in the next release. >>>
>>
>
Subject: Re: [rt.cpan.org #91764] DB2 Tables not being loaded
Date: Tue, 7 Jan 2014 13:05:45 -0200
To: bug-DBIx-Class-Schema-Loader [...] rt.cpan.org
From: Carlos Eduardo Panazzolo Guidugli <guidugli [...] gmail.com>
Download (untitled) / with headers
text/plain 6.2k
Sorry about all the emails, but I found something else related to unique constraints. The query: SELECT trim(sc.colname), trim(si.name), sc.colseq FROM sysibm.sysindexes si, sysibm.sysindexcoluse sc WHERE si.tbcreator=? and si.name=sc.indname and si.tbname=? AND si.uniquerule = 'U' Will return unique indexes AND unique constraints that do not have unique indexes. For example, suppose I have a constraint USER_EMAIL_UN (email column only). If I did not create a unique index, it will be shown in the query above. If I do create a unique index for the same column, then the index will be retrieved with the query above. If the only important thing is to know the columns that have unique restriction, than the query above may suffice. I am sending the result of the orginal query and the query above. I did create unique constraint for most of the unique indexes so I could use the original version, but notice that there are a couple of additional lines for the index that I did not had the unique constraint created. On Tue, Jan 7, 2014 at 10:22 AM, Carlos Eduardo Panazzolo Guidugli < guidugli@gmail.com> wrote: Show quoted text
> Hi, > > About the unique constraints, here is the modified method that also > include unique indexes. I put first the original query to get the unique > constraints and then the query to get unique indexes. After, I check if > there is already another constraint having the same columns. If yes, skip, > otherwise store as result. > > In my tests the program below brought the unique constraints ignoring its > duplicated indexes that I had created previously. When there isn't a > constraint but only unique index, the program added that to the result. > > Hope this helps. > > > sub _table_uniq_info { > my ($self, $table) = @_; > > my @uniqs; > > my $sth = $self->{_cache}->{db2_uniq} ||= $self->dbh->prepare(<<'EOF'); > SELECT trim(kcu.colname), trim(kcu.constname), kcu.colseq > FROM syscat.tabconst as tc > JOIN syscat.keycoluse as kcu > ON tc.constname = kcu.constname > AND tc.tabschema = kcu.tabschema > AND tc.tabname = kcu.tabname > WHERE tc.tabschema = ? and tc.tabname = ? and tc.type = 'U' > UNION > SELECT trim(sc.colname), trim(si.name), sc.colseq > FROM sysibm.sysindexes si, sysibm.sysindexcoluse sc > WHERE si.tbcreator=? and si.name=sc.indname and si.tbname=? AND > si.uniquerule = 'U' > > EOF > > $sth->execute($table->schema, $table->name, $table->schema, > $table->name); > > my %keydata; > my %cache; > while(my $row = $sth->fetchrow_arrayref) { > my ($col, $constname, $seq) = @$row; > push(@{$keydata{$constname}}, [ $seq, $self->_lc($col) ]); > } > foreach my $keyname (keys %keydata) { > my @ordered_cols = map { $_->[1] } sort { $a->[0] <=> $b->[0] } > @{$keydata{$keyname}}; > if ($cache{join '+', @ordered_cols}){ > #print "Skipping $keyname since another constraint exists with > the same columns\n"; > next; > } else { > $cache{join '+', @ordered_cols}=1; > } > push(@uniqs, [ $keyname => \@ordered_cols ]); > } > > $sth->finish; > > return \@uniqs; > } > > > > On Mon, Jan 6, 2014 at 8:46 PM, Carlos Eduardo Panazzolo Guidugli < > guidugli@gmail.com> wrote: >
>> Hi, found the problem that prevented DBIx-Class-Schema-Loader from >> getting the relationships. >> >> On the file /usr/local/share/perl5/DBIx/Class/Schema/Loader/DBI/DB2.pm, >> method _table_fk_info, the query is currently: >> my $sth = $self->{_cache}->{db2_fk} ||= $self->dbh->prepare(<<'EOF'); >> SELECT tc.constname, sr.reftabschema, sr.reftabname, >> kcu.colname, rkcu.colname, kcu.colseq, >> sr.deleterule, sr.updaterule >> FROM ........ >> >> The problem is that DB2 retrieves some columns preserving spaces at its >> end. So, the sr.reftabschema was bringing 'MYSCHEMA ' instead of >> 'MYSCHEMA'. >> >> To solve this problem I changed the query to: >> my $sth = $self->{_cache}->{db2_fk} ||= $self->dbh->prepare(<<'EOF'); >> SELECT trim(tc.constname), trim(sr.reftabschema), trim(sr.reftabname), >> trim(kcu.colname), trim(rkcu.colname), kcu.colseq, >> sr.deleterule, sr.updaterule >> FROM ......... >> >> With this change I was able to retrieve relation information. >> >> Another point that I'd like to show is about UNIQUE constraint in method >> _table_uniq_info. In DB2, it is possible to create a UNIQUE constraint, or >> a UNIQUE index with exactly the same effect. I was using unique indexes, so >> none appeared on the model. In order to make it work I created the unique >> constraints as well. I am new to DBIx, but what would happen if there are >> two unique constraints in the resulting class, as shown in the example >> below. >> >> __PACKAGE__->add_unique_constraint("SERVICELINE_SLNAME_UN", ["slname"]); >> __PACKAGE__->add_unique_constraint("SERVICELINE_SLNAME_IDX", ["slname"]); >> >> If this is not a problem, maybe the query could be changed to retrieve >> unique indexes as well: >> >> SELECT sc.colname, si.name, sc.colseq >> FROM sysibm.sysindexes si, sysibm.sysindexcoluse sc >> WHERE si.tbcreator=? and si.name=sc.indname and si.tbname=? AND >> si.uniquerule = 'U' >> >> UNION >> >> SELECT kcu.colname, kcu.constname, kcu.colseq >> FROM syscat.tabconst as tc >> JOIN syscat.keycoluse as kcu >> ON tc.constname = kcu.constname >> AND tc.tabschema = kcu.tabschema >> AND tc.tabname = kcu.tabname >> WHERE tc.tabschema = ? and tc.tabname = ? and tc.type = 'U' >> >> What do you think? Also, it may be a safe bet to add TRIM to char, >> varchar columns that have strings with variable length. >> >> Thank you >> >> >> On Mon, Jan 6, 2014 at 3:47 PM, Carlos Eduardo Panazzolo Guidugli < >> guidugli@gmail.com> wrote: >>
>>> Thank you. Do you of any bug regarding relationships? Somehow the loader >>> detects the primary keys but is not building the has_many, belongs_to, etc >>> methods. >>> On Jan 2, 2014 8:07 PM, "Dagfinn Ilmari Mannsaker via RT" < >>> bug-DBIx-Class-Schema-Loader@rt.cpan.org> wrote: >>>
>>>> <URL: https://rt.cpan.org/Ticket/Display.html?id=91764 > >>>> >>>> Thank you for testing. >>>> >>>> It turns out there was already a fix for this by Matt Phillips on a >>>> branch, so I've merged that and it'll be in the next release. >>>>
>>>
>>
>

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.



This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.