Re: [Dbix-class] Logging all SQL calls
On Wed, Mar 27, 2019 at 09:54:59AM -0400, Jesse Sheidlower wrote: > I've seen DBIx::Class::AuditLog, which requires that relevant statements be > wrapped in a transaction, and DBIx::Class::QueryLog, which seems to be > intended for debugging purposes only. I need something that just takes > everything and logs it to a text file, without having to rewrite the entire > codebase. How do I accomplish this? DBIx::Class::QueryLog is easy to sub-class, so you could write one that you load, and then it just writes to a file instead of remembering stuff. I believe you'd just need to over-ride query_end (to make it write the file and prevent it from remembering stuff) and quary_class() which is just an implementation detail. -- David Cantrell | Hero of the Information Age Irregular English: you have anecdotes; they have data; I have proof ___ 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] Joins using sub-selects
On Tue, Oct 09, 2018 at 08:48:33AM +0200, QE :: Felix Ostmann wrote: > i did not see a problem with you current approach. It is simple you dislike > literal sql? It's partly an aesthetic objection, but also I didn't like having to repeat the filters on type and id. But if there's no better way I'll just have to accept, comment the hell out of it, and write some extensive torture-tests to make sure no-one breaks anything when they refactor the "obviously unnecessary" repetition in the future. -- David Cantrell | London Perl Mongers Deputy Chief Heretic ___ 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] Joins using sub-selects
Hello gang! I'm having trouble figuring out how to express one of my joins in DBIx::Class. The two tables involved and some relevant sample data are: > select * from serviceplan_price; +++---+---+-+ | id | serviceplan_id | type | value | effective_date_time | +++---+---+-+ | 78 | 63 | new | 0.14 | 1973-01-01 00:00:00 | | 79 | 64 | new | 0.73 | 1982-01-01 00:00:00 | | 80 | 64 | new | 3.18 | 2012-01-01 00:00:00 | | 81 | 63 | new | 2.99 | 2019-01-01 00:00:00 | | 82 | 63 | renew | ... Note that the effective date can be in the future. This is how we represent historical prices, and planned price rises. And that there are two types, 'new' (the price you pay when you first buy something) and 'renew' (the price for subsequent renewals). The 'new' price might include the cost of setting up hardware, for example, which isn't needed on renewal. > select * from serviceplan; +++ | id | name | irrelevant details ... | +++ | 63 | foo | blahblah| | 64 | bar | blahblah| +++ And I want to define a relationship so that, along with a serviceplan, I can fetch its *current* new price or renewal price. For an added wrinkle we want to be able to mock the current date/time in our tests, so we can't just use NOW(), but I don't think that's the problem. In plain old SQL it would look like this for fetching them with their current new price: SELECT me.id, me.name, ... current_new_price.id, ... FROM serviceplan me JOIN serviceplan_price current_new_price ON ( current_new_price.serviceplan_id = me.id AND current_new_price.type = 'new' AND current_new_price.effective_date_time = ( SELECT MAX(effective_date_time) FROM serviceplan_price WHERE effective_date_time <= '$mocked' AND type ='new' AND serviceplan_id = me.id ) ) In terms of a DBIx::Class relationship on my serviceplan result class I've got this (repeated for the current_renew_price): __PACKAGE__->belongs_to( current_new_price => 'MyApp::Result::ServiceplanPrice', sub ($args) { my $foreign= $args->{foreign_alias}; my $me = $args->{self_alias}; my $mocked_now = MyApp::Mocks->now(), return { "$foreign.serviceplan_id" => { -ident => "$me.id" }, "$foreign.type"=> 'new', "$foreign.effective_date_time" => { -ident => qq{ ( SELECT MAX(effective_date_time) FROM serviceplan_price WHERE effective_date_time <= '$mocked_now' AND type = 'new' AND serviceplan_id = $me.id ) } } } } ); I *think* that I have no choice but to write the relationship condition as an anonymous sub, but embedding some raw SQL like that is just plain hideous. Also I'd like to get rid of the repetition where I've said twice that the 'type' field should be 'new' and that the serviceplan_id should match, and the inconsistency where I refer to the foreign table as $foreign is some places but by its true name inside the sub-select. Any clues on how to turn that into something a bit more SQL::Abstract? -- David Cantrell David Cantrell System Architect The Hut Group<http://www.thehutgroup.com/> Tel: Email: david.cantr...@uk2group.com<mailto:david.cantr...@uk2group.com> For the purposes of this email, the "company" means The Hut Group Limited, a company registered in England and Wales (company number 6539496) whose registered office is at Fifth Floor, Voyager House, Chicago Avenue, Manchester Airport, M90 3DQ and/or any of its respective subsidiaries. Confidentiality Notice This e-mail is confidential and intended for the use of the named recipient only. If you are not the intended recipient please notify us by telephone immediately on +44(0)1606 811888 or return it to us by e-mail. Please then delete it from your system and note that any use, dissemination, forwarding, printing or copying is strictly prohibited. Any views or opinions are solely those of the author and do not necessarily represent those of the company. Encryptions and Viruses Please note that this e-mail and any attachments have not been encrypted. They may therefore be liable to be compromised. Please also note that it is your responsibility to scan this e-mail and any attachments for viruses. We do not, to the extent permitted by law, accept any liability (whether in contract, negligence or other
Re: [Dbix-class] Static / reference data
On 2018-08-22 20:22, Andy Armstrong wrote: I should perhaps have mentioned that services may also do a self join to find a parent service - services are either one or two levels deep. I can make prefetch work for a single level service and I can make it work for two level services but not, as far as I can see, for both. If I do prefetch => ['service', { service => 'parent' }] I only get results for the cases where the service hierarchy is two levels deep. Sounds like you want a LEFT JOIN for the 'parent' relationship. IIRC for `has_many` and `might_have` relationships that is the default, for others you need to explicitly set the join type. See https://metacpan.org/pod/DBIx::Class::Relationship for gory details. -- David Cantrell David Cantrell System Architect The Hut Group<http://www.thehutgroup.com/> Tel: Email: david.cantr...@uk2group.com<mailto:david.cantr...@uk2group.com> For the purposes of this email, the "company" means The Hut Group Limited, a company registered in England and Wales (company number 6539496) whose registered office is at Fifth Floor, Voyager House, Chicago Avenue, Manchester Airport, M90 3DQ and/or any of its respective subsidiaries. Confidentiality Notice This e-mail is confidential and intended for the use of the named recipient only. If you are not the intended recipient please notify us by telephone immediately on +44(0)1606 811888 or return it to us by e-mail. Please then delete it from your system and note that any use, dissemination, forwarding, printing or copying is strictly prohibited. Any views or opinions are solely those of the author and do not necessarily represent those of the company. Encryptions and Viruses Please note that this e-mail and any attachments have not been encrypted. They may therefore be liable to be compromised. Please also note that it is your responsibility to scan this e-mail and any attachments for viruses. We do not, to the extent permitted by law, accept any liability (whether in contract, negligence or otherwise) for any virus infection and/or external compromise of security and/or confidentiality in relation to transmissions sent by e-mail. Monitoring Activity and use of the company's systems is monitored to secure its effective use and operation and for other lawful business purposes. Communications using these systems will also be monitored and may be recorded to secure effective use and operation and for other lawful business purposes. hgvyjuv ___ 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] Are might_have relationships overly fussy?
On Tue, Jul 24, 2018 at 12:29:29PM +0200, Marco Vittorini Orgeas wrote: > Have you specified a custom join condition on that relationship which is > not showed on the posted code? This is straight from the docs: No. -- David Cantrell | semi-evolved ape-thing Disappointment: n: No results found for "priapic dwarf custard wrestling". ___ 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] Are might_have relationships overly fussy?
Hello classy people! I have a result class that looks like this ... package Database::Chimera::Result::Serviceplan; use parent 'DBIx::Class::Core'; __PACKAGE__->table('serviceplan'); __PACKAGE__->add_columns( id => { data_type => 'INT', is_nullable => 0 }, ... renew_serviceplan_id => { data_type => 'INT', is_nullable => 1 }, ... ); __PACKAGE__->set_primary_key('id'); for this table ... CREATE TABLE `serviceplan` ( `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, ... `renew_serviceplan_id` mediumint(8) unsigned DEFAULT NULL, ... PRIMARY KEY (`id`) ); In brief, a serviceplan is a description of something (a service) that we sell. They all have a duration, and when a service reaches the end of its life it can be renewed. Some renew with the same serviceplan, but some have to renew with different serviceplans. We encode this in the renew_serviceplan_id. In the case where something should renew with the same serviceplan, renew_serviceplan_id is null. I also have ... __PACKAGE__->might_have( "renew_serviceplan" => "Database::Chimera::Result::Serviceplan", { 'foreign.id' => 'self.renew_serviceplan_id' }, ); That warns like this, although as far as I can tell it returns exactly the results I need when I prefetch that relationship ... DBIx::Class::Relationship::HasOne::_validate_has_one_condition(): "might_have/has_one" must not be on columns with is_nullable set to true (Database::Chimera::Result::Serviceplan/renew_serviceplan_id). This might indicate an incorrect use of those relationship helpers instead of belongs_to. at /home/dc/Chimera/dancer/../lib/Database /Chimera/Result/Serviceplan.pm line 78 I'm a bit surprised that it says that it *must not* be like that but then works anyway. I'd expect a "must not" to be fatal. Anyway ... if I change the relationship to a 'belongs_to' with 'join_type' => 'left' it shuts up, and as far as I can tell I get exactly the same data back. ie, belongs_to with a left join appears to be *exactly the same* as a might_have, just with more typing. I wonder therefore whether 'might_have' is being too fussy here and that warning should be got rid of. -- David Cantrell David Cantrell System Architect The Hut Group<http://www.thehutgroup.com/> Tel: Email: david.cantr...@uk2group.com<mailto:david.cantr...@uk2group.com> For the purposes of this email, the "company" means The Hut Group Limited, a company registered in England and Wales (company number 6539496) whose registered office is at Fifth Floor, Voyager House, Chicago Avenue, Manchester Airport, M90 3DQ and/or any of its respective subsidiaries. Confidentiality Notice This e-mail is confidential and intended for the use of the named recipient only. If you are not the intended recipient please notify us by telephone immediately on +44(0)1606 811888 or return it to us by e-mail. Please then delete it from your system and note that any use, dissemination, forwarding, printing or copying is strictly prohibited. Any views or opinions are solely those of the author and do not necessarily represent those of the company. Encryptions and Viruses Please note that this e-mail and any attachments have not been encrypted. They may therefore be liable to be compromised. Please also note that it is your responsibility to scan this e-mail and any attachments for viruses. We do not, to the extent permitted by law, accept any liability (whether in contract, negligence or otherwise) for any virus infection and/or external compromise of security and/or confidentiality in relation to transmissions sent by e-mail. Monitoring Activity and use of the company's systems is monitored to secure its effective use and operation and for other lawful business purposes. Communications using these systems will also be monitored and may be recorded to secure effective use and operation and for other lawful business purposes. hgvyjuv ___ 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] Calling enterprise/corporate users
On Wed, Jan 25, 2017 at 01:10:06AM +, Matt S Trout wrote: > For the past several years, Peter Rabbitson justified certain decisions he > made > by referring to enterprise/corporate users who'd talk to him privately about > DBIx::Class and their desires for the future. > > Sadly, given the current situation, he preserved your > privacy/off-the-record-ness by refusing to tell any of the other developers > who you were or what you'd said. > ... Putting my work hat on ... I don't recall us talking privately with anyone about requirements, but I think I did exchange emails with Peter in which I said that we'd be happy to test stuff people are working on against our code base. That offer still stands. Not that we're doing anything terribly complicated. -- David Cantrell ___ 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] ??? VOTE NOW: DBIC Governance and Namespace Control ???
On Mon, Dec 05, 2016 at 01:15:04AM -0500, David Golden wrote: > Therefore, I submit to the list the following two proposals: > > * PROPOSAL A: Primary permissions for DBIx::Class and related namespaces > shall be managed under the amended DBIC community governance structure > proposed by Matt Trout ... > > * PROPOSAL B: Primary permissions for DBIx::Class and related namespaces > shall be managed solely by Peter Ribasushi ... I vote for PROPOSAL A. -- David Cantrell | Nth greatest programmer in the world All children should be aptitude-tested at an early age and, if their main or only aptitude is for marketing, drowned. ___ 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] 4/5 Why Matt's proposal is a farce
On Tue, Oct 11, 2016 at 07:27:03PM +0200, Peter Rabbitson wrote: > Words are cheap. Let's look at the record instead: In the past several > years mst has been directly responsible ( single-handedly or in part ) > for the following: > > - Shoving FATAL-ized warnings down CPAN's users throats. After years of > incessant pushback finally semi-relented[1], but still continues to > insert it into his CPAN projects to this day. This is not necessarily a bad thing. In fact I've done it myself. First I deprecated a feature in the documentation. Then a while later I made it emit a warning. Then another while later I got rid of it which, if people were still using the deprecated feature, made their code die. Getting rid of the deprecated features made the code simpler and easier to understand, and so less likely to be a bug-laden piece of crap. And this is software whose users *must* keep it up to date for it to be useful. Unlike with DBIx::Class, whose users can quite happily keep using an old version if they don't want new features, users of Number::Phone will get wrong results if they don't keep up to date. And those wrong results will cost them money, because they're using it to do things like bill their customers and route phone calls. -- David Cantrell | Nth greatest programmer in the world You can't spell "slaughter" without "laughter" ___ 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] don't want to hit the db again
On Tue, Apr 28, 2015 at 03:37:42PM -0700, Kevin Karabian wrote: Yes, but the problem is for a has_many, prefetch causes multiple rows to be returned. For example if a result object has 10 related objects then 10 rows are returned for that one object. If the result object is large, then that is a lot of repetition. We've come across a similar problem at work too. We had a situation where there were a few very large rows which each had very many small related rows. We were carefully using prefetch to make just 1 query: -- meadows are big but few, cows are small but many SELECT meadows.*, cows.* FROM meadows, cows WHERE cows.meadow_id = meadows.id; but that ended up returning so much data (almost all of it repeated) that reading it from the database, transferring it across the network, and then unpacking it into perl structures took far too long. In the end we made the code faster by not pre-fetching and letting DBIx::Class follow the relationship (and issue a query) whenever we wanted related rows: SELECT * FROM meadows; foreach (@meadows) { SELECT * FROM cows WHERE meadow_id = $_-id; } That makes $#meadows + 2 queries instead of 1, but returns so much less data that it's quicker anyway. We could make the code faster and have fewer queries (although not just one) if we could do something like this: # few rows, but each row is really really big SELECT * FROM meadows # each row is small but there are a lot of them @cows= SELECT * FROM cows WHERE meadow_id in (map { $_-id } @meadows) iterate over @cows attaching them to appropriate meadow records That returns exactly the same amount of data as the second version, but in two queries. It's O(1) instead of O(N). There will be circumstances where this is faster. -- David Cantrell | Hero of the Information Age I'm in retox ___ 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] Inserting binary data without corrupting
On Fri, Feb 27, 2015 at 12:43:11PM +, Sam Kington wrote: On 27 Feb 2015, at 07:54, Peter Rabbitson rabbit+d...@rabbit.us wrote: On 02/26/2015 11:38 PM, Sam Kington wrote: Is this the best way of handling this, or is there a simpler or purer way I've overlooked? Interesting. This is one way of handling it, yes (btw `unpack 'H*', $binary data` would be much faster). If this definitely fixes things on a combination of a DBD and RDBMS version (you never said what you are using) - I can look into making this implicitly handled by the driver itself. MySQL 5.1.73-1, DBIx::Class 0.082810, DBI 1.622, DBD::mysql 4.022. Same happens in MySQL 5.5 with DBD::mysql $latest as well. -- David Cantrell | London Perl Mongers Deputy Chief Heretic You don't need to spam good porn ___ 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] Monkey-patching around a MySQL/UTF8 bug
On Thu, Feb 26, 2015 at 11:53:49PM +0900, Hailin Hu wrote: Give a try to connect with the option mysql_enable_utf8 = 1 We're already doing that. -- David Cantrell | Reality Engineer, Ministry of Information Disappointment: n: No results found for priapic dwarf custard wrestling. ___ 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] Monkey-patching around a MySQL/UTF8 bug
This bug in DBD::mysql is apparently not going to be fixed: https://rt.cpan.org/Ticket/Display.html?id=60987 and it's preventing us from inserting, eg, an i-acute character into our database. Our customer Mr. GarcÃa is Quite Irritated at this. It appears that any non-ASCII character with code-point below 0x100 is affected (higher codepoints like ij and Ï and â are OK). As a work-around I've done this in my application: BEGIN { my $old_ex = \DBIx::Class::Storage::DBI::_dbh_execute; my $new_ex = sub { foreach (@{$_[3]}) { if(exists($_-[1]) defined($_-[1])) { utf8::upgrade($_-[1]) } } return $old_ex-(@_); }; { no strict qw/ refs /; no warnings 'redefine'; *DBIx::Class::Storage::DBI::_dbh_execute = $new_ex; } } And it appears to work. However, I don't like monkey-patching like that. Is there a better way that I haven't been able to find in the DBIx::Class doco? -- David Cantrell | Hero of the Information Age Sobol's Law of Telecom Utilities: Telcos are malicious; cablecos are simply clueless. ___ 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] Fastest method to check for key existence?
On Thu, Feb 12, 2015 at 12:25:55PM +, Lianna Eeftinck wrote: Or just use -count, which doesn't need to retrieve and instantiate the objects. Something like this: SELECT COUNT(*) FROM foo WHERE bar IN ('ant', 'bat', cat', 'dog'); might tell you that two of them exist, but I got the impression that the important information which *which* two exist. -- David Cantrell | Minister for Arbitrary Justice Eye have a spelling chequer / It came with my pea sea It planely marques four my revue / Miss Steaks eye kin knot sea. Eye strike a quay and type a word / And weight for it to say Weather eye am wrong oar write / It shows me strait a weigh. ___ 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] Dynamic/Flexible DBIC views
On Fri, Nov 21, 2014 at 08:38:33AM -0500, Christian Lackas wrote: I have something like this in the view: __PACKAGE__-result_source_instance-view_definition(q[ select ... from projects me inner join ( select ... ) join_name where me.customer_id = ? and ... ]); and then can get the desired information with my $res = $view-search( {}, { bind = [ 42 ] } ); [but bind values are icky] When I had a similar problem a couple of years ago I was told that what you're doing here is the best solution. If anyone has come up with something better since, I'd love to know too. -- David Cantrell | top google result for topless karaoke murders Compromise: n: lowering my standards so you can meet them ___ 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] [ANNOUNCE] A less buggy DBIx::Class final (hopefully) trial - v0.082700_10
On Mon, Sep 15, 2014 at 05:09:45PM +0200, Peter Rabbitson wrote: ... R/RI/RIBASUSHI/DBIx-Class-0.082700_10.tar.gz If you do have the means and resources to run this against your in-house test suite - please do so. If no showstoppers are reported, this tarball will become 0.082800 on Tue the 23rd of September. Done, for ..._11, and passed. -- David Cantrell | Reality Engineer, Ministry of Information I'm in retox ___ 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] Please test the trial release of DBIx::Class 0.082800-to-be
On Thu, Jul 31, 2014 at 11:25:32AM +, Peter Rabbitson wrote: After a moderately quiet period the release machinery is firing up again. Please consider testing the next DBIC trial release 0.082700_04, against your *PRODUCTION TEST SUITE*. I finally got round to this. All our tests at work pass on 0.082700_05, except ... This is another maintenance release, and the usual rules of no breakages allowed is in effect. I had to patch our code thus: __PACKAGE__-belongs_to( service = Database::Chimera::Result::Service, -{ -'foreign.id' = 'self.service_id', -join_type= 'left' -} +{ 'foreign.id' = 'self.service_id' }, +{ join_type= 'left' } ); because the new DBIx::Class moaned at how it used to be. That seems like a pretty reasonable thing to do, given that that's brought that particular code into line with how all our other result classes are defined. I consider this to be a bug in our code, not in DBIx::Class. DBIx::Class did the right thing in complaining loudly and telling me exactly what it was complaining about and where. -- header FROM_DAVID_CANTRELLFrom =~ /david.cantrell/i describe FROM_DAVID_CANTRELLMessage is from David Cantrell scoreFROM_DAVID_CANTRELL15.72 # This figure from experimentation ___ 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] Dumping fixtures and loading in test script
On Mon, Nov 11, 2013 at 02:29:01PM -0500, Rob Kinyon wrote: This makes for poor testability. Otherwise, when you have a schema change, you either: 1. Force everyone sharing the same developer instance to immediately have to deal with your schema changes Having devs share a database will never* work, because different developers may require different incompatible versions of the schema. eg, the developer working on a future version of your product, and the developer backporting a bugfix to an old version that some customers are still paying for support on. Then you've also got problems like how to test that your code does the right thing with an empty table, when other devs are concurrently running tests that require having data in the table. To do anything other than have one database per developer is insane. Of course, this also means that you ought to have scripts that will run your tests against a clone of your database (and, indeed, a clone of your code and config). Why? So that you can run all the tests against one branch while you start work on another. Here we have such a script that takes args like: $ scripts/isolated.pl \ --cleanup \ --cover --cover_report_dir=$HOME/coverage \ prove -vm t It clones the entire environment and then runs whatever the hell you want against the clone. That could be running the test suite, or it could be starting an instance of the app that you can then interact with, or load testing, or ... and also has switches to turn on/off Devel::Cover. Finally, it can clean up the clone on exit or leave it hanging around for debuggery. * sweeping generalisations never work either -- David Cantrell | Nth greatest programmer in the world Never attribute to malice that which can be explained by stupidity -- Hanlon's Razor Stupidity maintained long enough is a form of malice -- Richard Bos's corollary ___ 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] DBIx::Class::Relationship::CascadeActions::delete(): Not in database
On Wed, Mar 27, 2013 at 06:02:27AM +1100, Peter Rabbitson wrote: From https://metacpan.org/module/DBIx::Class::Row#delete :: If you delete an object within a txn_do() (see txn_do in :: DBIx::Class::Storage) and the transaction subsequently fails, the :: result object will remain marked as not being in storage. If you know :: for a fact that the object is still in storage (i.e. by inspecting :: the cause of the transaction's failure), you can use :: $obj-in_storage(1) to restore consistency between the object and the :: database. This would allow a subsequent $obj-delete to work as :: expected. Eeuuww! I would thunk that in_storage should be rolled back too. -- David Cantrell | Cake Smuggler Extraordinaire Computer Science is about lofty design goals and careful algorithmic optimisation. Sysadminning is about cleaning up the resulting mess. ___ 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] how to empty a Table? when there is no primary key
On Wed, Mar 27, 2013 at 06:12:49AM +1100, Peter Rabbitson wrote: On Mon, Mar 25, 2013 at 03:57:45PM +, David Cantrell wrote: I've always thought that this is something that should be handled by the database, not by DBIx::Class - or at least that it should be something that you have to explicitly turn on in DBIx::Class to support data sources which don't really do relationships. When DBIC was first worked on (2005) most available data sources either did not handle FK constraints or (much more often the case, even today) did not have them declared. Not having them declared in the table definitions is, IMO, a bug in the database design and the application. As such the default of cascade_delete [1] is true for has_many's, as it is generally harmless (though wasteful) if FK-Cs are present, but is life-saving when they are not. There is a plan on how to take folks off the needle but it requires a bit more work in the ResultSource area and eeryone capable of doing it has been busy lately. Ah, OK. I'll try to remember not to whinge about this in future then :-) -- David Cantrell | London Perl Mongers Deputy Chief Heretic Aluminum makes a nice hat. All paranoids will tell you that. But what most do not know Is reflections will show On the CIA's evil landsat. ___ 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] DBIx::Class::Relationship::CascadeActions::delete(): Not in database
On Wed, Mar 27, 2013 at 11:49:53PM +1100, Peter Rabbitson wrote: On Wed, Mar 27, 2013 at 12:30:03PM +, David Cantrell wrote: Eeuuww! I would thunk that in_storage should be rolled back too. How would you implement that? (as in how would the perl logic actually look) in the code that flips that bit ... if we're in a transaction store in the transaction (handwave handwave, i've not looked at the code) a tuple of [ref to object we're updating, the old value of in_storage] update it fi and then in the transaction code ... if the transaction gets rolled back go through that list of tuples, resetting in_storage on each object fi If you think that these half-arsed ideas seem plausible, then please point me at the right places that I can shim them in! -- David Cantrell | top google result for topless karaoke murders Nuke a disabled unborn gay baby whale for JESUS! ___ 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] how to empty a Table? when there is no primary key
On Mon, Mar 25, 2013 at 11:58:31AM +1300, Paul Findlay wrote: I tried to use delete_all, but there is no primary key in the table so it failed. what else can i do? There is a discussion in the manual about this: https://metacpan.org/module/DBIx::Class::Manual::Intro#The-Significance-and-Importance-of-Primary-Keys But you could alternatively use $schema-resultset('Mytable')-delete; But this won't execute any on-delete triggers or cascade to MyTable's relationships. I've always thought that this is something that should be handled by the database, not by DBIx::Class - or at least that it should be something that you have to explicitly turn on in DBIx::Class to support data sources which don't really do relationships. -- David Cantrell | Cake Smuggler Extraordinaire comparative and superlative explained: Huhn worse, worser, worsest, worsted, wasted ___ 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] test failures in latest DBIx::Class
On Fri, Nov 16, 2012 at 05:55:39AM +1100, Peter Rabbitson wrote: On Thu, Nov 15, 2012 at 05:55:35PM +, David Cantrell wrote: I'm getting a test failure in the latest DBIx::Class: ... ARGH!!! Fixed: https://metacpan.org/source/RIBASUSHI/Class-Accessor-Grouped-0.10009/Changes I and my Jenkins thank you! -- David Cantrell | semi-evolved ape-thing All praise the Sun God For He is a Fun God Ra Ra Ra! ___ 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] test failures in latest DBIx::Class
I'm getting a test failure in the latest DBIx::Class: # Failed test 'DBIx::Class::perlstring appears to have entered inheritance chain by import into Class::Accessor::Grouped' # at t/55namespaces_cleaned.t line 144. # Looks like you failed 1 test of 14803. t/55namespaces_cleaned.t . Dubious, test returned 1 (wstat 256, 0x100) Failed 1/14803 subtests (less 39 skipped subtests: 14763 okay) As well as a bunch of TODO passes: t/752sqlite.t (Wstat: 0 Tests: 68 Failed: 0) TODO passed: 35 t/multi_create/existing_in_chain.t (Wstat: 0 Tests: 10 Failed: 0) TODO passed: 1-2, 5-6, 10 t/multi_create/reentrance_count.t (Wstat: 0 Tests: 18 Failed: 0) TODO passed: 1-4, 6-10, 12, 15-16, 18 t/prefetch/multiple_hasmany.t (Wstat: 0 Tests: 10 Failed: 0) TODO passed: 2, 6-8 t/prefetch/via_search_related.t(Wstat: 0 Tests: 24 Failed: 0) TODO passed: 21-22 t/row/inflate_result.t (Wstat: 0 Tests: 12 Failed: 0) TODO passed: 3 which, if they're no longer TODO should be turned into actual tests, I guess. If you need more details then please ask - although I hope you won't, because extracting them from this 'ere automagic deployment thingy is a pain in the arse :-) -- David Cantrell | semi-evolved ape-thing We found no search results for crotchet. Did you mean crotch? ___ 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] sqlite vs mysql
On Fri, Jul 27, 2012 at 01:39:34AM -0400, shawn wilson wrote: i was thinking that dbic would just dwim as far as keys go, create the other tables as 0s or 1s as the pk and then create the main (text) table with those the same fk as was used for the pk for those tables...? DBIx::Class doesn't actually pay any attention to fields' attributes, not even their data type. Therefore it *can't* DWYM. -- David Cantrell | top google result for internet beard fetish club Every normal man must be tempted at times to spit on his hands, hoist the black flag, and begin slitting throats. -- H. L. Mencken ___ 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] many_to_many data access
On Thu, Jul 12, 2012 at 09:53:30AM +0100, Frank Schwach wrote: except if you are expecting international customers: in many countries there are no states, so a city really only might_have a state and the city itself belongs_to a country, The (optional) state also belongs_to a country And not all addresses have a city, not all addresses (even within a single country) have the same number of elements, and some places are in multiple countries. Oh what fun! Stupid real world being hard to model. -- David Cantrell | Nth greatest programmer in the world We found no search results for crotchet. Did you mean crotch? ___ 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] Search_rs not returning newly created rows
On Wed, Jun 20, 2012 at 02:49:56PM -0400, Len Jaffe wrote: On Wed, Jun 20, 2012 at 2:39 PM, Bill Moseley mose...@hank.org wrote: I'd worry less about where your database calls are happening. Do you really care if [% user.address.city | html %] hits the database in the template or in the controller? ... One point of the object abstraction is you don't care about the implementation. The real problem I've seen, though, is doing something stupid like huge nested loops in the template where each one generates a query. This is what I meant to about maintenance nightmare. I've inherited apps like this where I had to roll nested queries (in templates) up into a single query to go from 120 round-trips to the database, taking 8 seconds, into one round trip, taking half a second. Making sure you don't hit the database from the templating layer doesn't magically make this problem go away. I recently fixed an application where we were making over a thousand queries *in a single subroutine* where one would do the job. I did it by using prefetch. That one line I added would have the same effect regardless of whether the loop was in the same subroutine or a mile away in a template. -- David Cantrell | top google result for topless karaoke murders The test of the goodness of a thing is its fitness for use. If it fails on this first test, no amount of ornamentation or finish will make it any better, it will only make it more expensive and foolish. -- Frank Pick, lecture to the Design and Industries Assoc, 1916 ___ 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] Adding comments to generated queries
On Wed, May 30, 2012 at 06:03:52AM -0500, Bill Moseley wrote: Of course, with DBIC it's a bit more difficult to define where a query comes from since it can get built in parts and doesn't get executed until it's used. Plus, we already have code that reports on slow queries (or excessive queries) in a given web request. Still, Is there any existing module that would do something like this this? I'm not sure what it would put in outside of a stack trace. You mean like this? http://search.cpan.org/~dcantrell/DBIx-Class-QueryLog-WithStackTrace-1.0/ -- David Cantrell | Nth greatest programmer in the world On the bright side, if sendmail is tied up routing spam and pointless uknot posts, it's not waving its arse around saying root me! -- Peter Corlett, in uknot ___ 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] Updating many-to-many relationships
On Wed, Feb 22, 2012 at 11:18:15AM +0100, Alexander Hartmaier wrote: set_$helper_name replaces all rows in the link table, add_to_$helper_name adds a row to the link table. If you look at the code in DBIx::Class::Relationship::ManyToMany you see that set_ deletes all rows and then calls the add_to_ method for every array element, so the syntax is the same. The pod contains an example for its usage: $actor-add_to_roles($role, { year = 1995 }); The first argument is a role object, the optional second parameter a hashref containing additional column data for the link table. OK, but that's still not really what I'm looking for. When I INSERT with my current code, not only does it populate the intermediate user_role table, but it also populates - if necessary - the role table. It would be perverse if there's nothing similar for UPDATEs. Maybe what I'm looking for doesn't exist shrug. -- David Cantrell | semi-evolved ape-thing Immigration: making Britain great since AD43 ___ 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] Updating many-to-many relationships
I have a bunch of classes set up as part of the ACL system for this 'ere application what I'm writing. There is a 'user' table, a 'role' table, and sitting in between them a 'user_role' table. Users can have any arbitrary combination of roles, so this is yer classic many-to-many situation. Pared down to the minimum, the classes are: package Database::Result::User; use base 'DBIx::Class::Core'; __PACKAGE__-table('user'); __PACKAGE__-add_columns( id = { data_type = 'INT', is_nullable = 0 }, # autoinc status = { data_type = 'CHAR', is_nullable = 0 }, username = { data_type = 'CHAR', is_nullable = 0 } ); __PACKAGE__-set_primary_key( id ); __PACKAGE__-has_many( user_roles, Database::Result::UserRole, { 'foreign.user_id' = self.id } ); 1; package Database::Result::UserRole; use base 'DBIx::Class::Core'; __PACKAGE__-table('user_role'); __PACKAGE__-add_columns( user_id = { data_type = 'INT', is_nullable = 0 }, role_id = { data_type = 'INT', is_nullable = 0 }, ); __PACKAGE__-set_primary_key( qw(user_id role_id) ); __PACKAGE__-belongs_to(user, Database::Result::User, { 'foreign.id' = 'self.user_id' }); __PACKAGE__-belongs_to(role, Database::Result::Role, { 'foreign.id' = 'self.role_id' }); 1; package Database::Result::Role; use base 'DBIx::Class::Core'; __PACKAGE__-table('role'); __PACKAGE__-add_columns( id = { data_type = 'INT', is_nullable = 0 }, # autoinc name = { data_type = 'CHAR', is_nullable = 0 }, ); __PACKAGE__-set_primary_key( id ); __PACKAGE__-has_many( user_roles, Database::Result::UserRole, { 'foreign.role_id' = self.id } ); 1; I can create users with roles easily, creating roles on the fly if necessary: my $person = ...-create({ username = 'anselm', status = 'alive', user_roles = [ { role = { name = 'Monk' } }, { role = { name = 'Archbishop' } }, ] }); I couldn't see this documented anywhere, but found it in the mailing list archives. It creates any necessary entries in the 'role' table, and in the 'user_role' table. However, I can't find any nice way of updating a user's roles, something like this (which I tried, but it doesn't work) ... $person-status('dead'); $person-user_roles([ { role = { name = 'Saint' } } ]); $person-update(); Am I missing something? It would make my life ever so pleasant if there were a nice easy way of doing this. As it is, however, the call to the user_roles() method is not having any effect at all - there's no queries generated whatsoever for it, just the UPDATE to change the status from alive to dead. -- David Cantrell | even more awesome than a panda-fur coat There is no one true indentation style, But if there were KR would be Its Prophets. Peace be upon Their Holy Beards. ___ 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] Updating many-to-many relationships
On Tue, Feb 21, 2012 at 06:24:03PM +0100, Alexander Hartmaier wrote: You can find an example in the many_to_many relationship bridge docs: https://metacpan.org/module/DBIx::Class::Relationship#many_to_many Nothing helpful there I'm afraid, just an Exciting Bug (or maybe just a not so exciting lack of documentation). If I add this: __PACKAGE__-many_to_many(user_roles_many_to_many = 'user_roles', 'role'); Then if I have a user who already has role 'Philosophise' and do this: ...-set_user_roles_many_to_many( [ { role = { name = 'Philosophise' } } ] ); Then it deletes all that user's records from the user_roles table (which is, I presume, the correct behaviour before re-populating it), but then generates this broken SQL: SELECT role.id, role.name FROM role role WHERE ( role.role NAME 'Philosophise' ) Maybe I'm calling it wrong, but it's not at all obvious what I should be doing as I can't see any documentation for the set_$method apart from that it exists - I ASSumed that the data should look the same as when I'm doing an INSERT! -- David Cantrell | Reality Engineer, Ministry of Information Deck of Cards: $1.29. 101 Solitaire Variations book: $6.59. Cheap replacement for the one thing Windows is good at: priceless -- Shane Lazarus ___ 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] DBIx::Class::SingletonRows
On Mon, Jun 30, 2008 at 11:36:33AM -0500, Jonathan Rockway wrote: I like this. Thankyou! People are constantly whining how singleton rows or non-singleton rows are the One True Way, and everything that disagrees with them is WRONG!!11! Now users of DBIC can pick for themselves instead of being told what to think :) Just as long as they *do* think I don't care what they think ;-) * On Wed, Jun 25 2008, David Cantrell wrote: Unlike the earlier versions, this one is a proper component and is only slightly magical. I'm a bit unclear on this part: sub magick_object { ... } Is there a reason why you have to fake inheritance here? I need to control my ref-counting so I don't leak memory, but I found that if I did real inheritance and just provided my own DESTROY it didn't work right. Something inside DBIx::Class (and I didn't get as far as figuring out what, as it was quicker to do an Evil Hack) was getting in the way. Hence me wrapping the real object inside another object, one which DBIx::Class doesn't know about, and so won't mess things up. The *counting* part of ref-counting was working, but deleting the object was spitting out some error that I forget now. It's ... hard to explain, unfortunately. And I might just have missed something really obvious. I did try weakening references and whatnot, but either it wasn't what I needed or I used it wrong. Either way, it didn't do the trick. Perhaps I'm missing something, but I think other people are probably wondering the same thing. (As an aside, whenever you have to have a long comment explaining why you do something, it's probably not the best approach ;) Oh I dunno, first time I saw a Schwartzian Transform I really wished there was a nice long comment with it! But I do see where you're coming from. Another reason that it's probably not the best approach is that it feels just plain dirty. -- David Cantrell | Reality Engineer, Ministry of Information There is no one true indentation style, But if there were KR would be Its Prophets. Peace be upon Their Holy Beards. ___ 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/[EMAIL PROTECTED]
[Dbix-class] DBIx::Class::SingletonRows
I got permission from my boss, and DBIx::Class::SingletonRows is now wending its merry way through the PAUSE and out to CPAN mirrors. Unlike the earlier versions, this one is a proper component and is only slightly magical. -- David Cantrell | Hero of the Information Age On the bright side, if sendmail is tied up routing spam and pointless uknot posts, it's not waving its arse around saying root me! -- Peter Corlett, in uknot ___ 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/[EMAIL PROTECTED]
[Dbix-class] Rows as singletons
I've been mumbling on IRC over the last week or two about rows being singletons when they get loaded into memory. This is mostly because, when writing tests for a DBIx::Class based project I got irritated when I had two references to the same row hanging around in memory, update()d one of them, but the other still had old data in it. Here's my fix: http://www.cantrell.org.uk/david/private/SingletonRows.pm Comments would be most welcome. Please note that it shouldn't be re-distributed yet, or used in any of your projects, as it's not yet got a proper licence on it. -- David Cantrell | top google result for internet beard fetish club Anyone who cannot cope with mathematics is not fully human. At best he is a tolerable subhuman who has learned to wear shoes, bathe and not make messes in the house. -- Robert A Heinlein ___ 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/[EMAIL PROTECTED]