RS2 JiT compiler
© RedTitan Technology 2013
Revision history
1.7 - FORMAT, FLASH, (Draft TABLE functions)
1.71 - Format adjusts for MSFEDIT
1.72 - TAB_ALIGN changes
1.73 - resourcePDF function - basefile API
1.74 - Support for bullet lists
1.75 - CHAR function
1.77 - RESOURCE changes. PIPE IPC function.
1.78 - LIST_INDEXOF function
1.79 - MOD operator compile time "divide by zero" fix. July 2010
1.80 - WRITE procedure fix. Prevent an unterminated WRITE causing EscapeE hang on exit.
1.83 - INPUTBOX extended, Escapee (on close) bug fixes
1.84 - Functions TRUNC and ROUND added
2.01 - Major new features including SQL database support and QRCODE 2D barcode generation.
2.02 - OCR and Overlay function
3.0  - FIELDSET overloaded, OVERLAY_FREE function 
3.1  - OCR input parameters implemented, JOIN function documented
3.3. - DOTMATRIX character OCR support
RS2 is a lightweight pascal like scripting language. There are 3 versions The remainder of this document is the standard function and procedures available to the RS2 system.
function Copy(S:string; Index, Count: Integer): string; S is an expression of a string type. Index and Count are integer-type expressions. Copy returns a substring containing Count characters starting at S[Index]. If Index is larger than the length of S, Copy returns an empty string or array. If Count specifies more charactersthan are available, only the characters from S[Index] to the end of S are returned.
function StrToIntDef(S: string; Default: Integer): Integer; StrToIntDef converts the string S, which represents an integer-type number in either decimal or hexadecimal notation, into a number. If S does not represent a valid number, StrToIntDef returns Default.
function Length(LS:string|list): Integer; Length returns the number of characters in a string expression or the number of elements in a list (see setLength procedure);
Procedure setLength(var S:string|var L:List;i:integer): Integer; (Version 2) Specify a new length for a STRING or a LIST variable. (see LENGTH function);
procedure Delete(var S: string; Index, Count:Integer); Delete removes a substring of Count characters from string S starting with S[Index]. S is a string-type variable. Index and Count are integer-type expressions. If index is larger than the length of the string or less than 1, no characters are deleted. If count specifies more characters than remain starting at the index, Delete removes the rest of the string. If count is less than or equal to 0, no characters are deleted.
Function replace(s,oldpattern,newpattern):string; Function Replace replaces occurrences of the substring specified by OldPattern with the substring specified by NewPattern.
S is the source string, whose substrings are changed.
OldPattern is the substring to locate and replace with NewPattern.
NewPattern is the substring to substitute for occurrences of OldPattern.
Function quote(s:String):string; Use Quote to convert the string S to a quoted string. A single quote character (') is inserted at the beginning and end of S, and each single quote character in the string is repeated.
function StrToFloatDef(S: string; Default: Number):Number; Convert the string representing a decimal number. If S cannot be converted the default is returned
Function Pos(Substr: string; S: string): Integer; Pos searches for a substring, Substr, in a string, S. Substr and S are string-type expressions. Pos searches for Substr within S and returns an integer value that is the index of the first character of Substr within S. Pos is case-sensitive. If Substr is not found, Pos returns zero.
function Trim(const S: string): string; Remove whitespace (leading and trailing) from the string expression specified by S.
function LowerCase(const S: string): string; Return S converted to lowercase
function UpperCase(const S: string): string; Return S converted to uppercase
Function Paramcount:Integer; ParamCount returns the number of parameters passed to the program on the command line
function ParamStr(Index: Integer): string; ParamStr returns the parameter from the command line that corresponds to Index, or an empty string if Index is greater than ParamCount. For example, an Index value of 2 returns the second command-line parameter.

In EscapeE, ParamStr(0) returns the path and file name of the RS/2 program e.g. TEST.RS2. ParamStr(1) supplies the page number. Paramstr(2) etc., are used to pass on other paramaters supplied in the EscapeE (v8.85+) extended command line filename syntax. e.g.
TEST.RS2,PARAM,PARAM
function InputBox(const ACaption, APrompt, ADefault: string[;multiline:boolean=false]): string; Modal dialogue returns user input or default. Set the fourth parameter to true (v1.83) to display a multi-line edit window.
Function CHOOSE(Caption,prompt:string;Listbox:List):integer;(Version 2) Display a modal dialogue showing a list box. The function returns the index of the item in the list selected or -1 if the dialogue CANCEL button is clicked.
Procedure Flash(s:string); Display non-modal text alert window until another modal dialogue or a new top window is selected.
Function Query(caption:string;[timeout:integer;default:boolean]):boolean; Display dialogue requesting a YES or NO response. The optional parameter TIMEOUT, DEFAULT specifies the number of milliseconds to wait for user response and the default if the dialogue times out,
Procedure Showmessage(s:string;[timeout:integer]); Display modal dialogue alert message; The optional parameter TIMEOUT specifies the number of milliseconds to wait for user response
Function Browse[(caption[[,InitialDir],filters]:String)]:String; Browse for a file dialogue.
e.g.
j:=browse(
  'Select',
  'c:\eeplugin',
  'Zip (*.zip)|*.zip|Async (*.abb)|*.abb|Async (*.asy)|*.asy'
  );
Defaults if parameters are omitted.
'Select file','','*.*|*.*' 
Program should check for an empty string return. This indicates the dialogue has been cancelled.
procedure WriteLn(P1 [, P2, ...,Pn ] ); Write a line to the console window. In EscapeE this is the LOG window. (To write to a file see WRITELINE and LOG procedures)
procedure Write(P1 [, P2, ...,Pn ] ); Write text to the console window.
Procedure LOG(fn,item:string);Append a text entry to a named log file.
Function PIPE(Pipename,Query:String):String; The RS2 function PIPE, provides interproccess communication on a local computer to another program that implements the named PIPE SERVER. (Google "NAMED PIPES" for more information). Strings of up to 8000 bytes may be sent and received. e.g. to send database queries to MICROSOFT SQL SERVER. See NAMESERVER.ZIP in the rs2 demo files.
Function trunc(n:Number):Integer; Round n to an integral value - towards 0. See also ROUND
Function round(n:Number):Integer; Round n to an integral value nearest to a whole number. Note: RS2 stores all numbers in floating point.
Function even(n:Number):Boolean; Return true if number N is not odd.
Function odd(n:Number):Boolean; Return true if number N is odd.
procedure Inc(var X [ ; N: Number ] ); X is an integer variable. N is an integer-type expression. X increments by 1, or by N if N is specified; that is, Inc(X) corresponds to the statement X := X + 1, and Inc(X, N) corresponds to the statement X := X + N. However, Inc generates optimized code and is especially useful in tight loops.
procedure Dec(var X[ ; N: Number]); X is an integer variable. N is an integer-type expression. X decrements by 1, or by N if N is specified; that is, Dec(X) corresponds to the statement X := X - 1, and Dec(X, N) corresponds to the statement X := X - N. However, Dec generates optimized code and is especially useful in tight loops.
Function Char(n:number):String; Construct a string consisting of a single wide character. $ffff>=n<=0. (see ORD function)
function Ord(const S: string): Integer; Return the ordinal value of the first wide character of the string specified by S. The result will be in the range 0..$ffff (see function CHAR)
function Min(A,B: Integer): Integer;
function Max(A,B: Integer): Integer;
Procedure Split(Source,Separator:string;var LX:List); Split the SOURCE string into a number of elements delimited by the SEPARATOR string. e.g.
split('alpha/beta/gamma','/',LX);
The elements are returned in the list specified by the LX parameter. The previous contents of the list are lost. If the separator does not exist in the source string the list will contain a single entry consisting of the entire source string.
See also JOIN function.
Function List_Strings(L:List;I:Integer):String; Return the element specified by I as a string. See also LENGTH and JOIN functions
Function List_Add(L:List;S:String):Integer; Add a string element to the list L. Returns the element index.
Procedure assign(var L:List;I:Integer;Value); (Version 2). Change the specified element of a list variable to a new value. The VALUE may be any type.
Procedure List_Clear(L:List); Remove all elements in L.
Function List_Numbers(L:List;I:Number:Integer):Number Return element I of list L as a number. If the list element cannot be interpreted as a number returns -1; See also LENGTH.
Function List_IndexOf(L:List;SearchFor:String;[CaseBlind:Boolean=True;[StartIndex:Integer=0]]):Integer; Returns the index of a specified string in a list. Returns -1 if the string is not found. The function defaults to case-blind string matching and searches from the first element of the list. e.g.
  l:=['alpha','Beta','gamma'];
  writeln(list_indexof(l,'beta')); // returns 1
  writeln(list_indexof(l,'beta',false)); // returns -1

Function Join(L:List;Sep:String):String; Return a string formed by concatonating the elements of the list L using a line ending specified in the SEP parameter.
  l:=['alpha','Beta','gamma'];
  flash(L,#10);

See also SPLIT function.
Function Pred(I:Integer):Integer; Equivalent to I:=I-1;
Function Succ(I:Integer):Integer; Equivalent to I:=I+1;
Function Now(Format:String):String; Format current date and time. e.g.
NOW('ddd mmm yyyy hh:mm:ss.zzz');

see format specifiers
function Random [Range: Integer]:integer; Random returns a random number within the range 0 <= X < Range.
Function Resource[PDF](FN:String; [x,y:number;[scale:Number;[Page:Number;[transparent:boolean[,clipleft,cliptop,clipright,clipbottom:integer]]]]]):Boolean; Note: Version 1.77 and above is required to support clip region. EscapeE only - Add the designated resource to the EscapeE page. FN must be the name of a file in a format that EscapeE can view. (PCL, PDF, TIFF, RS2 etc.) Note only the first parameter is mandated. (see also Function PROPERTIES) Defaults are
x=0,y=0,scale=1,page=1,transparent=true,clipleft=0,cliptop=0,clipright=0,clipbottom=0.
e.g. To draw a graphic at the top left hand corner of the page...
resource('TEST.PNG');
If the resource cannot be found, or the requested page does not exist in the file, the function return false. The ResourcePDF function is used to engage special processing for PDF export only. The ResourcePDF filename is only stored once in the output file and the content reused by each page as an embedded resource. e.g. In this example the 50 page PDF output file is only a little larger that the one page source.
// REDTITAN RS2 CONTROL
  resourcePDF('overlay.pdf');
  text(100,100,'Page '+paramstr(1));
  if paramstr(1)='50' then halt(1);
Function FormatFloat(s:String;n:Number):String; see FormatFloat specifiers
Procedure Font(Pointsize:Number;Fontname,Style:String); EscapeE only - engage named font e.g.
Font(12,'Arial','bold');
Procedure TEXT(X,Y:Number;S:String|L:List); EscapeE only - draw text S on page at X,Y (at 600dpi). Version 2.04 permits a list to be supplied as the third parameter. The list is displayed as a series of left justified lines.
Procedure Extent(s:string;var Ascent,Descent,Width); EscapeE only - Return text metrics for the string S. ASCENT returns the font maximum height above the baseline. DESCENT is the text maximum depth below the baseline and the WIDTH is the overall length of the string.
Function IntToStr(n:number):String; Convert N to string representation
Procedure Halt(n:number); In Windows RS2 JIT compiler, halt terminates program execution and returns the exit code N. In EscapeE HALT(1) is used to signal end of file.
Procedure Sleep(millisecs:number); Suspend processing for specified period
Procedure line(x1,y1,x2,y2:Number); EscapeE only. Draw a line from x1,y1 to x2,y2 using the the current PEN, and COLOR.
Procedure Rotate(angle: Number); EscapeE only - Specify ANGLE (0 to 360 degrees) for TEXT display.
procedure Colo(u)r(red,green,blue: number); EscapeE only. Specify color for TEXT and LINE drawing. 255 is fully saturated.
procedure BRUSH(red,green,blue: byte); EscapeE only. Specify color for filled regions
procedure Pen(Width:Number) EscapeE only. Specify pen width for LINE drawing.
Procedure Box(x,y,Dx,Dy:Number); Procedure Box(th:TableHandle); EscapeE only. Draw a filled box in the selected BRUSH color. The BOX function optionally takes a TableHandle(see TAB function). See also the FRAME and BUTTON functions.
Procedure Button(x,y,Dx,Dy:Number); Procedure Button(th:TableHandle); EscapeE only. Draw a filled button shape(lozenge) in the selected BRUSH color. The BUTTON function optionally takes a TableHandle(see TAB function). See also the FRAME and BOX functions.
Procedure Circle(x,y,r[,section=0]:Number); EscapeE only. If the section parameter is omitted or specified as 0 a complete circle of radius r is is drawn at position x,y using the current pen and colour.
section=1 draw the top right 90 degree section
section=2 bottom right
section=3 bottom left
section=4 top left
Procedure Curve(L:List); EscapeE only. Display bezier curve (see poly.rs2). L is a list of point coordinates consisting of a start point (x,y) followed groups of three coordinates.
Procedure PolyLine(L:List); EscapeE only. Display polyline linking all points specified by lists of coordinates in list L. (see poly.rs2)
Procedure Frame(x,y,Dx,Dy:Number); Procedure Frame(th:Thandle); EscapeE only. Draw a rectangle using the selected PEN and COLOR. A overload of this function takes a TABLEHANDLE (see TAB function). A filled rectangle is drawn using the box function.
Function Col_Create:CHandle; EscapeE only -The Col_Create function creates a columnn formatting resource. All "text in column" formatting procedures requires a column object handle - CHANDLE. There must be a corresponding COL_FREE call for each COL_CREATE function.
e.g.
cx:=col_create; 
for i:=1 to 30 do col_text(cx,'hello world '); 
col_compose(cx,4200,'rj'); 
col_display(cx,300,2600); 
col_free(cx);
Procedure Col_Text(cx:CHandle;s:String); EscapeE only - Add text to a "text in column" formatting object. No text is drawn by this operation. Any amount of text may be added before the object is composed and displayed. Use COL_FONT and COL_STYLE procedure to control the font face and style used by COL_TEXT.
Procedure Col_List(Handle:Number;ls:List);(Version 2) Add a list to a "text in column" object. A break is added after each list item
Procedure Col_Font(cx:CHandle;PT:Integer;Fontname:String); EscapeE only - Select the font to be used for the COL_TEXT procedure.e.g.
col_Font(cx,12,'Tahoma');
Procedure Col_Style(cx:CHandle;Style:String); EscapeE only - Select the font style to be used for the COL_TEXT procedure from BOLD and ITALIC. An empty string selects style "NORMAL" e.g.
col_Style(cx,'Bold');
Procedure Col_Compose(cx:CHandle;Width:integer;Format:String); EscapeE only - Specify a column width and column formatting option from 'LJ' 'CJ' 'RJ' or 'FILL'. The text in column is prepared for display. The column HEIGHT and LINES properties are calculated for the chosen option. The stored text is not destroyed by this procedure and it it may be repeated for the same text with different parameters.
Function Col_Display(cx:CHandle;x,y:Integer); EscapeE only - Text previously formatted using the COL_COMPOSE procedure is drawn at the specied X,Y position on the page. The stored text is not destroyed by this procedure and it it may be repeated for the same text with different parameters.
Procedure Col_Free(cx:CHandle); EscapeE only - Recover column formatting resources.
Procedure Col_Break(cx:CHandle);
Procedure Col_Blank(cx:CHandle;lines:Integer);
EscapeE only - Insert line breaks and blank lines in a column formatting object.
Function Col_Height(cx:CHandle):Integer;
Function Col_Count(cx:CHandle):Integer;
Procedure Col_Leading(cx:CHandle;L:Integer);
EscapeE only - COL_height returns the composed height of a column. Col_Count, the number of lines in a composed column. Col_leading allows the inter-line gap to be adjusted before a column is displayed.
Procedure Orient(Direction:String); EscapeE display direction - 'P'=portrait, 'L'=landscape , 'I'=Inverse or 'J'=Journal
Procedure Plex(Option:String); EscapeE only. [SIMPLEX|DUPLEX][LONG|SHORT] To specify plex and edge binding e.g.
Plex('DUPLEX LONG');
Procedure Copies(n:Number); EscapeE only. Number of copies.
Procedure Paper(Option:String;Force:Boolean); EscapeE only. Set paper type. e.g.
Paper('A4',false);
Procedure Custom(w,h:Number); EscapeE only. Set width and height for custom paper.
Procedure SetTrays(t,b:integer); EscapeE only. Set input and output paper size.
Function Fields(LS:List):Integer; In EscapeE this function will return the a list of all defined fields names. The result gives the number of fields returned
e.g.
  LX:=[];
  fields[LX];
  writeln(LX);
  

see also FIELDSET, FIELDVALUE
Function FieldValue(nam:String):String; In EscapeE this function will return the value of a mark-up or "composite" field.
e.g.
s:=FieldValue('{field1}');
In the Windows RS2 JIT compiler, this function will return an empty string. It can be used to detect the supporting platform. e.g.
if fieldvalue('{_Iname}')='' then 
begin 
  showmessage('Please open with RedTitan EscapeE',3000); 
  halt(1); 
end;

see also FIELDSET
Procedure fieldset(fieldname:string;value:string|value:List) In EscapeE this procedure will set the value of of a named field.
Function FieldBounds(Name:string;var Rect:List):Boolean; In EscapeE this function will return the bounding rectangle coordinates of the named field. i.e. LEFT, TOP, RIGHT and BOTTOM If the field does not exist the function willl return a false result. See also FIELDLeft|Top|Width|Height functions
FIELDLeft|Top|Width|Height(name:string):integer; In EscapeE these functions will return the named field position and dimension properties. If the field does not exist the functions return 0.
Procedure NewFile(name:String); EscapeE only. Start a new output file for this page. (name is currently ignored)
Function DeleteFile(fn:String):boolean;(Version 2) delete the named file
Function RenameFile(fn1,fn2:String):boolean;(Version 2) rename file fn1 to fn2
Function copyfile(fn1,fn2:String):boolean;Copy fn1 to fn2 and overwrite if required
Function OpenFile(name:string):FileHandle; Return a handle to a text file for reading. Use the handle in READLINE, READCSV and EOF functions.
e.g.
h:=openfile('test.txt'); 
while not eof(f) do 
  begin s:=readline(h); writeln(s); end;
Function Readline(var Handle:FileHandle):String; Return the next string read from the file specified by the HANDLE identifier (Created by OPENFILE). See also READCSV
Procedure ReadCSV(var Handle:Filehandle;var LX:List;[Separator:string[1]]); Return the next CSV record from the file specified by the HANDLE identifier (Created by OPENFILE) in the list specified by LX. If SEPERATOR is not specified "," is used. Each element of the list will contain a field from the CSV record.

A multi-line field is normalised to a string containing a number of lines delimited by line feed (#10) characters. i.e. CR (#13) is not stored. Use the SPLIT function to decompose multi-line fields.
Function Eof(var Handle:Filehandle):boolean; Test if any more data can be read from a file previously opened using OPENFILE. If EOF fails the handle is no longer valid and the file is closed.
Function CreateFile(Filename:String):FileHandle; Create a file Filename and return a handle that can be used for WRITELINE and CLOSEFILE procedures. CREATEFILE WRITELINE WRITELINE CLOSEFILE summarises the file create process.
Procedure Writeline(var Handle:Number;s:String); Write a string to file previously opened with CREATEFILE.
Procedure closefile(handle:Number):boolean; Close a file previously created with CREATEFILE
Function FileExists(fn:String):boolean; Returns true if the file specified by FN exists.
Function dotmatrix(fieldname:string;dbm:string;var L:list):integer; Use the specified database to convert the named field image to text. See dot matrix character recognition.
Function OCR(fieldname:string;var L:list):integer; Use Optical Character Recognition to process the graphic delimited by the named field. Text is returned in the list parameter. Function result is the number of lines of text returned in the list parameter L. A negative result indicates a configuartion error. See advanced configuration for additional input parameters.
Function Overlay_Create:Overlayhandle;
Procedure Overlay_draw(X,Y:Integer;Overlay:Overlay_Handle;Under:Boolean);
Procedure Overlay_End; Procedure Overlay_Free(Overlay:Overlay_Handle);
Escapee only. An overlay designates a number of elements (RS2 statements) that draw a part of a document page by adding to a display list maintained by EscapeE. For example(but not limited to), TEXT and LINE procedures. The overlay functions provide a way to reproduce a part of the display list offset by X and Y on the same page or later in the document by referring to a overlay handle. e.g.
  oh:=overlay_create
    text(10,10,'part of overlay');
    text(10,30,'another part of overlay');
  overlay_end;
  overlay_draw(0,300,oh,false);
  overlay_draw(0,600,oh,false);
  overlay_free(oh);
The fourth parameter controls the display order. e.g. to create a text layer underneath a PDF document define the UNDER parameter as TRUE
Function TAB(xpos,ypos:Integer;htabs:List;vspace:integer):TableHandle; Define a table position and a list of default column widths. VSPACE specifies the default row height. A number of related functions(subject to change in versions subsequent to 1.7) may be used to display table cells containing text with simple formatting.
Procedure TAB_CELL(TH:TableHandle;s:String¦l:List); Display text in cell. (Version 2) If the second paramter is of type LIST, each element of the list is displayed in adjoining cells. (See SQL_TABLE example)
Procedure TAB_ALIGN(TH:TableHandle;alopt:String); Specify horizontal text alignment. ALOPT may be (L)eft (C)enter (R)ight. The (N)one option suppresses any composition in the FORMAT and TAB_FORMAT functions
Procedure TAB_VALIGN(TH:TableHandle;alopt:String); Specify vertical text position. ALOPT may be (T)op (M)iddle (B)ottom
Procedure TAB_PAD(TH:TableHandle;padding:integer); Specify offset from edge of cell to text position.
Function TAB_NEXTROW(TH:TableHandle[;rulings:boolean=true]):Integer; Start next row (add rulings). Row height is determined by the maximum of the vertical spacing specified by the Table handle and the tallest text composed on the row.
Function TAB_HOME(TH:TableHandle):Integer; Return to the first column cell position without advancing the vertical position. Cell drawing may be repeated using the cell height determined by the maximum of the vertical spacing specified by the Table handle and the tallest text composed on the row. This function my be used to add additional text in each cell (in a different position) or add borders in particular positions. Returns current Y position.
Procedure TAB_BORDERS(TH:TableHandle;borders:string); Add borders to a cell. Border options are a combination of T B R for TOP LEFT BOTTOM RIGHT
Function TAB_FORMAT(TH:TableHandle;FormattedText:List):Integer; Add formatted text to a cell. See "format" for FormattedTextList options
Function FORMAT(AttributeList,FormattedText:List):Integer; FORMAT and TAB_FORMAT are analogues of the IDF Rich Text (RTF) container used in the dynamic composition number of text paragraphs. The overall text attributes are an ordered list of up to 13 properties as follows

Left,Top,Width,Height,Padding,BorderWidth,Rotate,LineJoin,LineEnd,BorderStyle,Borders,BorderColour,BGColor
e.g. [600, 600, 900, 1050, 0, 0, 0, "round", "round", "solid", "T,L", "Black", "#408000"]

The FormattedText list consists of "commandkey:value" pairs expressed as strings.
e.g. ["text:hello","break:","text:world"]

Command keys include
text: sequence text:hello world
font: name font:Arial
size: point size size:12
break: Argument ignored. Insert line break break:
blank: Argument ignored. Insert blank line blank:
align: Set text alignment. LJ, RJ, CJ, or FILL align:lj
bold: Engage bold font bold:
italic: Engage italic font italic:
underline: Engage text underline:
color: Engage named color color:#0000ff
Special mark up The command key "markup:[" and "markup:]" in used to introduce variable data merge parameters. These parameters are name=value pairs and are added to paragraphs by the UBERED property editor or the CSV merge wizard. UBERED uses these sequences to dynamically create RS2 scripts for variable data merge applications.
These parameters are processed by UBERED in combination with a mark-up template (DEFAULT.MUP)
Function QRCode(x,y:Integer;payload:string;module:integer;quality:string):integer; (Version 2). Render the PAYLOAD string as a 2D barcode at the defined X and Y position. MODULE defines the size of an idividual module (black square) not the overall size. The QUALITY specifies the robustness of the error correction information added and is chosen from 'H','M','L', or 'Q'. (see QRCODE documentation). RS2 QRCODE support is an alternative to the RedTitan barcode plugin. e.g.
QRCode(300,300,'http://cc2.co/tpm',12,'q');
Function SQL(filename:string):SQLHandle;

Procedure SQL_FREE(var h:SQLHandle);
(Version 2). Contact or create a new SQL database. Note: for all SQL functions the program SQLSERVER must be running. It provides all interface services to SQL. Version 2.0 SQSERVER interfaces to SQLLITE database services. The default directory for database files is controlled by the SQLSERVER environment variable. The SQL function returns a SQL HANDLE that must be released using the SQL_FREE procedure.
Function SQL_EXEC(var SQLH:SQLHandle;L:List):boolean; (Version 2). SQL_EXEC will execute an SQL statement specified by the list L. e.g. Add an entry to COMMENT field of the PICS table in the database GSTUNT2.SQLLITE
// REDTITAN RS2 CONTROL
// Note: the previous line is required

  l:=["CREATE TABLE pics"
    "(id INTEGER PRIMARY KEY AUTOINCREMENT,"
    "comments TEXT,"
    "description TEXT);"];
  db:=sql('gstunt2.sqlite');
  if not sql_tableexists(db,'pics') then sql_exec(db,l);
  lx:=['INSERT INTO PICS (comments) VALUES ("just testing");'];
  sql_exec(db,lx);
  sql_free(db);
  if paramstr(1)='2' then halt(1);
Function SQL_TABLEEXISTS(var SQLH:SQLHandle;s:string):boolean;(Version 2)Detect the presence of a the named table. See the SQL_EXEC example.
Function SQL_TABLE(HSQL:Handle;var L:List):SQLTableHandle;

Function SQL_NEXT(var SQLTH:SQLTableHandle;var SQLTable:List):Boolean;
(version 2) Create a table view using the query supplied in the list variable. The first row (if any) is returned as a list of fields. Further rows may be returned using the SQL_NEXT function with the SQL TABLE HANDLE returned by this function. Each entry is returned as a type that may be simply published by RS2 (see SQL_TYPES) with the exception of type BLOB (Binary Large OBject), which is returned as a string giving the a filename of the BLOB. i.e. using SQL_TABLE or SQL_NEXT on a table will extract any BLOB to an external file. (see SQL_BLOB) Note: the SQL TABLE HANDLE need not be explicitly freed - SQL TABLE handle resources are recovered when SQL_FREE is executed using the DATABASE handle e.g. Tabulate all entries in the PICS table (See SQL_EXEC example)

// REDTITAN RS2 CONTROL
// Note: the previous line is required

  db:=sql('gstunt2.sqlite');
  
  selection:=['select * from pics;'];
  tbl:=sql_table(db,selection);

  tx:=tab(300,400,[1200],0);
  tab_pad(tx,60);

  repeat
    tab_cell(tx,selection);
    tab_nextrow(tx);
  until not sql_next(tbl,selection);

  sql_free(db);

  halt(1);
Function SQL_COUNT(var H:SQLTableHandle):integer;(Version 2) Return the number of rows in a table
Procedure SQL_NAMES(var SQLTableH:SQLHandle;var L:List);(Version 2) List the column names in the selected table.
Procedure SQL_TYPES(var SQLTableH:SQLHandle;var L:List);(Version 2) List the column types in the selected table. In SQLLITE the type BLOB, STRING, INTEGER, and REAL are supported.
Function SQL_BLOB(var HSQL:Handle;Table,Fieldname,Filename:String):boolean;(Version 2) Store the contents of the specified filename as a BLOB within the defined FIELDNAME of the specified TABLE. (see also the WRITETIFF function) e.g.
// REDTITAN RS2 CONTROL

l:=["CREATE TABLE pics"
"(id INTEGER PRIMARY KEY AUTOINCREMENT,"
"comments TEXT,"
"pdata BLOB);"];

db:=sql('gstunt2.sqlite');

if not sql_tableexists(db,'pics') then sql_exec(db,l);

d:=sql_blob(db,'pics','pdata','signature.tif');

sql_free(db);
halt(1);

Function SQL_PATH:String;(Version 2) Return the directory folder used by SQLSERVER
Function WRITETIFF(fieldname,filename:string):String;(Version 2.0) This function is normally used by an RS/2 program executed by the EVALUATE plugin to recover the contents of a named EscapeE field as a TIFF format graphic. If the filename does not include a fully qualified path, the graphic is created in a temporary directory with a ".TIF" extension. The actual complete filepath used is returned as the function result.
Function PROPERTIES(property:integer):Integer ;(Version 2) Return properties of the current page as described below. This function is useful when adding objects of an indeterminate size to a dynamically composed page. In this context, the properties function can be called to recover the extent of the printed page. e.g. to avoid overwriting a graphic added using the RESOURCE function. The following PROPERTY values are supported.
filePages 0 number of pages in the file. If the user's pagenum parameter is negative then a result of -1 means number of pages not yet known. If pagenum = 0 then the number will be determined by reading them all if necessary
pageOrient 1 orientation of the page: P = 0, L=1, I=2, J=3
pageWidth 2 width of the page
pageHeight 3 height of the page
printedWidth 4 width of the printed area of the page
printedHeight 5 height of the printed area of the page
printedLeft 6 offset to left edge of printed area
printedTop 7 offset to top edge of printed area
paperCode 8 PCL paper type code e.g. 26 for A4
papertray 9 input tray number
paperbin 10 output bin number
pageplex 11 0 = simplex, 1 = duplex long-edge binding, 2 = duplex short-edge binding
pageside 12 0 = front, 1 = back
pagecopies 13 number of copies
printableLeft 14 offset to left edge of printable area
printableTop 15 offset to top edge of printable area
pageLines 16 number of lines per page
highestTray 17 number of the highest defined input tray