Hello friendly perl monks!

I am trying to find_or_create the following:

my $foo = MyDB::Foo->find_or_create({ name => 'name', uri => 'hello', });

with my MyDB::Foo looking like this:

package MyDB::Foo; use base MyDB; __PACKAGE__->table('foo'); __PACKAGE__->columns( ALL => ('foo_id','name','uri') ); 1;

and I get the following error:

MyDB::Foo can't SELECT FROM foo WHERE name = ? AND uri = ? : DBD::mysql::st execute failed: You have an error in your SQL syntax; + check the manual that corresponds to your MySQL server version for t +he right syntax to use near 'FROM foo WHERE name = 'name' AND uri = 'hello'' at line 2 [for Statement "SELE +CT FROM foo WHERE name = ? AND uri = ? " with ParamValues: 0='name', 1='hello'] at C:/Perl/site/lib/DBIx/Cont +extualFetch.pm line 52. at C:/Perl/site/lib/Class/DBI/Search/Basic.pm line 169

Now if I use insert instead of find_or_create, it inserts fine and all the data is in the DB like I want it.

Also, inserting it, then searching for it makes the insert work fine, search not ( which kind of makes my title a bit misleading I guess, sry )

just in case this is relevant, here is the SQL file I used to create the table:

CREATE TABLE foo ( foo_id INTEGER PRIMARY KEY AUTO_INCREMENT, name TEXT, uri TEXT );

where is my mistake?

any help appreciated...


In reply to Class::DBI find_or_create by theugywithahat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.