Re: [RDBO] auto_initialize from custom $dbh

2007-02-06 Thread mreece
working up an extra simpler test case, i managed to get it working with an
extra simpler $dbh.

for posterity, this is what i hope and ultimately does work, to bootstrap
some source files for hand-editing.

#!perl
use strict; use warnings;

use DBI;

## Set up $dbh
our $dbh;

BEGIN {
$dbh = DBI->connect('DBI:mysql:database=test','test','test');
}

package My::Junk;
use base 'Rose::DB::Object';

sub init_db {
return Rose::DB->new(
dbh => $dbh, driver => 'mysql',
database => 'test' # yields warnings without this redundancy
);
}

__PACKAGE__->meta->table('junk');
__PACKAGE__->meta->auto_initialize;
print __PACKAGE__->meta->perl_class_definition;


> i am getting the following error when trying to auto_initialize a
> table class from a custom $dbh:
>
>Could not auto-retrieve primary key columns for class My::Junk -
> no primary key info found for catalog '' schema '' table 'junk'
>
>
> the table is very simple:
>
> mysql> create table junk ( junk_id int auto_increment primary key,
> name varchar(32) ) ;
> Query OK, 0 rows affected (0.09 sec)
>
> mysql> show create table junk\G
> *** 1. row ***
> Table: junk
> Create Table: CREATE TABLE `junk` (
>`junk_id` int(11) NOT NULL auto_increment,
>`name` varchar(32) default NULL,
>PRIMARY KEY  (`junk_id`)
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8
> 1 row in set (0.00 sec)
>
> mysql> insert into junk set name = 'one' ;
> Query OK, 1 row affected (0.01 sec)
>
> mysql> insert into junk set name = 'two' ;
> Query OK, 1 row affected (0.00 sec)
>
> mysql> select * from junk ;
> +-+--+
> | junk_id | name |
> +-+--+
> |   1 | one  |
> |   2 | two  |
> +-+--+
> 2 rows in set (0.01 sec)
>
>
>
> here is my test script:
>
> % cat auto.pl
> #!perl
> use strict; use warnings;
>
> ## Set up $dbh
> use Vinq::Globals qw($dbh);
> BEGIN { Vinq::Globals->init(confName => 'plexmreece') }
>
> BEGIN {
>  ## verify $dbh is working
>  my $sth = $dbh->prepare('SELECT COUNT(1) FROM junk');
>  $sth->execute;
>
>  print "got ", $sth->fetchrow_array, " junks from dbh $dbh\n";
> }
>
> package My::Junk;
> use base 'Rose::DB::Object';
> use Vinq::Globals qw($dbh);
>
> sub init_db {
>  print "Setting up Rose::DB with dbh => $dbh\n";
>  return Rose::DB->new(dbh => $dbh, driver => 'mysql');
> }
>
> __PACKAGE__->meta->table('junk');
> __PACKAGE__->meta->auto_initialize;
>
>
> and here is the output:
>
> % perl auto.pl
> got 2 junks from dbh Vinq::DB=HASH(0x8832a74)
> Setting up Rose::DB with dbh => Vinq::DB=HASH(0x8832a74)
> Setting up Rose::DB with dbh => Vinq::DB=HASH(0x8832a74)
> Setting up Rose::DB with dbh => Vinq::DB=HASH(0x8832a74)
> Could not auto-retrieve primary key columns for class My::Junk - no
> primary key info found for catalog '' schema '' table 'junk' at
> auto.pl line 28
>
>
>
> am i missing something?  do i need to tell Rose::DB more about the
> dbh i am injecting?
>
> % perl -MRose::DB -MRose::DB::Object -e 'print "Rose::DB
> $Rose::DB::VERSION\nRose::DB::Object $Rose::DB::Object::VERSION\n"'
> Rose::DB 0.732
> Rose::DB::Object 0.760
>
>
>
> -
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job
> easier.
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> ___
> Rose-db-object mailing list
> Rose-db-object@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rose-db-object
>


-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


[RDBO] Additional where criteria in left outer joins

2007-02-06 Thread Matt Schnitz

There was a conversation back in September about left outer joins with
additional where criteria:
http://sourceforge.net/mailarchive/message.php?msg_id=34475671

I was wondering if any progress had been made on the issue since then, or
whether there are any new features we could use for dealing with this case.

Also,  I (partially) disagree with, or don't understand, the part that "it's
okay to have a variety of conditions, but they each require a new named
relationship".  In a strict relational model, yeah, you're right.  But left
outers, even NULLs, have always been in the gray never-never land between
pure relational algebra and hacked-up real-world database software.

I tend not to think about the additional clauses in the left outers as a new
named relationship.  They're more a kind of data-driven relationship.
Admitted, I know jack about your architecture, but maybe a generics/template
model will satisfy the design?


Schnitz

BTW - John, I love reading your stuff on ArsTechnica. I read it word for
word.  All 21 pages. :)
-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


