Views and tables without primary keys

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Views and tables without primary keys

IvorW
I have an application that uses a view. The application uses
DBIx::Class::Schema::Loader, and I get a warning about primary keys,
every time I start the app. The application works fine. In fact I get
the warning when I use a MySQL database, but not when I use sqlite.

I've traced it in the source code to DBIx::Class::Schema::Loader::Base,
and I attach a patch which removes the warning. In theory, this warning
might be serving some purpose if you had a genuine table that didn't
have a primary key, but not for a view. This warning just gets in the way.

--- /usr/share/perl5/DBIx/Class/Schema/Loader/Base.pm 2008-04-09 10:08:27.000000000 +0100
+++ ./Base.pm 2008-07-06 12:44:53.000000000 +0100
@@ -660,8 +660,8 @@
     }
 
     my $pks = $self->_table_pk_info($table) || [];
-    @$pks ? $self->_dbic_stmt($table_class,'set_primary_key',@$pks)
-          : carp("$table has no primary key");
+    $self->_dbic_stmt($table_class,'set_primary_key',@$pks)
+          if @$pks;
 
     my $uniqs = $self->_table_uniq_info($table) || [];
     $self->_dbic_stmt($table_class,'add_unique_constraint',@$_) for (@$uniqs);

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Views and tables without primary keys

claco
IvorW wrote:
> I have an application that uses a view. The application uses
> DBIx::Class::Schema::Loader, and I get a warning about primary keys,
> every time I start the app. The application works fine. In fact I get
> the warning when I use a MySQL database, but not when I use sqlite.
>
> I've traced it in the source code to DBIx::Class::Schema::Loader::Base,
> and I attach a patch which removes the warning. In theory, this warning
> might be serving some purpose if you had a genuine table that didn't
> have a primary key, but not for a view. This warning just gets in the way.

I'd say this warning should be kept if your using Loader to generate a
static schema (files), but it should be removed if you're using a
dynamic schema (on the fly).


-=Chris

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Views and tables without primary keys

Jonathan Rockway
* On Sun, Jul 06 2008, Christopher Laco wrote:

> IvorW wrote:
>> I have an application that uses a view. The application uses
>> DBIx::Class::Schema::Loader, and I get a warning about primary keys,
>> every time I start the app. The application works fine. In fact I get
>> the warning when I use a MySQL database, but not when I use sqlite.
>>
>> I've traced it in the source code to DBIx::Class::Schema::Loader::Base,
>> and I attach a patch which removes the warning. In theory, this warning
>> might be serving some purpose if you had a genuine table that didn't
>> have a primary key, but not for a view. This warning just gets in the way.
>
> I'd say this warning should be kept if your using Loader to generate a
> static schema (files), but it should be removed if you're using a
> dynamic schema (on the fly).

I disagree; I think the warning should be kept regardless.  When you are
generating code from the database, any small change to the database can
affect your code.  For that reason, when your app stops working, you
want as much info printed out as possible.  (Maybe Log::Dispatch or
similar would be more appropriate, so you can turn warnings off... but
since we are just sticking with 'warn', I say keep 'em.)

If you want the warning to shut up, don't use a dynamic schema.  Dynamic
schemas are nice for one-off scripts, but for anything else I would
really make a static schema and let DBIC be the canonical source for the
database definition.  If you are seeing the warning enough to patch the
library, you probably really want a static schema ;)

Regards,
Jonathan Rockway

--
print just => another => perl => hacker => if $,=$"

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Views and tables without primary keys

Matt S Trout
In reply to this post by IvorW
On Sun, Jul 06, 2008 at 01:21:22PM +0100, IvorW wrote:
> I have an application that uses a view. The application uses
> DBIx::Class::Schema::Loader, and I get a warning about primary keys,
> every time I start the app. The application works fine. In fact I get
> the warning when I use a MySQL database, but not when I use sqlite.
>
> I've traced it in the source code to DBIx::Class::Schema::Loader::Base,
> and I attach a patch which removes the warning. In theory, this warning
> might be serving some purpose if you had a genuine table that didn't
> have a primary key, but not for a view. This warning just gets in the way.

Then you should write a patch that turns the warning off -for- -views-.

--
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Loading...