Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Error while using Catalyst to insert record to Oracle

by marscld (Beadle)
on Aug 14, 2008 at 07:52 UTC ( [id://704301]=perlquestion: print w/replies, xml ) Need Help??

marscld has asked for the wisdom of the Perl Monks concerning the following question:

While using Catalyst to insert a book record, error occurs. After searching info from google, no solution is found. Would you pls offer some advice ? Here is the controller's code.
sub url_create : Local { # In addition to self & context, get the title, rating, & # author_id args from the URL. Note that Catalyst automatical +ly # puts extra information after the "/<controller_name>/<action +_name/" # into @_ my ($self, $c, $title, $rating, $author_id) = @_; # Call create() on the book model object. Pass the table # columns/field values we want to set as hash values my $book = $c->model('DB::Books')->create({ title => $title, rating => $rating }); # Add a record to the join table for this book, mapping to # appropriate author $book->add_to_book_authors({author_id => $author_id}); # Note: Above is a shortcut for this: # $book->create_related('book_authors', {author_id => $author_ +id}); # Assign the Book object to the stash for display in the view $c->stash->{book} = $book; # This is a hack to disable XSUB processing in Data::Dumper # (it's used in the view). This is a work-around for a bug in # the interaction of some versions or Perl, Data::Dumper & DBI +C. # You won't need this if you aren't using Data::Dumper (or if # you are running DBIC 0.06001 or greater), but adding it does +n't # hurt anything either. $Data::Dumper::Useperl = 1; # Set the TT template to use $c->stash->{template} = 'books/create_done.tt2'; }
However, after accessing URL "http://localhost:3000/books/url_create/TCPIP_Illustrated_Vol-2/5/4", error shows up as :
INSERT INTO books (rating, title) VALUES (?, ?): '5', 'TCPIP_Illustrat +ed_Vol-2' SELECT COUNT( * ) FROM books me: SELECT COUNT( * ) FROM books me: [info] *** Request 1 (0.038/s) [5225] [Thu Aug 14 15:29:27 2008] *** [debug] "GET" request for "books/url_create/TCPIP_Illustrated_Vol-2/5/ +4" from "202.38.40.128" [debug] Path is "books/url_create" [debug] Arguments are "TCPIP_Illustrated_Vol-2/5/4" [error] DBI Exception: DBD::Oracle::st execute failed: ORA-01400: cann +ot insert NULL into ("SDB2"."BOOKS"."ID") (DBD ERROR: OCIStmtExecute) + [for Statement "INSERT INTO books (rating, title) VALUES (?, ?)" wit +h ParamValues: :p1='5', :p2='TCPIP_Illustrated_Vol-2'] at /usr/local/ +lib/perl5/site_perl/5.10.0/DBIx/Class/Schema.pm line 954

Replies are listed 'Best First'.
Re: Error while using Catalyst to insert record to Oracle
by psini (Deacon) on Aug 14, 2008 at 10:07 UTC

    It looks like your BOOKS table has an ID column declared NOT NULL. How was the table created?

    Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

      The problem seems that primary key ID of BOOKS is not being calculated correctly. And it is supposed to be a incremental process to fetch max ID and increase by 1. However, not finding a clue on tutorial. Though Catalyst tutorial uses SQLite as database, I just try to use Oracle instead.

        Oracle uses sequences and triggers, not just a null or zero like some other DB engines. See link for a short discussion. Details can be found in your local Oracle docs but this is at least mentioned in the module description.

        I started with MySQL (which allows what you tried) and have had to deal with many issues with other DB's. Some people may recommend a higher-level DB interface but I've never used them personally.

      It is created by running a command, which is a little bit different from tutorial.
      script/myapp_create.pl model DB DBIC::Schema MyApp::Schema create=stat +ic dbi:Oracle:OTEST sdb2 sdb
Re: Error while using Catalyst to insert record to Oracle
by phaylon (Curate) on Aug 19, 2008 at 11:40 UTC
    I have no real experience (anymore) with Oracle, but just FYI and for the future: Catalyst is model-agnostic. It doesn't insert anything into any database by itself. You are using DBIx-Class and connecting it to Catalyst via Catalyst::Model::DBIC::Schema which is its own distribution.

    Ordinary morality is for ordinary people. -- Aleister Crowley

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://704301]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-03-28 15:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found