ploticus: using #shell and #sql in ploticus scripts

## Using #shell and #sql in ploticus scripts | Welcome Gallery Handbook |
| Manual page for Using_#shell_and_#sql_in_ploticus_scripts(PL)

## #shell and #sql

These are two new directives that can be used in scripts with ploticus 2.00 and higher. They both work similary, and can either stream results into the script, or set variables. #shell is an interface for running external commands and capturing the results.`` #sql will allow ploticus to operate as a client to SQL databases, and works with pocketSQL. Interface to other databases (MySQL, Oracle, etc.) is not yet available; code contributions are sought in these areas (see `dbinterface.c`).``

## STREAMING DATA

Here is an example of how #sql is to be used with proc getdata :

     	#proc getdata
     	delim: tab
           data:
     	#sql #dumptab select * from trialresults where trialnum = @TRIALNUM

For longer SQL commands a multi-line construct is available:

     	#proc getdata
     	delim: tab
           data:
     	#sql #dumptab
     		select trialnum, age, sex, weight, time1, time2
     		 from trialresults
     		where trialnum = @TRIALNUM and trialdate = @TDATE
           #endsql

The #shell directive can be used similary, but this is redundant since proc getdata already has a `command` attribute.``

## SETTING VARIABLES

These directives may be used to set variables for plot labels, etc.`` For example:

     	#sql #load select fullname from tsyms where tickersym = @TSYM

           #proc annotate
           location: min max-0.2
           text: @fullname

Here is an example where the results of a shell command may be used to set variables:

           // submit the command..
           #shell #processrows cat mydata | grep "^Jan"
           // get one result rows and parse out fields..
           #call $shellrow( A, B, C )

     	#proc annotate
     	location: min max-0.2
     	text: @A @B

## DRIVING LOOPS

These directives may be used to drive loops that iterate once per row of results. For example:

     	// get a list of cases
     	#sql #processrows select caseid from cases
     	#while $sqlrow() = 0
     	  // get data for a case
     	  #proc getdata
     	  delim: tab
     	  data:
     	    #sql2 #dumptab select * from casedata where caseid = @caseid
     	    ... plot the case

     	#endloop

#shell may be used similary.``
data display engine
Copyright Steve Grubb

Markup created by unroff 1.0, `` `` September 17, 2001.