perl_class_definition always returns 'scalar' column types

86 views
Skip to first unread message

Chris

unread,
Jul 24, 2012, 1:32:36 PM7/24/12
to rose-db...@googlegroups.com
I have an Oracle table definition :

CREATE TABLE PRODUCTS(
  ID            INTEGER,
  NAME          VARCHAR2(255 BYTE)              NOT NULL,
  STATUS        VARCHAR2(128 BYTE)              DEFAULT 'inactive'            NOT NULL,
  DATE_CREATED  TIMESTAMP(6)                    DEFAULT sysdate,
  RELEASE_DATE  TIMESTAMP(6),
  VENDOR_ID     INTEGER
);

When calling perl_class_defintion from within my Rose::DB::Object class as such :

__PACKAGE__->meta->table('PRODUCTS');
__PACKAGE__->meta->auto_initialize();
print __PACKAGE__->meta->perl_class_definition(
    indent => 4,
    braces => 'bsd'
);


It returns all scalar column types : 

package TestApp::DB::Object::Product;
use strict;
use base qw(TestApp::DB::Object);

__PACKAGE__->meta->setup
(
    table   => 'PRODUCTS',

    columns => 
    [
        ID           => { type => 'scalar', alias => 'id', length => 38, not_null => 1 },
        NAME         => { type => 'scalar', alias => 'name', length => 255, not_null => 1 },
        STATUS       => { type => 'scalar', alias => 'status', default => 'inactive', length => 128, not_null => 1 },
        DATE_CREATED => { type => 'scalar', alias => 'date_created', default => 'sysdate', length => 11 },
        RELEASE_DATE => { type => 'scalar', alias => 'release_date', length => 11 },
        VENDOR_ID    => { type => 'scalar', alias => 'vendor_id', length => 38 },
    ],

    primary_key_columns => [ 'ID' ],
);
1;

Also, it doesn't seem to be detecting unique indices as well.  I have a unique index defined on the 'name'  column but as you can see 'unique_key => name' isn't part of the output.

I've scoured the docs (as well as this group) for the answer but to no avail.

Thoughts?

Thanks.

John Siracusa

unread,
Jul 24, 2012, 1:42:08 PM7/24/12
to rose-db...@googlegroups.com
What versions of Rose::DB::Object, Rose::DB, DBD::Oracle, DBI, and
Oracle are you using?

-John

Chris

unread,
Jul 24, 2012, 1:50:51 PM7/24/12
to rose-db...@googlegroups.com
Rose::DB::Object : 0.798
Rose::DB : 0.769
DBD::Oracle : 1.46
DBI : 1.618
Oracle : 10g


John Siracusa

unread,
Jul 24, 2012, 2:19:54 PM7/24/12
to rose-db...@googlegroups.com
I don't have access to Oracle 10g here, but if you can throw a
breakpoint into auto_generate_column() in
Rose::DB::Object::Metadata::Auto and see what value $type and
$column_class end up with, that might get you started debugging it.

-John

Chris

unread,
Jul 30, 2012, 10:36:55 AM7/30/12
to rose-db...@googlegroups.com
Just for other's sake....because Rose::DB::Object::Metadata doesn't support varchar2 out of the box, I had to add the following method to my Metadata subclass :

__PACKAGE__->column_type_class(
    varchar2 => 'Rose::DB::Object::Metadata::Column::Varchar',
);

As for my INTEGER field, DBD Oracle returns 'NUMBER' type for any defined numeric columns in Oracle.  According to the DBD::Oracle POD this is because Oracle only supports NUMBER fields but does support other numeric fields as aliases.

Would I be losing any resolution if I just left NUMBER columns as default scalars (as are ID and VENDOR_ID in my table example above)?  Or should I bother in trying to map these columns manually with actual Rose::DB::Object::Metadata::Column types?

John Siracusa

unread,
Aug 10, 2012, 9:24:23 AM8/10/12
to rose-db...@googlegroups.com
On Mon, Jul 30, 2012 at 10:36 AM, Chris <ccam...@gmail.com> wrote:
> Just for other's sake....because Rose::DB::Object::Metadata doesn't support
> varchar2 out of the box, I had to add the following method to my Metadata
> subclass :
>
> __PACKAGE__->column_type_class(
> varchar2 => 'Rose::DB::Object::Metadata::Column::Varchar',
> );

OK, I'll add that.

> As for my INTEGER field, DBD Oracle returns 'NUMBER' type for any defined
> numeric columns in Oracle. According to the DBD::Oracle POD this is because
> Oracle only supports NUMBER fields but does support other numeric fields as
> aliases.

What do you think about mapping number to the
Rose::DB::Object::Metadata::Column::Numeric column type?

> Would I be losing any resolution if I just left NUMBER columns as default
> scalars (as are ID and VENDOR_ID in my table example above)? Or should I
> bother in trying to map these columns manually with actual
> Rose::DB::Object::Metadata::Column types?

I think you should be fine with them as scalar, but maybe
Rose::DB::Object::Metadata::Column::BigInt might be required for very
large integer values. Test it out with very large values and tell me
if the scalar type works for you.

-John


-John

Tom Adamo

unread,
Sep 26, 2012, 4:24:44 PM9/26/12
to rose-db...@googlegroups.com
John,

I like the idea of mapping number to Rose::DB::Object::Metadata::Column::Numeric, since I'm currently running into this problem as well (I'm trying to build a validation profile, so I need to know the datatype of this column numeric). I noticed it's already in Rose::DB::Object::Metadata, but just commented out.

- Tom

On Friday, August 10, 2012 9:24:23 AM UTC-4, John Siracusa wrote:

John Siracusa

unread,
Sep 26, 2012, 4:40:25 PM9/26/12
to rose-db...@googlegroups.com
On Wed, Sep 26, 2012 at 4:24 PM, Tom Adamo <tad...@gmail.com> wrote:
> I like the idea of mapping number to
> Rose::DB::Object::Metadata::Column::Numeric, since I'm currently running
> into this problem as well (I'm trying to build a validation profile, so I
> need to know the datatype of this column numeric). I noticed it's already in
> Rose::DB::Object::Metadata, but just commented out.

Just the "number" type name is commented out (and I'm not sure why).
You should be able to use the "numeric" or "num" type names to get the
same result.

-John

Tom Adamo

unread,
Oct 19, 2012, 3:57:03 PM10/19/12
to rose-db...@googlegroups.com
Yeah, I'm doing this now and it works fine.

package Local::DB::Object::Metadata;
use base 'Rose::DB::Object::Metadata';

__PACKAGE__->column_type_class(
    number => 'Rose::DB::Object::Metadata::Column::Numeric',
    varchar2 => 'Rose::DB::Object::Metadata::Column::Varchar',
);

Thanks,
- Tom
Reply all
Reply to author
Forward
0 new messages