1 (edited by jihem 2017-09-24 19:50:53)

Topic: [another way to do] MSXML2.DSOControl, error 80020009

Hi,

I use MSXML2.DSOControl to access data stored in a XML file. Everything works well as far as I don't pass an ADODB.Recorset as parameter to a recursive procedure... If I comment the line 22 all the records are read.

If I remove the comment and I let the program explore the sublevels, it crashs at the end of the first sublevel on the adoRS.MoveNext. The reference to adoRS is lost (even if it was working previously on the test adoRS.EOF).

You can download the sample project : http://codyssea.com/downloads/007.zip.

Any help is welcome, I have no hair left... and can't stop scratching my head.

Regards,
jihem


procedure Dump(iLvl:integer;var adoRS:Variant);
var
  i:integer;
  v:Variant;
begin
  while not adoRS.EOF do
  begin
    for i:=0 to adoRS.Fields.Count-1 do
    begin
      if adoRS.Fields(i).Name<>'$Text' then
      begin
        if adoRS.Fields(i).Type=136 then
        begin
          // Dump(iLvl+1,adoRS.Fields(i).Value); // <-- line #22 ; crash if uncommented
        end
        else // =12
        begin
          log(IntToStr(iLvl)+': adoRS.Fields('+IntToStr(i)+') : '+adoRS.Fields(i).Name+' => '+adoRS.Fields(i).Value);
        end;
      end;
    end;
    adoRS.MoveNext;
  end;
end;
while(! success=retry());
https://jihem.itch.io

Re: [another way to do] MSXML2.DSOControl, error 80020009

Hello.


Unfrotunately I can't find the reason of error, but if you run this procedure twice, it's works, strangely )

try this

procedure Dump(adoRS:Variant);
var
  i:integer;
  v:Variant;
begin
  while not adoRS.EOF do
  begin
    for i:=0 to adoRS.Fields.Count-1 do
    begin
      if adoRS.Fields(i).Name<>'$Text' then
      begin
        if adoRS.Fields(i).Type=136 then
        begin
          Dump(adoRS.Fields(i).Value); // crash if uncommented
        end
        else // =12
        begin
          log(': adoRS.Fields('+IntToStr(i)+') : '+adoRS.Fields(i).Name+' => '+adoRS.Fields(i).Value);
        end;
      end;
    end;
    adoRS.MoveNext;
  end;
end;


procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
var
  adoCN,
  adoRS:Variant;
begin

  adoCN:=CreateOleObject('ADODB.Connection');
  adoRS:=CreateOleObject('ADODB.Recordset');
  adoCN.Open('Provider=MSDAOSP; Data Source=MSXML2.DSOControl');
  adoRS.Open(ExtractFilePath(Application.ExeName)+'catalog.xml', adoCN);

  try Dump(adoRS); except end;
  Form1.Memo1.Clear;
  Dump(adoRS);
end;
Dmitry.

Re: [another way to do] MSXML2.DSOControl, error 80020009

DriveSoft wrote:

Unfrotunately I can't find the reason of error, but if you run this procedure twice, it's works, strangely )

Hi,
It wasn't the answer I was waiting for... I expected an update which solves this.
Thanks for your help. I will do things twice.
Regards,
jihem

while(! success=retry());
https://jihem.itch.io

Re: [another way to do] MSXML2.DSOControl, error 80020009

Hi,

If You modify catalog.xml to two-cascade xml, sript works.
But sorting fields in cascade is probably not correct.

<catalog>
   <book>
      <author>Dorothy Hoskins</author>
      <title>XML and InDesign</title>
      <genre>Computer</genre>
      <ISBN>144934416X</ISBN>
      <website>WEBLINK1</website>
   </book>
   <book>
      <author>Tad Williams</author>
      <title>The War of the Flowers</title>
      <genre>Fantasy</genre>
      <ISBN>0756401356</ISBN>
      <website>WEBLINK2</website>
   </book>
</catalog>

Re: [another way to do] MSXML2.DSOControl, error 80020009

Hi,
Thanks for your help.
The provided project and XML file is only a sample to show the bug.
In my app, I download a file (and I have no way to change it). It's more complex : Open Street Map format. You can have a look on the current state of my project : http://codyssea.com/index.php/2017/09/16/maposm-wip.
Regards,
jihem

while(! success=retry());
https://jihem.itch.io

Re: [another way to do] MSXML2.DSOControl, error 80020009

Hi,

Bjarke Viksoe wrote an OLE DB Provider allowing you to query XML documents with SQL : https://www.viksoe.dk/code/xmloledb.htm.
I ended with something like the code below...
I thank you folks for your remarks.
Regards,
jihem

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
var
  adoConn,
  adoRS:Variant;
  i:integer;
begin
  adoConn:=CreateOleObject('ADODB.Connection');
  adoConn.Open('Provider=XmlOleDb.XML;Location='+ExtractFilePath(Application.ExeName)+'\catalog.xml');
  adoConn.CursorLocation:= 3; //adUseClient;
  adoRS:=adoConn.Execute('SELECT * FROM book,info');
  while (not adoRS.EOF) do
  begin
    for i:=0 to adoRS.Fields.Count-1 do
    begin
      log('adoRS.Fields('+IntToStr(i)+')='+adoRS.Fields(i).Name+' = '+adoRS.Fields(i).Value);
    end;
    adoRS.MoveNext();
  end;
  adoRS.Close();
  adoConn.Close();
end;
while(! success=retry());
https://jihem.itch.io

Re: [another way to do] MSXML2.DSOControl, error 80020009

Thank you for the example!

Dmitry.