[ic] Safe restrictions

Mike Heins interchange-users@icdevgroup.org
Fri Nov 8 15:31:01 2002


Quoting Jerry (jerry@digitalfm.com):
> 
> This has been driving me nuts today. Maybe I'm
> just missing something simple or perhaps an
> sql insert isn't possible with SAFE other than
> into products? Maybe someone can help why this
> code gives a safe error:
> Safe: no access for database products
> 
>     [perl tables=codes]
>     $Tag->query({sql => "insert into codes (code, region) values ('1',
> '12345')"});
> 	return;
>     [/perl]
> 
> This code, if used to write to the products database
> works fine. Safe::Hole is installed and currently
> running IC 4.8.
> 

This is because you don't tell it which database it can find "codes" in. We
don't parse the SQL statement direectly, and it has no way of knowing
that it needs to go to the codes table to get it.

Either:

    [perl tables="codes products"]
    ... as before

or

    $Tag->query({
	    base => 'codes',
	    sql => "insert into codes (code, region) values ('1', > '12345')",
    });

will probably work. The second is better, though better yet would
be:

    my $db = $Db{codes};
    my $rc = $db->query("insert into codes (code, region) values ('1', > '12345')");

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.513.523.7621      <mike@perusion.com>

"All you need in this life is ignorance and confidence, and
then success is sure." -- Mark Twain