Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is it possible to store an array in a sql database?? 1

Status
Not open for further replies.

wixsas

Programmer
May 23, 2007
12
0
0
AU
Hi just wondering if it was possible to store an array in an sql database???
Here is my code:


my @ListOfSongs = param("songs");

my $dbh = DBI->connect("DBI:SQLite:sessions.db")
or die "Cannot connect: " . $DBI::errstr;

$sth = $dbh->prepare("UPDATE sessions SET contents = @ListOfSongs WHERE cartID = $cookie")
or die "Cannot prepare";
$sth->execute() or die "Cannot execute";


As you can see i have an array called @ListOfSongs which holds song titles. I want to store it in the array so that i can then pull it out later when it is needed.

Cheers
 
You never put quotes around ? placeholders in the SQL. It looks like it might be some kind of parameter binding error. Have a look at the bind methods in the DBI documentation on CPAN.

Although DBI has some support for passing in a couple of lists of parameters and breaking them down into tuples, so you can do a multiple insert with one call, it looks like it might be more trouble than it's worth. Have a go with the bind and see what happens. Also, if you can post a snippet showing what your code looks like at the moment, it might help. You can also print out $DBI::err and $DBI::errstr after each call for debugging.

Does it break on the first iteration, or the second? Is it a primary key issue?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top