Chemistry Reference
In-Depth Information
</BODY>
</HTML>
<?php
function marvin_sketch() {
$dbconn = pg_connect("host=localhost dbname=book user=reader");
$res = pg_exec($dbconn, "select marvin_sketch()");
$row = pg_fetch_array($res);
pg_close($dbconn);
return $row["marvin_sketch"];
}
?>
The marvin _ sketch SQL function can be called from any client
program using database access methods described in Chapter 5. The
marvin _ sketch program can be modified to allow specification of the
sketch applet size, loading an initial SMILES, or any other option pro-
vided by the Marvin sketch applet.
Most Web applications that search a database will need to know the
names of the columns in a table. Rather than coding this into the application,
consider writing an SQL function to provide this information. The following
SQL function returns the names of the columns in a particular table.
Create Or Replace Function get_fields(text,text) Returns Setof
Record As $EOSQL$
Declare
col_types Record;
Begin
For col_types In
SELECT attname::text, typname::text
FROM pg_attribute
Join pg_class On attrelid = pg_class.oid
Join pg_namespace On relnamespace = pg_namespace.oid
Join pg_type On atttypid = pg_type.oid
Where attnum > 0
And nspname = $1
And relname = $2
Loop
Return Next col_types;
End Loop;
End;
$EOSQL$ Language plpgsql;
This function is specific to PostgreSQL, using system catalog tables. It can
be used in a Web application as in the following php example.
<HTML>
<HEAD>
<TITLE>Sample PHP web app example</TITLE>
<SCRIPT SRC="http://www.chemaxon.com/marvin/marvin.js"></SCRIPT>
</HEAD>
Search WWH ::




Custom Search