function datatype(var flddef:tfielddef):string;
begin
case flddef.datatype of
ftstring: result:='text('+inttostr(flddef.size)+')';
ftsmallint:result:='smallint('+inttostr(flddef.size)+')';
ftInteger: result:='integer';
ftlargeint:result:='largeint('+inttostr(flddef.size)+')';
ftBoolean: result:='yesno('+inttostr(flddef.size)+')';
ftdatetime:result:='datetime';
ftfloat:result:='float';
ftcurrency:result:='currency';
else
result:='text('+inttostr(flddef.size)+')';
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
session.GetAliasNames(combobox1.items);
bitbtn1.Enabled :=false;
bitbtn2.enabled:=false;
bitbtn3.enabled:=false;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
session.GetTableNames(combobox1.items[combobox1.itemindex],'*.db',false,false,listbox1.items);
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
i:integer;
tablelist:tstringlist;
str:string;
flddef:tfielddef;
begin
table1.Databasename :=combobox1.items[combobox1.itemindex];
table1.TableName:=listbox1.items[listbox1.itemindex];
adotable1.tablename:=table1.tablename;
memo1.Lines.Clear;
tablelist:=tstringlist.create;
adoconnection1.GetTableNames(tablelist);
if tablelist.IndexOf(adotable1.tablename)<0 then
memo1.lines.add('create table '+adotable1.tablename +'(')
else
memo1.lines.add('create table '+adotable1.tablename +'new(');
table1.fielddefs.Update;
for i:=0 to table1.fielddefs.Count -1 do
begin
flddef:=table1.fielddefs;
str:=' '+table1.fielddefs.Name +' '+datatype(flddef);
if i=table1.fielddefs.count-1 then
str:=str+');'
else
str:=str+',';
memo1.Lines.Add(str);
end;
bitbtn2.Enabled :=true;
bitbtn3.enabled:=true;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
adocommand1.CommandText :=memo1.Text;
adocommand1.Execute;
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
var
i:integer;
begin
table1.Open;
adotable1.Open;
try
while not table1.eof do
begin
adotable1.Insert;
for i:=0 to table1.FieldDefs.count-1 do
begin
with table1.fields do
adotable1.FieldByName(table1.FieldDefs.Name ).value:=value;
adotable1.post;
table1.Next;
end;
end;
finally
table1.close;
adotable1.close;
end;
end;
procedure TForm1.ListBox1Click(Sender: TObject);
begin
bitbtn1.Enabled :=true;
end;
end.