[Date Prev][Date Next][Subject Prev][Subject Next][ Date Index][ Subject Index]

Re: Xy as database handler--a workable idea



Reply to note from Harry Binswanger  Sat, 13 Jun 2009 09:22:33 -0400

Harry:

> You can get the contents of any field neatly, say the third
> one, by:
>
> <SV02,<VA@01,3>

Bear in mind, though, that with VA@ you have a 77-byte limit on data
length (S/G 01, in your example). Last year I wrote a routine with a
similar syntax that works around that; if you need it I'll post it
again.

> But to use Xy as an *economical* database handler, you have to
> be able to change the contents of any field. How? My new idea
> is by an inverse operation--build a new string with all the
> unchanged contents plus the changed one. E.g., to change "cc"
> above to "xxxx":
>
> <SV02,<VA@01,1>+","+<VA@01,2>+",xxxx,"+<VA@01,4>+","+<VA@01,5>>
>
> And the damn thing works!

No, it doesn't! There's a typo there. Should be "<SX02..." -- SX,
not SV. And shouldn't it be <SX01? You want to reconstruct 01, no?

Of course, even if you get it right, the same 77-byte limit applies.
Also, your example is hard-coded for cell #3; but, in practice, the
cell number will be variable. You can code for that using VA@, of
course, but, all in all, I'd say you're better off using XS for
this. Here's a commented procedure (encoded two ways); try it with
various values for S/G 03 (cell number).

XPLeNCODE v2.0
b-gin [UNTITLED]
{<}SV01,aaa,bbbb,cc,dddddd,e{>};*; data[cr|lf]
{<}SV02,,{>};*; separator[cr|lf]
{<}SX03,3{>};*; target cell number[cr|lf]
;*; Cell number must be an integer[cr|lf]
{<}SX03,{<}IS03{>}{>}
{<}IF{<}VA{021}03{>}<1{>};*; If not...[cr|lf]
;*; Show data and{032}EXit[cr|lf]
{<}LBa{>}
{<}PR@01{>}{<}EX{>}
{<}EI{>};*;[cr|lf]
;*;{032}Cell number must be greater than 0[cr|lf]
{<}IF{<}PV03{>}<1{>};*; If not...[cr|lf]
{<}GLa{>}
{<}EI{>};*; [cr|lf]
;*; We have a good cell number[cr|lf]
{<}SV04,xxxx{>};*; New data to{032}insert in target cell[cr|lf]
{<}SV05,{>};*; 05 = left$ holder[cr|lf]
{<}SV06,{>};*; 06= right$ holder[cr|lf]
;*; Loop (CountUp)[cr|lf]
{<}SX03,{<}PV03{>}-1{>}{<}CUb,03{>};*;[cr|lf]
;*;{032}Parse[cr|lf]
{<}SV06,{>}
{<}XS01,02,07,08,06{>};*;[cr|lf]
;*; If non-existent cell, leave loop[cr|lf]
{<}IF{<}IS08{>}<>{<}IS02{>}{>}
{<}SX01,{<}IS05{>}+{<}IS01{>}{>}
{<}GLa{>}
{<}EI{>};*;[cr|lf]
;*; Else build left$, swap in right$, and loop back[cr|lf]
{<}SX05,{<}IS05{>}+{<}IS07{>}+{<}IS02{>}{>}
{<}SX01,{<}IS06{>}{>}
{<}LBb{>};*;[cr|lf]
;*; End loop[cr|lf]
;*; Reconstruct data[cr|lf]
;*; If target cell is last in series, zero it out[cr|lf]
{<}IF{<}IS02{>}{238}{<}IS01{>}<0{>}
{<}SV01,{>}
{<}SV02,{>}
{<}SV06,{>}
{<}EI{>};*;[cr|lf]
;*; Last parse (if target cell is not last)[cr|lf]
{<}IF{<}VA|01{>}>0{>}
{<}SV06,{>}
{<}XS01,02,07,08,06{>}
{<}EI{>};*;[cr|lf]
;*; Rebuild left$ + new data + right$[cr|lf]
{<}SX01,{<}IS05{>}+{<}IS04{>}+{<}IS02{>}+{<}IS06{>}{>};*;[cr|lf]
;*; Show new data[cr|lf]
{<}GLa{>}[cr|lf]
-nd
XPLeNCODE

'%--_XYENCode_start--
~<SV01,aaa,bbbb,cc,dddddd,e~>',*',_data'^
~<SV02,,~>',*',_separator'^
~<SX03,3~>',*',_target_cell_number'^
',*',_Cell_number_must_be_an_integer'^
~<SX03,~<IS03~>~>
~<IF~<VA~U03~><1~>',*',_If_not...'^
',*',_Show_data_and_EXit'^
~<LBa~>
~<PR@01~>~<EX~>
~<EI~>',*','^
',*',_Cell_number_must_be_greater_than_0'^
~<IF~<PV03~><1~>',*',_If_not...'^
~<GLa~>
~<EI~>',*',_'^
',*',_We_have_a_good_cell_number'^
~<SV04,xxxx~>',*',_New_data_to_insert_in_target_cell'^
~<SV05,~>',*',_05_=_left$_holder'^
~<SV06,~>',*',_06=_right$_holder'^
',*',_Loop_(CountUp)'^
~<SX03,~<PV03~>-1~>~<CUb,03~>',*','^
',*',_Parse'^
~<SV06,~>
~<XS01,02,07,08,06~>',*','^
',*',_If_non-existent_cell,_leave_loop'^
~<IF~<IS08~><>~<IS02~>~>
~<SX01,~<IS05~>+~<IS01~>~>
~<GLa~>
~<EI~>',*','^
',*',_Else_build_left$,_swap_in_right$,_and_loop_back'^
~<SX05,~<IS05~>+~<IS07~>+~<IS02~>~>
~<SX01,~<IS06~>~>
~<LBb~>',*','^
',*',_End_loop'^
',*',_Reconstruct_data'^
',*',_If_target_cell_is_last_in_series,_zero_it_out'^
~<IF~<IS02~>~{~<IS01~><0~>
~<SV01,~>
~<SV02,~>
~<SV06,~>
~<EI~>',*','^
',*',_Last_parse_(if_target_cell_is_not_last)'^
~<IF~<VA|01~>>0~>
~<SV06,~>
~<XS01,02,07,08,06~>
~<EI~>',*','^
',*',_Rebuild_left$_+_new_data_+_right$'^
~<SX01,~<IS05~>+~<IS04~>+~<IS02~>+~<IS06~>~>',*','^
',*',_Show_new_data'^
~<GLa~>'^
'%--_XYENCode___end--

--
Carl Distefano
cld@acedsl.com