theugywithahat has asked for the wisdom of the Perl Monks concerning the following question:
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...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Class::DBI find_or_create
by theugywithahat (Initiate) on Dec 29, 2011 at 07:36 UTC | |
by choroba (Cardinal) on Dec 29, 2011 at 10:50 UTC |