[Dbix-class] Using and inter-linking multiple databases via DBIC: Can't find source
We are using Catalyst for a web app. We've split off the authentication database to facilitate multiple different apps using the same user credentials, but we're having trouble linking the auth db to the biz-info db. The generalized user/team credentials and related info are in Auth, and the actual business info for this app is in DB. Here's an object from the DB database: package Learn::Schema::DB::Result::TeamEmail; #... __PACKAGE__-belongs_to( team = 'Learn::Schema::Auth::Result::Team' ); Note that we're trying to get DB::TeamEmail to refer to Auth::Team here. And below is the related object from the Auth database: package Learn::Schema::Auth::Result::Team; #... __PACKAGE__-has_many( emails = 'Learn::Schema::DB::Result::TeamEmail', 'team' ); At this point we expect *$team-emails_rs* to work but instead we get Can't find source for Learn::Schema::DB::Result::TeamEmail because TeamEmail isn't in $self-source_registrations (full names) or $self-class_mappings (brief names) in the DBIx::Class::Schema::source() method. Pointers? Is there a different approach? Got a clue stick? ___ 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@lists.scsys.co.uk
Re: [Dbix-class] Handling Null values in search,find and upgrade
$rs-search( { field = undef } ) creates sql like so: ...where field is null... on the other hand $rs-search( { field = { '!=' = undef } } ) produces: ...where field is not null... On Wed, May 22, 2013 at 4:03 PM, Ekki Plicht (DF4OR) e...@plicht.de wrote: Hi. I am a little bit uncertain how DBIx::Class handles Null values in various circumstances. With the following table: id, { data_type = integer, is_auto_increment = 1, is_nullable = 0 }, id_prod, { data_type = integer, is_foreign_key = 1, is_nullable = 1 }, lang, { data_type = varchar, is_nullable = 1, size = 2 }, size, { data_type = varchar, is_nullable = 1, size = 2 }, atext, { data_type = text, is_nullable = 1 }, __PACKAGE__-set_primary_key(id); __PACKAGE__-add_unique_constraint(text_UNIQUE, [size, id_prod, lang]); What is the difference between -search( { size = 'S', lang = 'de', }, { key = 'text_UNIQUE' }); and -search( { size = 'S', lang = 'de', id_prod = undef }, { key = 'text_UNIQUE' }); In the first case one constraint component (id_prod) is missing entirely, in the second case it's present but set to undef. Which of these two cases would be preferrable if the value of 'id_prod' is Dont care? What I did so far to find it out myself: Search CPAN docs high and low; google for appropriate search terms, check stackoverflow, all to no avail. What I could have done to help myself: Set up a database to simulate this. But I am at an early stage of development of a new DB and don't have no data yet. Sorry. TIA, Ekki ___ 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@lists.scsys.co.uk -- Will Trillich :: 812.454.6431 “Grading takes away all the fun from failing. And a huge part of education is about failure.” -- Shimon Schocken ___ 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@lists.scsys.co.uk
Re: [Dbix-class] why is this returning an hash?
If you have a lot of result rows that you're expecting, assigning the whole set to an array might cause memory troubles. I'd recommend the _rs approach for processing one at a time: my $rs = $schema -resultset('Mytable') -*search_rs*( # note _rs suffix, instead of -all { item_id = $id }, ); while ( my $item = $rs-next ) { # do useful things with $item and $item-item_status } On Wed, May 15, 2013 at 10:59 PM, Rajeev Prasad rp.ne...@yahoo.com wrote: from here i understood, that if i collect output in array element, i will get an array. http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/ResultSet.pm#search in below, $id is unique in the table, so it returns just one row. my @item_array = $schema-resultset('Mytable')-search( { item_id = $id }, { select = [qw/item_status/] } ); print print array =@item_array\n; ./test.pl node status=Db::Schema::Result::Mytable=HASH(0x17b9cf8) $ I actually/finally want to get the value of an specific column by supplying $id. not sure how to get that. ___ 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@lists.scsys.co.uk -- Will Trillich :: 812.454.6431 “Grading takes away all the fun from failing. And a huge part of education is about failure.” -- Shimon Schocken ___ 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@lists.scsys.co.uk
Re: [Dbix-class] Fine-tuning of prefetched relationships
Shea -- There may be a legacy code situation or some political barriers, but Peter's point is that you can modify both individual Result:: classes and ResultSet:: classes to make your scripts much more powerful and flexible. They're designed to work this way, which is why each Result class contains two lines such as this: # Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-09-17 11:26:16 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:npZZ70E+uwdbrUkjvsG7bA You can add all kinds of handy conveniences BELOW that text including __PACKAGE__-belongs_to(...) __PACKAGE__-has_many(...) has something = ( ... ) not to mention your own additional methods from scratch: sub status { my $team = shift; while ( $team ) { return INACTIVE unless $team-active; $team = $team-parent; } return ACTIVE; } The Result classes can be pre-made from your database schema. The ResultSet classes you get to conjure up entirely on your own, no limits! On Mon, Apr 1, 2013 at 8:37 AM, Peter Rabbitson rabbit+d...@rabbit.uswrote: On Mon, Apr 01, 2013 at 09:07:51AM -0400, Shea Levy wrote: On 04/01/2013 08:58 AM, Peter Rabbitson wrote: On Mon, Apr 01, 2013 at 08:54:55AM -0400, Shea Levy wrote: Hi Peter, On 04/01/2013 08:46 AM, Peter Rabbitson wrote: On Mon, Apr 01, 2013 at 08:43:43AM -0400, Shea Levy wrote: Hi all, In my db, a Project has many Jobs. I have a query on Projects where I want to: 1. Sort the jobs of each project by a particular column on the Jobs table 2. Only include jobs that satisfy some criterion, without excluding projects where no such jobs exist (i.e. add a condition to JOIN ON, not WHERE) Are either of these possible with a single search on Projects? Currently we're breaking it up into two queries. Both are possible using usual syntax (and a custom-condition relationship) in a single query using the 0.08242 or greater (not yet released) version. So something like (using Catalyst in my project): $c-model('DB::Projects')-search({ jobs.hidden = 0} {order_by = jobs.name }) Almost - jobs.hidden will produce a WHERE condition (what you do not want). Instead you want to declare a *new* relationship like this: https://github.com/dbsrgits/dbix-class/blob/master/t/lib/DBICTest/Schema/Artist.pm#L53 Ah, I see. So I guess there's no way to do this without modifying the schema? Not currently, however - what is so scary/undesirable about modifying the schema ? That is a real question - you are not the first to word things thusly. I need to figure out where the fear to add an extra definition is coming from. Cheers ___ 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@lists.scsys.co.uk -- Will Trillich :: 812.454.6431 “Grading takes away all the fun from failing. And a huge part of education is about failure.” -- Shimon Schocken ___ 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@lists.scsys.co.uk
Re: [Dbix-class] Caching a resultset?
One problem I see with the exact code posted here is a typo referring to singular-vs-plural on the hash key: On Sun, Jan 13, 2013 at 10:35 PM, Jesse Sheidlower jes...@panix.com wrote: unless ( $c-stash-{subjects} = $cache-get( 'subjects' ) ) { $c-stash-{subjects} = $c-model('WordsDB::Subject')-search(); $cache-set( 'subject', $c-stash-{subjects} ); } Note 'subject' vs 'subjects': $cache-set( 'subject', $c-stash-{subjects} ); -- Will Trillich :: 812.454.6431 “Grading takes away all the fun from failing. And a huge part of education is about failure.” -- Shimon Schocken ___ 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@lists.scsys.co.uk
Re: [Dbix-class] Correct (and secure) searching using -like?
Octavian -- Inlining the values, as you say, would be fraught with peril -- DBI (and DBIx::Class) know better, so it's not a problem. It's not special to the -like operator, it's part of how DBIC works. To see it in action -- when you're single-step debugging your cody, try this: DB1 x $rs-as_query You'll see that it establishes the ? placeholders in the query, and binds the values (ala $sth-execute( @_ )) at runtime. Here's an example of what a query might look like: DB1 x $rs-as_query 0 REF(0xcd53148) - ARRAY(0xcd53258) 0 '(SELECT me.id, me.name, me.team, me.active FROM team me WHERE ( me.id IN ( ?, ?, ? ) ) ORDER BY name)' 1 ARRAY(0xcd52e88) 0 'me.id' 1 138 2 ARRAY(0xcd040d8) 0 'me.id' 1 387 3 ARRAY(0xcc28bc8) 0 'me.id' 1 412 So if someone put nefarious strings in one of the ID values, it'd still be quoted. On Mon, Oct 8, 2012 at 2:49 AM, Octavian Rasnita orasn...@gmail.com wrote: Hi, I've seen examples of searching in a database using the LIKE operator like: $rs = $rs-search( { name = { -like = %$name% }, } ); It doesn't look to be very secure to quote the variable $name this way. Or maybe the special chars in the whole composed string %$name% are then escaped if -like key is used? Or is there a better alternative? Thanks. --Octavian ___ 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@lists.scsys.co.uk -- Will Trillich :: 812.454.6431 “Waiting for perfect is never as smart as making progress.” -- Seth Godin ___ 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@lists.scsys.co.uk
Re: [Dbix-class] Excellent experience with dbix
On Wed, Oct 26, 2011 at 2:53 PM, Roger Day c.roger@gmail.com wrote: Aside from a few little difficulties - as much to do with Oracle as with anything - I have had an enormously positive experience with DBIx::class. It has allowed me to produce clean code in a short time without delving into SQL. I'd like to thank the maintainers and writers of this software for a job well done. +1 -- The very nucleus of Character: to do what you know you should do, when you don't want to do it. Stephen Covey ___ 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@lists.scsys.co.uk
Re: [Dbix-class] Re: using as normal perl module
Dave posted a good link with a straightforward example for DBIx::Class, have you checked this out? http://search.cpan.org/~abraxxa/DBIx-Class-0.08195/lib/DBIx/Class/Manual/Example.http://search.cpan.org/~abraxxa/DBIx-Class-0.08195/lib/DBIx/Class/Manual/Example.pod podhttp://search.cpan.org/~abraxxa/DBIx-Class-0.08195/lib/DBIx/Class/Manual/Example.pod It's really pretty sweet. One of the nice things about the Catalyst setup is that you don't have to do the schema part by hand, as the example shows: http://search.cpan.org/~abraxxa/DBIx-Class-0.08195/lib/DBIx/Class/Manual/Example.pod#Set_up_DBIx::Class::Schema Instead, Catalyst gives your app its own XXX_create.pl script to handle that for you, once you have your tables and fields set up. On Fri, Jul 29, 2011 at 10:07 PM, Rajeev Prasad rp.ne...@yahoo.com wrote: Hello Adam, thank you. I am totally new to DB access using perl. I have looked at perl DBI and DBIx::Class. I can get up to speed on DBI comparatively easily i guess. (But), i want to start and stick to DBIx::Class, as i want to eventually use Catalyst. Catalyst prefers DBIx::Class, so wanted to start from it. when i saw CPAN for both I understood DBI methods easily and clearly compared to DBIx. use DBI;$dbh = DBI-connect($dsn, $user, $password, { RaiseError = 1, AutoCommit = 0 }); where as in comparison i do not see (even in your example below) anything similar in DBIx case. (like) use DBIx::Class; ... etc. hence the confusion. I am so new with using perl with DBI, I have no code yet written (sorry). Hence I was looking for something simple. which fetches data from tables, uses it and then stores some data into tables. as cgi script. thank you. Rajeev -- *From:* Adam Sjøgren a...@koldfront.dk *To:* dbix-class@lists.scsys.co.uk *Sent:* Friday, July 29, 2011 3:41 PM *Subject:* [Dbix-class] Re: using as normal perl module On Thu, 28 Jul 2011 14:52:35 -0700 (PDT), Rajeev wrote: all the examples i see are of using the module in a webapp (built with catalyst). I am only trying to use it in my cgi perl programe, but finding very less documentation. can someone please refer a URL or small script which stores and retrieves data from a table using this module plz. I recently used DBIx::Class in a very simple command-line script that reads files from the filesystem and stuffs them into the database. I looked roughly like this: #!/usr/bin/perl use strict; use warnings; use utf8; use File::Slurp qw(slurp); use MessageID::DB; my $schema=MessageID::DB-connect('dbi:Pg:dbname=message-id', 'USER', 'PASSWD', { AutoCommit=1, pg_enable_utf8=1 }); my $transaction=sub { while(my $filename=) { chomp $filename; my $article=slurp($filename); my $message_id=extract_message_id($article, $filename); $schema-resultset('Article')-create({ message_id=$message_id, article=$article }); } }; $schema-txn_do($transaction); It is trivial, but you asked for something that doesn't use Catalyst and is small (I left out the helper-sub and the error-checking) :-) Maybe if you show what you have tried and describe what you wanted, it is easier to get help. Best regards, Adam -- Good car to drive after a war Adam Sjøgren a...@koldfront.dk ___ 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@lists.scsys.co.uk ___ 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@lists.scsys.co.uk -- Don't just accept the benefits of civilization -- add to it. Extend it. Preserve it. -- Jeff Greason ___ 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@lists.scsys.co.uk
Re: [Dbix-class] Re: set_on_update=0
That's a handy feature. Thanks for the pointer! On Thu, Jul 21, 2011 at 12:52 AM, oli...@seeliger.name wrote: Jane! How do I stop this crazy thing?! Pointers welcome. Have a look at DBIx-Class-DynamicDefault [1]. I remember having had a similar problem, but I can't find the source where I solved this problem. [1] http://search.cpan.org/~flora/DBIx-Class-DynamicDefault-0.03/lib/DBIx/Class/DynamicDefault.pm#dynamic_default_on_update ___ 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@lists.scsys.co.uk -- Don't just accept the benefits of civilization -- add to it. Extend it. Preserve it. -- Jeff Greason ___ 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@lists.scsys.co.uk
[Dbix-class] Re: set_on_update=0
This is quite puzzling! $item-as_of( 2001-12-31 23:59:59 ); $params-{as_of} = 2005-05-05 05:05:05; $form-process( item = $item, params = $params ); # here, $item-as_of is CURRENT_TIMESTAMP regardless! We're wanting to keep the timestamp as-is, not set-to-current-timestamp-upon-every-update. Using HTML::FormHandler (v0.32005) to process the $form, it doesn't seem to matter what we stuff into the $params-{as_of} field, or what we inject into the $item-as_of() field itself, it gets set to current timestamp no matter what. All suggestions and clue-sticks welcome. In MyApp::Schema::DB::Result::MyTable we override the db field completely: __PACKAGE__-add_columns('as_of', { # %{__PACKAGE__-column_info('as_of')}, data_type = 'timestamp', datetime_undef_if_invalid = 1, # default_value = \current_timestamp, is_nullable = 0, # set_on_create = 1, # *set_on_update = 0*, # ignored wholesale from what we can tell } ); So there's no set_on_create or set_on_update at all: DB10 x $item-column_info('as_of') 0 HASH(0xd7d2538) '_ic_dt_method' = 'timestamp' '_inflate_info' = HASH(0xd7d8fd0) 'deflate' = CODE(0xd7d90d0) - DBIx::Class::InflateColumn::DateTime::__ANON__[/usr/local/share/perl/5.10.0/DBIx/Class/InflateColumn/DateTime.pm:190] in /usr/local/share/perl/5.10.0/DBIx/Class/InflateColumn/DateTime.pm:185-190 'inflate' = CODE(0xd7d1e68) - DBIx::Class::InflateColumn::DateTime::__ANON__[/usr/local/share/perl/5.10.0/DBIx/Class/InflateColumn/DateTime.pm:184] in /usr/local/share/perl/5.10.0/DBIx/Class/InflateColumn/DateTime.pm:169-184 'data_type' = 'timestamp' 'datetime_undef_if_invalid' = 1 'is_nullable' = 0 'name' = 'as_of' Jane! How do I stop this crazy thing?! Pointers welcome. On Tue, Jul 19, 2011 at 3:53 PM, will trillich will.trill...@serensoft.comwrote: Been using DBIx::Class (v0.08127) for a while now with Catalyst (v5.80032) and Moose (v1.24), what a great suite of powerful libraries! Question on how to turn OFF or DISABLE *set_on_update* tho: __PACKAGE__-add_columns('as_of', { %{__PACKAGE__-column_info('as_of')}, set_on_create = 1, # set_on_update = 0, } ); The set_on_create is working as expected. The set_on_update seems to work whether we specify 1 or 0 or leave the declaration out altogether. Is there another setting somewhere that interferes? -- Don't just accept the benefits of civilization -- add to it. Extend it. Preserve it. -- Jeff Greason -- Don't just accept the benefits of civilization -- add to it. Extend it. Preserve it. -- Jeff Greason ___ 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@lists.scsys.co.uk
[Dbix-class] set_on_update=0
Been using DBIx::Class (v0.08127) for a while now with Catalyst (v5.80032) and Moose (v1.24), what a great suite of powerful libraries! Question on how to turn OFF or DISABLE *set_on_update* tho: __PACKAGE__-add_columns('as_of', { %{__PACKAGE__-column_info('as_of')}, set_on_create = 1, # set_on_update = 0, } ); The set_on_create is working as expected. The set_on_update seems to work whether we specify 1 or 0 or leave the declaration out altogether. Is there another setting somewhere that interferes? -- Don't just accept the benefits of civilization -- add to it. Extend it. Preserve it. -- Jeff Greason ___ 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@lists.scsys.co.uk