Structured Query Scripting Language x4GL API reference

sql_execute

file csqic.c
declaration
function sql_execute(i_query, def_fd, verbose, html, width, txtvar)
    define i_query	char(K_scriptbuf),	#the sql statemet(s)
	   def_fd,				#output stream
	   flags,				#various behavioural flags
	   width	integer,		#text width
	   txtvar	text			#where to store the output
returns sqlcode, integer, sql error returned by the script
purpose Implements the structured query scripting language interpreter
example none
notes All of the considerations of sql_execute2 apply with the exception of the K_preserve flag, which is ignored.

sql_execute2

file csqic.c
declaration
function sql_execute2(i_query, def_fd, verbose, html, width, txtvar)
    define i_query	text,			#the sql statemet(s)
	   def_fd,				#output stream
	   flags,				#various behavioural flags
	   width	integer,		#text width
	   vars		byte			#hash containing variables
	   txtvar	text			#where to store the output
returns sqlcode, integer, sql error returned by the script
purpose sql_execute2 offers a slightly different interface to the structured query scripting language interpreter facility than sql_execute
example none
notes
  • def_fd is any valid stream open for writing, or 0 to signify that the default output should go to txtvar. On exit the stream is left open.
  • flags is any combination of the following:
    • K_html produces a simple but effective html output
    • K_verbose flags that status information should be displayed
    • K_isbatch signals that interactive expansions (picklists and prompts) should not be allowed
    • K_errorcont has the same effect as whenever error continue
    • K_dml flags that DML/DDL statements are allowed
    • K_noconf specifies that no confirmation should be asked to the user before executing DML/DDL statements
    • K_preserve specifies that variables and sql resources should be preserved across invocations. Use sql_release to release resources at the end of the session
    constants are defined in csqll.4gh
  • When K_preserve has been used, it is important not to dispose of the vars byte variable before having called sql_release: any such action will ultimately result in a SQL resources and memory leak
  • When using K_preserve and executing multiple scripts at the same time (eg when invoking 4gwMenus - the 4glWorks ISQL Menus surrogate - scripts while within the SQSL interpreter viewer) it is important to realize that scripts might affect each others connections: altough named connections are private to each script, the default connection is not, and it is possible for a script to close a database on the default connection that another script expects to be the current database. This has furthermore implications on the second script prepared statements. In order to avoid conflicts, it is best that invocations using the K_preserve flag (eg the SQSL interpreter viewer) switch to a named connection before proceeding with anything else. By the same token, it is suggested that invocations not using the K_preserve flag (eg 4gwMenus) switch to the default connection, and for good measure, reopen the desired database
  • the behaviour of the expansion facility (and in particular the ability to use pick lists) depends on the user interface in use. See sql_explode for more information

sql_explode

file csqic.c
declaration
function sql_explode(i_query, hash, verbose, state, s)
    define i_query	char(K_scriptbuf),	#the script buffer
	   hash		text,			#variables hash
	   verbose,				#verbose flag
	   state,				#expansion state flag
	   s		smallint		#starting column
returns ts, smallint, start of unexpanded query text
te, smallint, end of unexpanded query text
txt, char(512), expanded text
tr, smallint, scan resume point
purpose Implements the expansion facility
example none
notes
  • s should initially be 1, and the value returned by tr on successive calls
  • the end of the query is marked by tr being set to NULL
  • state is at present used in conjunction with the sql_execute family of routines. If set to zero, it allows to skip actions on expansion blocks (eg because in inactive sections of the input script), if set to -1, interactive expansions (picklists and prompts) are disabled
  • the expansion facility does not allow the use of pick lists if the application is not running (or has been linked not to run) in form mode.

sql_message

file csqic.c
declaration
function sql_message(message)
    define message	integer			#sqlcode
returns str, char[80], message corresponding to the input sqlcode
purpose returns a description of the error corrisponding to the code passed as the input parameter
example none
notes none

sql_release

file csqic.c
declaration
function sql_release(vars)
    define vars	byte		#hash containing vars & resource info
returns nothing
purpose Releases resources used by sql scripts executed with the K_preserve flag in effect.
example none
notes see sql_execute2


Please address questions or comments to Marco Greco
(last updated Mon, 19 September 2016 15:35:52 BST)