469,271 Members | 1,014 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

how to solve the error " DBD::SQLite::db selectall_arrayref failed: unrecognized"?

47
Can you give me a hint that how to print out the 2d array

package DataLayer;
sub nextWords {
my $lang_size = languages();
for my $id(1 .. $lang_size ){
my ($id, $offset) = @_;
my @array = ();
my $statement = $db->selectall_arrayref("select word from words
left outer join language
on words.languageId = language.languageId
where words.languageId = $id
order by word asc
limit 10 offset $offset;");

my @main= ();
foreach my $i (@$statement)
{
push(@main, @{$i}[0]);
}
@array[$id] = [@main];

return @array;
}
}

and I create a test class in order to test the result.

$object = DataLayer->new();


print "Words :\n";

for my $id(1 .. 3 ){

print "=======ID = " . $id . "=======\n";
my $self = 0;
NAME: while (1 > 0){
my @newwordsList = $object->nextWords($id,$self);

$self+= 10;
foreach my $k (@{@newwordsList[$id]}) {

print $k . "\n";
}
print "\n";
if (!@{@newwordsList[$id]}[0]) {
last NAME;
}
}
}

and it gives me an error DBD::SQLite::db selectall_arrayref failed: unrecognized token: "0x156b16c" at C:/

please help .. thank you very much
Feb 28 '11 #1
11 3634
rovf
41
Did you have strict and warnings enabled?
Feb 28 '11 #2
Wiinie
47
yes i did have both
use strict;
use warning;
Feb 28 '11 #3
rovf
41
I guess you mean "use warnings", and not "use warning"....

This is strange, because I would have expected that you should get warning (for example) for

push(@main, @{$i}[0]);

Which Perl version are you using?
Feb 28 '11 #4
Wiinie
47
I did not get any warnings. and i use the latest version.
anything in the codes are ok. i just have a problem with printing the result. can you help me to print the result

thanks
Feb 28 '11 #5
rovf
41
Well, since the error is issued by selectall_arrayref, did you verify that $id and $offset has a reasonable value? I see that you get them from @_, so it might be that they are already garbage at this point.

Further, this construct is weird:


for my $id(1 .. $lang_size ){
my ($id, $offset) = @_;
...
}


You have a variable $id, and in the loop you "hide" it with another variable of the same name, $id (which you incidentally also get from @_). It is not *forbidden* doing it, but is this REALLY what you want to achieve?
Feb 28 '11 #6
Wiinie
47
lol, sorry about that,

for my $id(1 .. $lang_size ){
my ($id, $offset) = @_;
...
}



i just wanna get the size of language() which is (1,2,3)
so i can loop 3 times with different of languages.

can you give me a specific code to print it out because i try several ways, i am still stuck with selectall_arrayref .. please help.. thanks
Feb 28 '11 #7
rovf
41
That's not the point. I would like to know, why you use the SAME name for two DIFFERENT local variables? This really looks like a bug. And why are you assigning @_ *INSIDE* a loop, though it doesn't change? Your code, as posted, is equivalent to the following:


my ($id, $offset) = @_;
for my $this_variable_is_not_used_anyway (1 .. $lang_size ){
my @array = ();
...
}


Are you aware that in your original code, $id has the SAME value on every run through the loop, and that it does NOT have the values 1,2,3...? Basically, you are looping three times, but every time you issue the query with exactly the same values for $id and $offset. This is not forbidden, but certainly looks like a bug.
Mar 1 '11 #8
Wiinie
47
the idea i did that cuz i just wanna to increase the offset 10 each until it goes through each language
Mar 1 '11 #9
rovf
41
I don't question your "idea", but your "$id" (pun intended). No matter how many languages your have, $id will be the SAME value in each iteration.

BTW, you didn't comment yet on my earlier posting, where I asked you: "did you verify that $id and $offset has a reasonable value?"
Mar 1 '11 #10
Wiinie
47
ya i did.. but can u help me to print it out... i am really want to print out.. i cannot figure out how to print out the result..
Mar 1 '11 #11
rovf
41
So what where the values of $id and $offset right before doing the call to selectall_arrayref?

IMO it doesn't make sense discussing the result, as long as you get the error message in selectall_arrayref.
Mar 1 '11 #12

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.