[Lazarus] SQLiteDataSet Patch

Luiz Americo Pereira Camara luizmed at oi.com.br
Thu Mar 18 21:40:50 CET 2010


Guionardo Furlan escreveu:
> Well
>
> This code:
>
> //  sqlite is a TSQLite3DataSet
>   sqlite.FieldDefs.Clear;
>   sqlite.FieldDefs.Add('id',ftAutoInc);
>   sqlite.FieldDefs.Add('name',ftString);
>   sqlite.FileName:='test.sq3';
>   sqlite.TableName:='test';
>   sqlite.CreateTable;

Try

  sqlite.PrimaryKey := 'id';
  sqlite.FieldDefs.Clear;
  sqlite.FieldDefs.Add('id',ftInteger);
  sqlite.FieldDefs.Add('name',ftString);
  sqlite.FileName:='test.sq3';
  sqlite.TableName:='test';
  sqlite.CreateTable;

Luiz

>
> produces a table with this code
>
> CREATE TABLE test (id AUTOINC_INT , name VARCHAR(255))
>
> When I browse the code, using an external application like 
> SQLiteAdministrator the ID field isn't "auto_inced" when I append a 
> new line to the table and commit.
>
> But, checking the DDL that the SQLiteAdministrator and SQLiteStudio 
> produces when I define an autoinc field, they result in:
> CREATE TABLE test (id INTEGER NOT NULL PRIMARY KEY ASC AUTOINCREMENT, 
> name VARCHAR(255))
>
> And this works perfectly. 
>
> 2010/3/17 Luiz Americo Pereira Camara <luizmed at oi.com.br 
> <mailto:luizmed at oi.com.br>>
>
>     Guionardo Furlan escreveu:
>
>         Hello, source-owners
>         I''ve made a change in the *CreateTable* method of the
>         *TCustomSqliteDataset *class to include the *AutoInc *field
>         type working ok. The current implementation don't of the type
>         ftAutoInc doesn't work.
>
>         This is the source on the file *CustomSQLiteDS.pas*
>         *
>         *
>         *Could this be updated in the sources?*
>
>
>     Hi, ftAutoInc field is a type that is incremented at
>     TSqliteDataset side so there's no need to set  in sqlite field name.
>     But why not use the field type you propose (INTEGER AUTOINC)?
>
>     1. It will not be possible to determine that's an ftAutoInc field
>     when dataset is loaded because it's recognized as INTEGER
>     2. It's already possible to get the behavior you want:
>      - Set PrimaryKey to your integer field
>      - (Optional) If you want that this field is autoincremented in
>     TSqliteDataset side set AutoIncrementKey to true
>      - The table will be created with a INTEGER PRIMARY KEY field that
>     by definition is an autoincrement field. See the sqlite.org
>     <http://sqlite.org> FAQ
>
>     Luiz
>
>
>     --
>     _______________________________________________
>     Lazarus mailing list
>     Lazarus at lists.lazarus.freepascal.org
>     <mailto:Lazarus at lists.lazarus.freepascal.org>
>     http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
>
>
> -- 
> Timeo hominem unius libri
> Cogito ergo sum - Carpe diem
>
> []s
> Guionardo Furlan
> http://guionardo.blogspot.com
> http://www.guionardofurlan.com.br
> ------------------------------------------------------------------------
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>   





More information about the Lazarus mailing list