OpenVMS Source-Code Demos

mysql_demo12

1000	declare string constant k_program = "mysql_demo12"
	!=========================================================================================
	! title  : mysql_demo12.bas
	! author : Neil Rieck ( http://neilrieck.net MAILTO:n.rieck@sympatico.ca )
	!        : Waterloo, Ontario, Canada.
	! created: 2017-08-17
	! OS     : OpenVMS-8.4 (Itanium2)
	! notes  : 1) this program was derived from MYSQL_DEMO11.bas and shows how to copy string
	!	   data from "C" to "BASIC"
	!	   2) this C portion of this demo concatenates record fields onto each individual
	!	   line of the BASIC array which may not be the most efficient way to go
	! ver who when   why
	! --- --- ------ -------------------------------------------------------------------------
	! 12  NSR 170817 1. original effort
	!     NSR 171121 2. minor tweak in the data presentation area
	!=========================================================================================
	option type=explicit							! no kid stuff
	!
	! passing notes:
	! 1) passing "string desc"		passes the address of a VMS-style string descriptor
	! 2) passing "string dim() desc"	passes the address of an array descriptor which contains
	!					dimensions as well as the address of the stored data (a
	!					list of string descriptors)
	! 3) passing "string dim() by ref"	passes the address of the stored data (a list of string
	!					descriptors) so you need to provide array dimensions
	!
	external long function NSR_CONNECTOR(	long by ref		,	&
						long by ref		,	&
						long by ref		,	&
						long by ref		,	&
						string by desc		,	&
						string dim() by ref	,	&
						string by desc			)
	!
	declare long		rc		,&
				test		,&
				i,j		,&
				rows,cols,stat	,&
				max_rows	,&
		string		sqlMsg$		,&
				sqlCmd$		!
	!
	goto main								!
	!=======================================================================
	!	init arrays
	!	note: unless specified otherwise, declared arrays always begin
	!	with subscript zero
	!=======================================================================
1100	init_arrays:
	dim string a$(max_rows)							! assumes: 0..max_rows
	return
	!=======================================================================
	!	main
	!=======================================================================
1200	main:
	print "-i-program: "; k_program						!
	rc = 0									!
	max_rows	= 999							! 999 rows
	gosub init_arrays							! allocate some memory
	sqlCmd$		= "select user,password,host from user"			!
	!
	print "-i-BASIC calling C =============================="		!
	test = NSR_CONNECTOR(	rows,						! returned rows			&
				cols,						! returned columns		&
				stat,						! returned sql status		&
				max_rows,					! pass size of array		&
				sqlCmd$,					! sql command			&
				a$(),						! data passed back thru here	&
				sqlMsg$)					! sql message
	print "-i-now back in BASIC ============================"		!
	print "-i-status:";stat							! returned sql status
	print "-i-msg   : ";sqlMsg$						! returned sql status text
	print "-i-rows  :";rows							! returned rows
	print "-i-cols  :";cols							! returned columns
	print "-i-raw dump of row data from the array:"				!
	for i = 0 to (rows-1)							!
	    print "-i-row:";i;" ";a$(i)						!
	next i									!
	!
32000	fini:									!
	print "-i-exiting BASIC ================================"
	end

Back to OpenVMS
Back to OpenVMS Demo Index
Back to Home
Neil Rieck
Kitchener - Waterloo - Cambridge, Ontario, Canada.