Author: Mike Shkolnik
Generate the script for SELECT-statement
Answer:
I want to publish a small procedure that generate a SELECT-statement for data of
table. This code I uses in DIM: Database Information Manager
(http://www.scalabium.com/download/dbinfo.ziphttp://www.scalabium.com/download/dbinf
o.zip):
1 function GetSelectTable(Dataset: TTable): TStrings;
2 var3 i: Integer;
4 str: string;
5 begin6 Result := TStringList.Create;
7 try8 for i := 0 to DataSet.FieldCount - 1 do9 begin10 if i = 0 then11 str := 'SELECT'
12 else13 str := ',';
14 str := str + ' ' + DataSet.Fields[i].FieldName;
15 Result.Add(str);
16 end;
17 Result.Add('FROM ' + DataSet.TableName)
18 except19 Result.Free;
20 Result := nil;
21 end;
22 end;
Of course, you can add the ORDER BY-clause (just iterate by index fields)...