OpenVMS Source Code Demos

mysql_demo13

1000	declare string constant k_program = "mysql_demo13"
	!=========================================================================================
	! title  : mysql_demo13.bas
	! author : Neil Rieck ( https://neilrieck.net MAILTO:n.rieck@bell.net )
	!        : Waterloo, Ontario, Canada.
	! created: 2017-08-17
	! OS     : OpenVMS-8.4 (Itanium2)
	! notes  : 1) this program was derived from MYSQL_DEMO12.bas and shows how to copy string
	!	   data from "C" to "BASIC"
	!	   2) unlike MYSQL_DEMO12.bas which conconcatenates record fields onto each line
	!	   of the array, this demo places individual fields onto individual lines. It uses
	!	   a larger array but dispences with field delimitors
	! ver who when   what
	! --- --- ------ -------------------------------------------------------------------------
	!  13 NSR 170817 1. original effort
	!     NSR 171121 2. bug fixes 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,e		,&
				r,c		,&
				rows,cols,stat	,&
				max_rows	,&
				max_cols	,&
				max_elements	,&
		string		sqlMsg$		,&
				sqlCmd$		!
	!
	goto main								!
	!=======================================================================
	!	init
	!
	!	note: unless specified otherwise, declared arrays always begin
	!	with subscript zero
	!=======================================================================
	init_arrays:								!
1100	dim string a$(max_elements)						!
	return									!
	!=======================================================================
	!	main
	!=======================================================================
1200	main:
	print "-i-program: "; k_program						!
	rc = 0									!
	max_rows	= 999							! 0..999
	max_cols	= 3							! 0..3
	max_elements	= (max_rows+1) * (max_cols+1)				! compute maximum elements
	gosub	init_arrays							! allocate memory
	sqlCmd$		= "select user,password,host from user"			! return these three fields
	!
	print "-i-BASIC calling C =============================="		!
	test = NSR_CONNECTOR(	rows,						! returned rows		&
				cols,						! returned columns	&
				stat,						! returned sql status	&
				max_elements,					! pass size of array	&
				sqlCmd$,					! sql command		&
				a$(),						! data will go here	&
				sqlMsg$)					! sql message
	print "-i-now back in BASIC ============================"		!
	print "-i-status:";stat							!
	print "-i-msg   : ";sqlMsg$						!
	print "-i-rows  :";rows							!
	print "-i-cols  :";cols							!
	!
	!	Just for this demo, we will surround field data with double brackets.
	!	This is not really necessary.
	!
	print "-i-here is the dump of row data from the field array"
	e = 0									! init subscript
	for r = 0 to (rows-1)							! step thru the rows
	    for c = 0 to (cols-1)						! step thru the columns
		e = (r*cols) + c						! compute the subscript
		print ",[["		;	if c<>0				! double brackets for this demo
		print "-i-row:";r;" [["	;	if c=0				!
		print a$(e)		;					!
		print "]]"		;					!
	    next c								!
	    print								! signal end of row
	next r									!
	!
32000	fini:									!
	print "-i-exiting BASIC ================================"
	end

Back to Home
Neil Rieck
Waterloo, Ontario, Canada.