[ic] Accessing table in Perl prevents [import] from working later

Chris Wenham cwenham@netmonger.net
Thu, 21 Sep 2000 16:31:44 -0400 (EDT)

 I have a page that uses some perl code to do some error checking
 before using [import] to add a record to a table.

 Within the perl code I need to access the same table that [import]
 works on later, so I open it in the perl tag like this:

 [perl tables="tenants"]
       ...blah blah blah...

 Later on in the page comes the [import] tag, looking like this:

 [seti import_results]
 [import table=tenants type=LINE continue=NOTES]
	 field: value

 After running a number of tests I've found that the insert will work
 if I don't name the table in the [perl] tag, but fails to insert the
 record if the table /is/ named in the [perl] tag.

 Is Interchange locking the table in some way?

 I'm using Interchange 4.5.6 from the CVS repository (updated thursday
 morning) but I've observed it with 4.5.5 too.

 The full code is as follows:

[seti numerrors][perl tables="userdb tenants"]
	my @errors = ();
	my $output = "";
	my $user = $Session->{username};
	my $opt = {
		op	=> 'time',
		body	=> '%s',

	if ($Values->{subject_ln} !~ /\w+/) { push @errors, "Missing a last name."; };
	if ($Values->{tenant_id} !~ /^\d{3}-\d{2}-\d{4}$/) { push @errors, 'Malformed or missing Social Security number (must be in the form ###-##-####).'; };

        if (($Tag->data( 'tenants', 'tenant_id', $Values->{tenant_id}) eq $Values->{tenant_id}) & ($Values->{report_mode} eq 'new')) { push @errors, 'There is already a tenant with this Social Security number in the database.'; };

	if ($Tag->data('userdb', 'member', $user) < $Tag->tag( $opt )) { push @errors, 'You have an insufficient or expired membership.'; };

	if (@errors > 0) {
		foreach $error (@errors) {
			$output .= "<li> $error\n";
		$Scratch->{errors} = $output;
	return @errors;

[if scratch numerrors > 0]
	<h1>Errors found</h1>

	[scratch errors]

	[set name="report_phase"]initial[/set]
	[seti name="report_mode"][value report_mode][/seti]

	<p><strong>Please correct the errors listed above before continuing.</strong>


[if explicit]
	return 1 if (($Values->{report_phase} eq "confirmation") & ($Scratch->{numerrors} == 0)) || return 0;

	[comment] Save the record [/comment]
	[tag flag write]tenants[/tag]

	[seti import_results]
	[import table=tenants type=LINE continue=NOTES]
	tenant_id: [value tenant_id]
	relationship: [value relationship]
	subject_fn: [value subject_fn]
	subject_ln: [value subject_ln]
	address: [value address]
	start_date: [value start_date]
	end_date: [value end_date]
	payment: [value payment]
	violations: [value_extended violations]
	return: [value return]
	legal: [value legal]
	damages: [value damages]
	rating: [value rating]
	comments: [value comments]
	[if value report_mode eq new]
		enterer: [data session username]
		entered: [tag op=time]%s[/tag]
		updator: [data session username]
		updated: [tag op=time]%s[/tag]

	[if value report_mode eq new]
		<p>Thank you for reporting a tenant to the National
		Tenant Rating Bureau! Remember that the NTRB can be
		used to report both good and bad tenants.
		<p>Your tenant report has been updated. Thank you for
		helping us keep the National Tenant Rating Bureau up
		to date!

	<p><a href="[area deadbeat/report]"><strong>Report another Tenant</strong></a>
	<p><a href="[area index]"><strong>Main Menu</strong></a>
	<p><strong>Search the National Tenant Rating Bureau</strong>


	[seti export_results][tag export tenants][/tag][/seti]