From 9ba23acd7a2e062457f5c07cbcfd2449a4ff65a3 Mon Sep 17 00:00:00 2001 From: Max Maischein Date: Fri, 3 Apr 2009 19:46:29 +0000 Subject: [PATCH] Added a canary test for #RT 36836 --- Changes | 1 + t/rt_36836_duplicate_key.t | 86 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 t/rt_36836_duplicate_key.t diff --git a/Changes b/Changes index 90f6c0f..9fe0f53 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ Revision history for Perl extension DBD-SQLite. 1.19_07 not released yet - re-enable and fix t/70schemachange.t, as per RT #43448 (CORION) + - added a canary test to probe for RT #36863 (segfault on OSX 10.5.2) 1.19_06 Sat 4 Apr 2009 - Fixed a segv with an error function under x86 linux diff --git a/t/rt_36836_duplicate_key.t b/t/rt_36836_duplicate_key.t new file mode 100644 index 0000000..8a4079f --- /dev/null +++ b/t/rt_36836_duplicate_key.t @@ -0,0 +1,86 @@ +#!/usr/bin/perl + +# This is a simple insert/fetch test. + +use strict; +BEGIN { + $| = 1; + $^W = 1; +} + +use t::lib::Test; + +use vars qw($state); + +# +# Include lib.pl +# +do 't/lib.pl'; +if ($@) { + print STDERR "Error while executing lib.pl: $@\n"; + exit 10; +} + +sub ServerError() { + print STDERR ("Cannot connect: ", $DBI::errstr, "\n", + "\tEither your server is not up and running or you have no\n", + "\tpermissions for acessing the DSN 'DBI:SQLite:dbname=foo'.\n", + "\tThis test requires a running server and write permissions.\n", + "\tPlease make sure your server is running and you have\n", + "\tpermissions, then retry.\n"); + exit 10; +} + +# +# Main loop; leave this untouched, put tests after creating +# the new table. +# +my ($dbh, $def, $table, $cursor); +while (Testing()) { + + # + # Connect to the database + Test($state or $dbh = DBI->connect('DBI:SQLite:dbname=foo', '', ''), + 'connect') + or ServerError(); + + # + # Find a possible new table name + # + Test($state or $table = FindNewTable($dbh), 'FindNewTable') + or DbiError($dbh->err, $dbh->errstr); + + # + # Create a new table; EDIT THIS! + # + Test($state or ($def = TableDefinition($table, + # CREATE TABLE nums (num INTEGER UNIQUE); + ["num", "INTEGER", 4, 0], + ) and + $dbh->do($def)), 'create', $def) + or DbiError($dbh->err, $dbh->errstr); + Test($state or ($dbh->do("CREATE UNIQUE INDEX idx_${table}_num ON $table (num)"))) + or DbiError($dbh->err, $dbh->errstr); + + + # + # Insert a row into the test table....... + # + Test($state or $dbh->do("INSERT INTO $table (num)" + . " VALUES(1)" ), 'insert') + or DbiError($dbh->err, $dbh->errstr); + + # + # Now try to insert a duplicate + # + Test($state or !$dbh->do("INSERT INTO $table (num)" + . " VALUES(1)" ), 'insert') + ; + + # + # Finally drop the test table. + # + Test($state or $dbh->do("DROP TABLE $table"), 'drop') + or DbiError($dbh->err, $dbh->errstr); + +}