This same program seg fault with MySQL. SQL statements are slightly modified to satisfy mySQL syntax. Tested on Windows XP.
use strict; use warnings; use Test::More tests => 4; use DBI; my $database = 'allwords.sqlite-v3'; unlink $database; my( %forward, %backward ); my $dbh = DBI->connect( "DBI:mysql:test", '', '', { RaiseError => 1, AutoCommit => 0 } ); #diag "Using DBD::SQLite $DBD::SQLite::VERSION"; diag "Creating database\n"; my @words = split /\s+/, <DATA>; @forward{ @words } = reverse @words; #$dbh->do('drop table wordtable'); diag "Creating word-pair database...\n"; $dbh->do('create table wordtable(a varchar(10),b varchar(10))'); my $sth = $dbh->prepare( "INSERT INTO wordtable(a, b) VALUES ( ?, ? )" ); while ( my( $left, $right ) = each %forward ) { $sth->execute( $left, $right ); } $sth->finish; $dbh->commit; diag "Database created.\n"; diag "Selecting (static value, 1st)\n"; my $value; $sth = $dbh->prepare( "SELECT b FROM wordtable WHERE a = 'shine'" ); undef $value; eval { $value = $dbh->selectrow_array( $sth, {}, ); }; is( $value, 'shine', 'Got "shine"'); diag "Selecting (static value, 2nd)\n"; undef $value; eval { $value = $dbh->selectrow_array( $sth, {}, ); }; is( $value, 'shine', "Got 'shine' and didn't crash"); diag "Selecting (placeholder, 1st round)\n"; my $value; $sth = $dbh->prepare( "SELECT b FROM wordtable WHERE a = ?" ); undef $value; eval { $value = $dbh->selectrow_array( $sth, {}, 'shine' ); }; diag $@ if $@; is( $value, 'shine', 'Got "shine"'); # This one crashes diag "Selecting (placeholder, 2nd round)\n"; undef $value; eval { $value = $dbh->selectrow_array( $sth, {}, 'shine' ); }; diag $@ if $@; is( $value, 'shine', "Got 'shine' and didn't crash"); $sth->finish(); $dbh->disconnect(); __DATA__ shine shine
In reply to Re: New way to segfault: selectrow_array() with placeholders, DBD::SQLite
by pg
in thread New way to segfault: selectrow_array() with placeholders, DBD::SQLite
by davido
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |