FAQ
Hi,
Could someone please show me the syntax to create multiple records. For example my table book has 3 fields : id (auto_increment), title, price. On the template I have 3 rows of title/price. I want to enter 3 book titles and prices and create at the same time.
With the old syntax, I can do something like
my $book = myapp::M::CDBI::Book::Shift->create(\%hash);

In this new version, I get error.

Thank you

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20061229/6a40c2cd/attachment.htm

Search Discussions

  • Jonathan Rockway at Dec 29, 2006 at 8:07 pm

    Will Smith wrote:
    Hi,
    Could someone please show me the syntax to create multiple records. For
    example my table book has 3 fields : id (auto_increment), title, price.
    On the template I have 3 rows of title/price. I want to enter 3 book
    titles and prices and create at the same time.
    With the old syntax, I can do something like
    my $book = myapp::M::CDBI::Book::Shift->create(\%hash);
    Are you really using CDBI? If so, switch to DBIC and do:


    push @records, {title => "foo", price => "13.37"};
    # same thing a few more times...
    eval {
    $c->model('BookDB::Books')->create($_) for (@records);
    }
    die "Error: $@" if($@);

    or something similar.

    --
    package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
    $,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
    ";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;
  • Will Smith at Dec 29, 2006 at 8:27 pm
    Thank you,
    Yes, I mean I'm using DBIC. I've tried your method. It did not give error, but, also did not insert into the table.
    Do I miss something?


    Jonathan Rockway wrote: Will Smith wrote:
    Hi,
    Could someone please show me the syntax to create multiple records. For
    example my table book has 3 fields : id (auto_increment), title, price.
    On the template I have 3 rows of title/price. I want to enter 3 book
    titles and prices and create at the same time.
    With the old syntax, I can do something like
    my $book = myapp::M::CDBI::Book::Shift->create(\%hash);
    Are you really using CDBI? If so, switch to DBIC and do:


    push @records, {title => "foo", price => "13.37"};
    # same thing a few more times...
    eval {
    $c->model('BookDB::Books')->create($_) for (@records);
    }
    die "Error: $@" if($@);

    or something similar.

    --
    package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
    $,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
    ";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;

    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/


    __________________________________________________
    Do You Yahoo!?
    Tired of spam? Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20061229/537fcae1/attachment.htm
  • Juan Miguel Paredes at Dec 29, 2006 at 11:52 pm

    On 12/29/06, Will Smith wrote:
    Thank you,
    Yes, I mean I'm using DBIC. I've tried your method. It did not give error,
    but, also did not insert into the table.
    Do I miss something?
    Hi, Will!

    Are the correct SQL statements being generated? (try export
    DBI_TRACE=1 or something like that)

    Is a COMMIT missing? (check AutoCommit on your dsn and/or DBD::*
    database specific docs, e.g. for PostgreSQL/Oracle it is off by
    default, IIRC)

    Greetings!
  • Will Smith at Jan 2, 2007 at 3:54 pm
    happy new year to all of you.

    thanks all for your support. Back to the question, (which I guess, will irritate some catalyst/perl gurus - but please be patient for learners), I've been able to add multiple records with "PRE" assigned values. But that's not my purpose. I need to add multiple rows that have the same name on the html. I tried several ways, but none was good.

    my $book;
    my $record;
    foreach $book ( @{$c->request->params->{book}}){

    push @records, {title => $book, price => $price };
    };

    eval{
    $c->model('bookDB::Book')->create($_) foreach (@records);
    };

    ---- this gives me the compling error: Global symbol "@records" requires explicit package name

    Juan Miguel Paredes wrote: On 12/29/06, Will Smith wrote:
    Thank you,
    Yes, I mean I'm using DBIC. I've tried your method. It did not give error,
    but, also did not insert into the table.
    Do I miss something?
    Hi, Will!

    Are the correct SQL statements being generated? (try export
    DBI_TRACE=1 or something like that)

    Is a COMMIT missing? (check AutoCommit on your dsn and/or DBD::*
    database specific docs, e.g. for PostgreSQL/Oracle it is off by
    default, IIRC)

    Greetings!

    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/


    __________________________________________________
    Do You Yahoo!?
    Tired of spam? Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070102/0de1ae97/attachment.htm
  • Leandro Hermida at Jan 2, 2007 at 4:24 pm
    Where did you declare @records? I can't see that in your code below but
    "my $record" could have been a typo and should read "my @records". You
    get that error in Perl when you try to use a variable that is not
    declared (under use strict;) or the declared variable is then used
    outside of its lexical scope.

    Leandro




    ________________________________

    From: Will Smith
    Sent: Tuesday, January 02, 2007 16:54
    To: The elegant MVC web framework
    Subject: Re: [Catalyst] Create multiple records


    happy new year to all of you.

    thanks all for your support. Back to the question, (which I
    guess, will irritate some catalyst/perl gurus - but please be patient
    for learners), I've been able to add multiple records with "PRE"
    assigned values. But that's not my purpose. I need to add multiple rows
    that have the same name on the html. I tried several ways, but none was
    good.

    my $book;
    my $record;
    foreach $book ( @{$c->request->params->{book}}){

    push @records, {title => $book, price => $price };
    };

    eval{
    $c->model('bookDB::Book')->create($_) foreach
    (@records);
    };

    ---- this gives me the compling error: Global symbol "@records"
    requires explicit package name


    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070102/e21ea619/attachment-0001.htm
  • Will Smith at Jan 2, 2007 at 4:48 pm
    oops, that a typo, sorry, I fixed that one. I realized it right after I sent the mail. The problem is it does not loop through the html page. this is what i done, and just the first value got inserted:
    my @records;
    my $book;
    foreach ( $book = (shift @{$c->request->params->{book}})){

    push @records, {title => $book};
    };
    if, i try to put a second params, it just do nothing;
    push @records, {title => $book, price => $c->request->params->{price}};


    "Hermida, Leandro" wrote: Where did you declare @records? I can't see that in your code below but "my $record" could have been a typo and should read "my @records". You get that error in Perl when you try to use a variable that is not declared (under use strict;) or the declared variable is then used outside of its lexical scope.

    Leandro



    ---------------------------------
    From: Will Smith
    Sent: Tuesday, January 02, 2007 16:54
    To: The elegant MVC web framework
    Subject: Re: [Catalyst] Create multiple records



    happy new year to all of you.

    thanks all for your support. Back to the question, (which I guess, will irritate some catalyst/perl gurus - but please be patient for learners), I've been able to add multiple records with "PRE" assigned values. But that's not my purpose. I need to add multiple rows that have the same name on the html. I tried several ways, but none was good.

    my $book;
    my $record;
    foreach $book ( @{$c->request->params->{book}}){

    push @records, {title => $book, price => $price };
    };

    eval{
    $c->model('bookDB::Book')->create($_) foreach (@records);
    };

    ---- this gives me the compling error: Global symbol "@records" requires explicit package name
    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/


    __________________________________________________
    Do You Yahoo!?
    Tired of spam? Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070102/71dcddc7/attachment.htm

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedDec 29, '06 at 6:24p
activeJan 2, '07 at 4:48p
posts7
users4
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2021 Grokbase