[RDBO] auto_initialize from custom $dbh

2007-02-06 Thread Michael Reece
i am getting the following error when trying to auto_initialize a  
table class from a custom $dbh:

   Could not auto-retrieve primary key columns for class My::Junk -  
no primary key info found for catalog '' schema '' table 'junk'


the table is very simple:

mysql> create table junk ( junk_id int auto_increment primary key,  
name varchar(32) ) ;
Query OK, 0 rows affected (0.09 sec)

mysql> show create table junk\G
*** 1. row ***
Table: junk
Create Table: CREATE TABLE `junk` (
   `junk_id` int(11) NOT NULL auto_increment,
   `name` varchar(32) default NULL,
   PRIMARY KEY  (`junk_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

mysql> insert into junk set name = 'one' ;
Query OK, 1 row affected (0.01 sec)

mysql> insert into junk set name = 'two' ;
Query OK, 1 row affected (0.00 sec)

mysql> select * from junk ;
+-+--+
| junk_id | name |
+-+--+
|   1 | one  |
|   2 | two  |
+-+--+
2 rows in set (0.01 sec)



here is my test script:

% cat auto.pl
#!perl
use strict; use warnings;

## Set up $dbh
use Vinq::Globals qw($dbh);
BEGIN { Vinq::Globals->init(confName => 'plexmreece') }

BEGIN {
 ## verify $dbh is working
 my $sth = $dbh->prepare('SELECT COUNT(1) FROM junk');
 $sth->execute;

 print "got ", $sth->fetchrow_array, " junks from dbh $dbh\n";
}

package My::Junk;
use base 'Rose::DB::Object';
use Vinq::Globals qw($dbh);

sub init_db {
 print "Setting up Rose::DB with dbh => $dbh\n";
 return Rose::DB->new(dbh => $dbh, driver => 'mysql');
}

__PACKAGE__->meta->table('junk');
__PACKAGE__->meta->auto_initialize;


and here is the output:

% perl auto.pl
got 2 junks from dbh Vinq::DB=HASH(0x8832a74)
Setting up Rose::DB with dbh => Vinq::DB=HASH(0x8832a74)
Setting up Rose::DB with dbh => Vinq::DB=HASH(0x8832a74)
Setting up Rose::DB with dbh => Vinq::DB=HASH(0x8832a74)
Could not auto-retrieve primary key columns for class My::Junk - no  
primary key info found for catalog '' schema '' table 'junk' at  
auto.pl line 28



am i missing something?  do i need to tell Rose::DB more about the  
dbh i am injecting?

% perl -MRose::DB -MRose::DB::Object -e 'print "Rose::DB  
$Rose::DB::VERSION\nRose::DB::Object $Rose::DB::Object::VERSION\n"'
Rose::DB 0.732
Rose::DB::Object 0.760



-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


[RDBO] Additional where criteria in left outer joins

2007-02-06 Thread Matt Schnitz

There was a conversation back in September about left outer joins with
additional where criteria:
http://sourceforge.net/mailarchive/message.php?msg_id=34475671

I was wondering if any progress had been made on the issue since then, or
whether there are any new features we could use for dealing with this case.

Also, I wanted to say I (partially) disagree with, or don't understand, the
part that "it's okay to have a variety of conditions, but they each require
a new named relationship".  In a strict relational model, yeah, you're
right.  But left outers, even NULLs, have always been in the gray
never-never land between pure relational algebra and hacked-up real-world
database software.

I tend not to think about the additional clauses in the left outers as a new
named relationship.  They're more a kind of data-driven relationship.
Admitted, I know jack about your architecture, but maybe a generics/template
model will satisfy the design?


Schnitz

BTW - John, I love reading your stuff on ArsTechnica. I read it word for
word.  All 21 pages. :)
-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


Re: [RDBO] Deleting from a one-to-many

2007-02-06 Thread Derek Watson

I agree that performing a group of actions in a single transaction is one of
the prettiest features of RDBO, and I also like John's approach to making
these shortcuts to Manager routines.  I find myself constantly re-writing my
table relationships for manager calls.


On 2/6/07, Ask Bjørn Hansen <[EMAIL PROTECTED]> wrote:



On Feb 6, 2007, at 11:22 AM, John Siracusa wrote:

> I'm not a big fan of the *_now method types, however, which is why
> they're not the defaults.  OTOH, a delete_on_save method might seem
> strange when doing something like this:

I don't think so.

I was working on converting a small CDBI app (http://
www.pool.ntp.org/ ) to RDBO recently and I quickly started to get
tripped up by the "delete now" things I made.  When you get the hang
of it, it's Very Very Nice that RDBO automatically "does things in a
big transaction" with ->save(cascade => 1) being the "commit".


  - ask

--
http://develooper.com/ - http://askask.com/



-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job
easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


Re: [RDBO] Deleting from a one-to-many

2007-02-06 Thread Ask Bjørn Hansen

On Feb 6, 2007, at 11:22 AM, John Siracusa wrote:

> I'm not a big fan of the *_now method types, however, which is why
> they're not the defaults.  OTOH, a delete_on_save method might seem
> strange when doing something like this:

I don't think so.

I was working on converting a small CDBI app (http:// 
www.pool.ntp.org/ ) to RDBO recently and I quickly started to get  
tripped up by the "delete now" things I made.  When you get the hang  
of it, it's Very Very Nice that RDBO automatically "does things in a  
big transaction" with ->save(cascade => 1) being the "commit".


  - ask

-- 
http://develooper.com/ - http://askask.com/



-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


Re: [RDBO] Deleting from a one-to-many

2007-02-06 Thread Jud
John Siracusa wrote:
> How about a delete_now method type for 1-to-m relationships (same arg
> formats as the "find" method type):

+1 for this. Would be very helpful.


-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


Re: [RDBO] Deleting from a one-to-many

2007-02-06 Thread John Siracusa
On 2/6/07, Derek Watson <[EMAIL PROTECTED]> wrote:
> That was pretty much my position, too -- I was looking for something more
> semantically appropriate. My task was trivial to solve in one or two ways, I
> just didn't see any examples on how to do this stuff elegantly. What I am
> really looking for is something expressive like
>
> $product->find_prices(query => [ region => 'UK' ])->delete_all;

How about a delete_now method type for 1-to-m relationships (same arg
formats as the "find" method type):

$product->delete_prices({ region => 'UK' });

I'm not a big fan of the *_now method types, however, which is why
they're not the defaults.  OTOH, a delete_on_save method might seem
strange when doing something like this:

$product->delete_prices({ region => 'UK' }); # delete_on_save

Then fetch the prices and see the UK price(s) still there:

@prices = $product->prices;

all because you haven't yet said:

$product->save;

To actually execute the delete.

Like "find", this kind of method seems like a shortcut to a Manager
call.  So it should probably execute immediately, and it's probably
entirely outside the scope of the "collection" methods for
get/set/add.

Anyone have any better ideas? :)

-John

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


Re: [RDBO] Deleting from a one-to-many

2007-02-06 Thread Clayton Scott

On 2/6/07, Ted Zlatanov <[EMAIL PROTECTED]> wrote:


On Tue, 6 Feb 2007 13:19:37 -0500 "John Siracusa" <[EMAIL PROTECTED]>
wrote:

JS> my($price) = grep { $_->region eq 'UK' } $p->prices;
JS> $price->delete;
JS> $p->prices(undef);# forget previously fetched collection
JS> @prices = $p->prices; # collection no longer contains deleted
entry

What always annoyed me about this technique is that it looks like
you're losing all the prices.  Setting something to undef generally
has that meaning in Perl.  I would rather write



I have the same interpretation of the code without the accompanying
comments.
I wasn't ready to say anything until I had a better idea of how to do  it,
and I still
don't have a better idea.

$p->forget_prices();


That looks to me like  it should delete the prices as well.
How about $product->unload_prices; or
$product->unload_relationship('prices');


Clayton Scott
--
[EMAIL PROTECTED]
-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


Re: [RDBO] Deleting from a one-to-many

2007-02-06 Thread Derek Watson

That was pretty much my position, too -- I was looking for something more
semantically appropriate. My task was trivial to solve in one or two ways, I
just didn't see any examples on how to do this stuff elegantly. What I am
really looking for is something expressive like

$product->find_prices(query => [ region => 'UK' ])->delete_all;



On 2/6/07, Ted Zlatanov <[EMAIL PROTECTED]> wrote:


On Tue, 6 Feb 2007 13:19:37 -0500 "John Siracusa" <[EMAIL PROTECTED]>
wrote:

JS> After doing that, you could set prices to undef to cause the
JS> collection to be re-fetched from the database on the next access:

JS> my($price) = grep { $_->region eq 'UK' } $p->prices;
JS> $price->delete;
JS> $p->prices(undef);# forget previously fetched collection
JS> @prices = $p->prices; # collection no longer contains deleted
entry

What always annoyed me about this technique is that it looks like
you're losing all the prices.  Setting something to undef generally
has that meaning in Perl.  I would rather write

$p->forget_prices();

or something like it (the same effect could be achieved behind the
scenes).  This should definitely not be a helper function, if it's
used, because the whole point is that the default semantics should not
be confusing to new users.  Perhaps I'm the only one of this opinion.

Ted

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job
easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


Re: [RDBO] Deleting from a one-to-many

2007-02-06 Thread Ted Zlatanov
On Tue, 6 Feb 2007 13:19:37 -0500 "John Siracusa" <[EMAIL PROTECTED]> wrote: 

JS> After doing that, you could set prices to undef to cause the
JS> collection to be re-fetched from the database on the next access:

JS> my($price) = grep { $_->region eq 'UK' } $p->prices;
JS> $price->delete;
JS> $p->prices(undef);# forget previously fetched collection
JS> @prices = $p->prices; # collection no longer contains deleted entry

What always annoyed me about this technique is that it looks like
you're losing all the prices.  Setting something to undef generally
has that meaning in Perl.  I would rather write

$p->forget_prices();

or something like it (the same effect could be achieved behind the
scenes).  This should definitely not be a helper function, if it's
used, because the whole point is that the default semantics should not
be confusing to new users.  Perhaps I'm the only one of this opinion.

Ted

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


Re: [RDBO] Deleting from a one-to-many

2007-02-06 Thread John Siracusa
On 2/6/07, Derek Watson <[EMAIL PROTECTED]> wrote:
> How would I go about deleting only the UK price? The following seems to
> delete the UK price record, but leaves it in the collection of $p->prices.
>
> my ($price) = grep { $_->region eq 'UK' } $p->prices;
> $price->delete;

After doing that, you could set prices to undef to cause the
collection to be re-fetched from the database on the next access:

my($price) = grep { $_->region eq 'UK' } $p->prices;
$price->delete;
$p->prices(undef);# forget previously fetched collection
@prices = $p->prices; # collection no longer contains deleted entry

> Should I also be calling $p->save? Or should I be doing something more like
> this?
>
> my @prices = grep { $_->region ne 'UK' } $p->prices;
> $p->prices(@prices);
> $p->save;

That works too, but it's quite inefficient, deleting and re-inserting
the entire price list (now sans one price) on save().

> Is there a more explicit way to do what I'm after without resorting to this
> grep business?

Both of those techniques seem pretty explicit to me :)  I'm not sure
what more could be done without delving into some extra magic, e.g.
making each price aware of what collection it was fetched as part of
so that $price->delete will also cause it to be removed from the list.
 But magic like that it a lot more trouble than it's worth, IMO.
(It's not hard to think of scenarios where that magic would break.)

If you do this a lot, it shouldn't be too much trouble to make a
helper method to hide the details of the implementation.

> I remember talk a couple weeks back about $p->find_prices(region => 'UK')
> functionality.  Will this be included in a release sometime soon?

Yes, probably by the end of the month at the latest.  It's in SVN now
if you want to try it.

-John

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


[RDBO] Deleting from a one-to-many

2007-02-06 Thread Derek Watson

Hello,

What is the recommended idiom for deleting a single object from a
one-to-many relationship? Using the textbook example,

$p = Product->new(name => 'Kite');
$p->prices({ price => 1.23, region => 'US' },
  { price => 4.56, region => 'UK' });
$p->save; # database is modified here


How would I go about deleting only the UK price? The following seems to
delete the UK price record, but leaves it in the collection of $p->prices.

my ($price) = grep { $_->region eq 'UK' } $p->prices;
$price->delete;

Should I also be calling $p->save? Or should I be doing something more like
this?

my @prices = grep { $_->region ne 'UK' } $p->prices;
$p->prices(@prices);
$p->save;

Is there a more explicit way to do what I'm after without resorting to this
grep business? I remember talk a couple weeks back about
$p->find_prices(region => 'UK') functionality.  Will this be included in a
release sometime soon? I'd prefer not to resort to a Manger call, because
then I need to repeat the expression of the relationship (--DRY).

Cheers,
-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object