Subject copy table?
Author Gerhard Knapp
hi,
what is the best way do copy programmable a table-schema?
(for create a new table, or copy a table, p.e.)


i think with IBO is a better way as my handmade
..............................this is dirty, but works
flist:= TStringlist.create;
with dmps.q_xall do begin
close;
sql.clear;
sql.text:= 'select * from '+xtable_name;
open;
first;
//--------------------------------------
f_main.xbar.max:= dmps.q_xall.recordcount;
f_main.l_max.caption:= Inttostr(f_main.xbar.max);
xnum:= 0;
f_main.refresh;
//--------------------------------------
dmps.q_xall.GetFieldNames(flist);

sqllist.add('create table ' + new_table_name + ' (');
sqllist.add('xid integer, '); //..add a id-field
k:= dmps.q_xall.fieldcount;
for i:= 0 to k - 2 do begin
iarray[i+1].fname:= dmps.q_xall.Fields[i].FieldName;
case dmps.q_xall.fields[i].datatype of
ftWideString, ftString:
begin
iarray[i+1].fl:= inttostr(dmps.q_xall.fields[i].size);
iarray[i+1].ftyp:= 'varchar(' +
inttostr(dmps.q_xall.fields[i].size) + '),';
end;
ftinteger: iarray[i+1].ftyp:= 'integer,';
ftsmallint: iarray[i+1].ftyp:= 'integer,';
ftDatetime: iarray[i+1].ftyp:= 'date,';
end;
end;
iarray[k].fname:= dmps.q_xall.Fields[k-1].FieldName;
case dmps.q_xall.fields[k-1].datatype of
ftWideString, ftString:
begin
iarray[k].fl:= inttostr(dmps.q_xall.fields[i].size);
iarray[k].ftyp:= 'varchar(' +
inttostr(dmps.q_xall.fields[k-1].size) + '))';
end;
ftinteger: iarray[k].ftyp:= 'integer)';
ftsmallint: iarray[k].ftyp:= 'integer)';
ftDatetime: iarray[k].ftyp:= 'date)';
end;
//close;
end;
for i:= 1 to k do begin
sqllist.add(iarray[i].fname + ' ' + iarray[i].ftyp);
end;
with dmps.q_all do begin
close;
sql.clear;
for i:= 0 to sqllist.count - 1 do begin
sql.add(' ' + sqllist[i] + ' ');
end;
execsql;
close;
end;
flist.free;