如何通过xml来更新数据库结构!

如何通过xml来更新数据库结构!

<?xml version="1.0" encoding="GBK"?>

<SqlMain>
<property name="1" table="索引ID_Tpu_Menu3_Cyzgxz">
    create unique index ID_Tpu_Menu3_Cyzgxz on Tpu_Menu3_Cyzgxz(CyzgxzID)
  </property>

  <property name="3" table="T_CYRY_MZ">
    drop table T_CYRY_MZ
  </property>


  <property name="2" table="TPu_Menu8_Clxx">
    alter table tpu_menu8_clxx alter column dzw decimal(6,2)
  </property>
</SqlMain

procedure TFrmMain.UpDataStruct(aFileName:String);
var
  vNode,vChildNode:IXMLNode;
  iLen,i:integer;
  fSqlText,fName,fTable:string;
begin
  try 
    XMLDoc.LoadFromFile(aFileName);
    XMLDoc.Active:=True;
    vNode:=XMLDoc.ChildNodes.FindNode('SqlMain');
    iLen:=vNode.ChildNodes.Count;
    pb1.Max:=iLen*10;
    for i:=0 to iLen-1 do
    begin
      vChildNode:=vNode.ChildNodes.Get(i);
      fSqlText:=vChildNode.NodeValue;
      fName:=vChildNode.Attributes['name'];
      fTable:=vChildNode.Attributes['table'];
      DoSqlText(fSqlText,fName,fTable);
    end;
  except
    on e:Exception do
      Showmessage('XML文件读取错误,请与开发商联系!'+chr(13)+e.Message);
  end;
end;

procedure TFrmMain.DoSqlText(aSqlText,aName,aTable:string);
var
  it:Integer;
begin
  ADOExec.SQL.Clear;
  ADOExec.SQL.Add(aSqlText);
  try
    it:=StrToInt(aName);
    case it of
    1:lb1.Caption:='建立表'+aTable;
    2:lb1.Caption:='更新表'+aTable;
    3:lb1.Caption:='删除表'+aTable;
    10:
    begin
      lb1.Caption:='添加数据表'+aTable;
      ClearData(aTable);
    end;
    11:lb1.Caption:='更新数据表'+aTable;
    else
      lb1.Caption:='更新表'+aTable;
    end;
    ADOExec.ExecSQL;
    memo1.Lines.Add('信息→'+lb1.Caption+'操作成功!');
  except
    on e:Exception do
      memo1.Lines.Add('警告→'+e.Message);
  end;
  pb1.StepIt;
  pb1.Refresh;
  lb1.Refresh;
  memo1.Refresh;
end;


注明出处:http://www.blogjava.net/badboyryan/archive/2007/05/28/120510.html

你可能感兴趣的:(如何通过xml来更新数据库结构!)