Alpha Video Training
Results 1 to 5 of 5

Thread: Arguments from XML

  1. #1
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,388

    Default Arguments from XML

    Hi Everyone,

    I know this is a bit backwards, but I have a text file that contains the xml for the arguments I
    want to use for a query.
    How do I get this data into myargs for the statement ?
    Code:
    cn.execute(sqlcode,myargs)
    Here is the xml I am referring to

    Code:
    <SQLArguments>
    	<SQLArgument>
    		<Name>billto_rec_number1</Name>
    		<Data Type="N">39</Data>
    		<IsNull Type="L">0</IsNull>
    		<Usage>Input</Usage>
    	</SQLArgument>
    	<SQLArgument>
    		<Name>billto_rec_number2</Name>
    		<Data Type="N">53</Data>
    		<IsNull Type="L">0</IsNull>
    		<Usage>Input</Usage>
    	</SQLArgument>
    	<SQLArgument>
    		<Name>date_statement1</Name>
    		<Data Type="D">2019-05-14</Data>
    		<IsNull Type="L">0</IsNull>
    		<Usage>Input</Usage>
    	</SQLArgument>
    </SQLArguments>
    All help is greatly appreciated,

    Gregg

  2. #2
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,388

    Default Re: Arguments from XML

    Certainly not graceful or easy, but this seems to accomplish the task.
    Code:
    dim myargs as sql::Arguments
    dim xmlcode as c
    dim argptr[0] as p
    dim mycounter as n
    xmlcode = <<%txt%
    <SQLArguments>
    	<SQLArgument>
    		<Name>billto_rec_number1</Name>
    		<Data Type="N">39</Data>
    		<IsNull Type="L">0</IsNull>
    		<Usage>Input</Usage>
    	</SQLArgument>
    	<SQLArgument>
    		<Name>billto_rec_number2</Name>
    		<Data Type="N">53</Data>
    		<IsNull Type="L">0</IsNull>
    		<Usage>Input</Usage>
    	</SQLArgument>
    	<SQLArgument>
    		<Name>date_statement1</Name>
    		<Data Type="D">2019-05-14</Data>
    		<IsNull Type="L">0</IsNull>
    		<Usage>Input</Usage>
    	</SQLArgument>
    </SQLArguments>
    %txt%
    
    for each dataline in xmlcode
    	if "<Name>" $ dataline.value then
    		argptr[].argname = extract_string(dataline.value,"<Name>","</Name>",1,.f.,.f.,.f.)
    		mycounter = argptr.size()
    	else
    	select
    		case "</Data>" $ dataline.value
    			argptr[mycounter].argdata = extract_string(dataline.value,">","</Data>",1,.f.,.f.,.f.)
    	end select	
    	end if
    next
    'debug(1)
    for n = 1 to mycounter
    	myargs.Set(argptr[n].argname,argptr[n].argdata)
    next

  3. #3
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,388

    Default Re: Arguments from XML

    a little more elegant/practical
    Code:
    dim myargs as sql::Arguments
    dim xmlcode as c
    dim argptr[0] as p
    dim mycounter as n
    dim flname as c
    dim fileptr as p
    flname = "f:\downloads\workingArguments.txt"
    fileptr = file.open(flname,FILE_RO_SHARED)
    while .not. fileptr.eof()
    	xmlcode = xmlcode + fileptr.read_line()+crlf()
    end while	
    
    for each dataline in xmlcode
    	if "<Name>" $ dataline.value then
    		argptr[].argname = extract_string(dataline.value,"<Name>","</Name>",1,.f.,.f.,.f.)
    		mycounter = argptr.size()
    	else
    	select
    		case "</Data>" $ dataline.value
    			argptr[mycounter].argdata = extract_string(dataline.value,">","</Data>",1,.f.,.f.,.f.)
    	end select	
    	end if
    next
     
    for n = 1 to mycounter
    	myargs.Set(argptr[n].argname,argptr[n].argdata)
    next
    end

  4. #4
    Alpha Software Employee Beta Spark's Avatar
    Real Name
    Sarah Mitchell
    Join Date
    Jul 2015
    Posts
    425

    Default Re: Arguments from XML

    Quote Originally Posted by madtowng View Post
    a little more elegant/practical
    Code:
    dim myargs as sql::Arguments
    dim xmlcode as c
    dim argptr[0] as p
    dim mycounter as n
    dim flname as c
    dim fileptr as p
    flname = "f:\downloads\workingArguments.txt"
    fileptr = file.open(flname,FILE_RO_SHARED)
    while .not. fileptr.eof()
    	xmlcode = xmlcode + fileptr.read_line()+crlf()
    end while	
    
    for each dataline in xmlcode
    	if "<Name>" $ dataline.value then
    		argptr[].argname = extract_string(dataline.value,"<Name>","</Name>",1,.f.,.f.,.f.)
    		mycounter = argptr.size()
    	else
    	select
    		case "</Data>" $ dataline.value
    			argptr[mycounter].argdata = extract_string(dataline.value,">","</Data>",1,.f.,.f.,.f.)
    	end select	
    	end if
    next
     
    for n = 1 to mycounter
    	myargs.Set(argptr[n].argname,argptr[n].argdata)
    next
    end

    Hello Gregg,

    You can just assign the xml to the args.XML property:

    Code:
    dim args as SQL::Arguments
    dim xml as c =<<%xml%
    <SQLArguments>
    	<SQLArgument>
    		<Name>billto_rec_number1</Name>
    		<Data Type="N">39</Data>
    		<IsNull Type="L">0</IsNull>
    		<Usage>Input</Usage>
    	</SQLArgument>
    	<SQLArgument>
    		<Name>billto_rec_number2</Name>
    		<Data Type="N">53</Data>
    		<IsNull Type="L">0</IsNull>
    		<Usage>Input</Usage>
    	</SQLArgument>
    	<SQLArgument>
    		<Name>date_statement1</Name>
    		<Data Type="D">2019-05-14</Data>
    		<IsNull Type="L">0</IsNull>
    		<Usage>Input</Usage>
    	</SQLArgument>
    </SQLArguments>
    %xml%
    
    args.XML = xml
    
    ? args.Find("billto_rec_number2").Data
    = 53
    Happy Bike to Work Day!
    Sarah Mitchell

    Looking for answers? Try our documentation.
    If you can't find something, let us know!

  5. #5
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,388

    Default Re: Arguments from XML

    Hi Sarah,

    I knew there had to be a better way that what I created, and I learned about args.find to boot.

Similar Threads

  1. Arguments
    By njguy in forum Mobile & Browser Applications
    Replies: 3
    Last Post: 04-24-2016, 02:22 PM
  2. sql arguments
    By mvilla25 in forum Application Server Version 11 - Web/Browser Applications
    Replies: 4
    Last Post: 01-04-2013, 09:56 AM
  3. Report Editor Arguments vs Data Source Definition Arguments
    By DaveF in forum Application Server Version 11 - Web/Browser Applications
    Replies: 1
    Last Post: 10-19-2012, 03:08 PM
  4. SQL and Arguments
    By njguy in forum Application Server Version 11 - Web/Browser Applications
    Replies: 1
    Last Post: 04-30-2012, 04:48 PM
  5. Arguments in xbasic
    By Gman in forum Alpha Five Version 10 - Desktop Applications
    Replies: 2
    Last Post: 02-15-2010, 10:46 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •