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

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.