[Lazarus] Make table with TDataset structure
M.Santhoff at web.de
Sat Jun 20 22:42:34 CEST 2015
On Sa, 2015-06-20 at 06:36 -0700, aradeonas wrote:
> No,I explained it badly. I mean working on Lazarus Data Desktop source
> didnt help to do what I want otherwise its a very good app,if I didnt go
> wrong you write the code more than 7 years ago and its clean,codes like
> this show me how to write code professionally.
> I want to do what this app done in a code but I will lost in it,as I
> said I have a connection to a sqlite database and want to make create
> sql for one of the tables.
(from my meomry, please check details yourself)
I think TDataset is not the best choice for the task. You would have to
iterate over all fields to store, create the metadata entries (field
type, length, contraint, etc.) and in the end trigger table creation.
It would be much easier to use TSQLQuery. Taht way you only have to set
the SQL string for table creation to a correct value like
'CREATE TABLE somthing(ID serial, shortname varchar(20), name
and then run it using the ExecSQL method (or similar, lok in the docs).
Afterwards you can open it using the TDataset. This is much faster if
you have your field definitions ready before starting. You could store
the SQL or make it a constant.
If you need to have a universal table creation function you can still
iterate over the fields an have a mapping between lazarus/fpc types and
the storage types for your database, e.g. string -> varchar(), integer
-> int, and so on. More works, but it boils down to simple string
Marc Santhoff <M.Santhoff at web.de>
More information about the Lazarus