[fpc-pascal] MSSQL and ftAutoInc: FPC 2.6.5 changes the behavior of 2.6.2 but AutoInc not works yet
lacak at zoznam.sk
Fri Apr 25 07:46:23 CEST 2014
Do you have tried for ftAutoInc field simply set ReadOnly:=False; ?
P.S. there is feature request about automatic fetching of new values of
idnetity columns, but implementing it in generic way for all supported
SQLConnections is not trivial ;-)
> I'm using 2.6.5 (fixes_2_6) now but something broke between 2.6.2 and
> 2.6.5 using AutoInc fields.
> AutoInc never worked well (at least for MSSQL) and because that I have
> my own "Query"  that implements AutoInc values very well.
> I override the ApplyRecUpdate method from TSQLQuery and update the
> AutoInc field getting the value in DB using FLib.GetLastAutoIncValue
> method that, for MSSQL, I use "select scope_identity() as id" (see
> code below)
> The problem is to use Field.SetData to put a value. If the field is
> AutoInc it is ReadOnly too and I got a exception:
> But in 2.6.2 version it worked.
> I need to know the ID (identity column). So, if the behavior was
> changed between 2.6.5 and 2.6.2, then the AutoInc fields needs to
> works too, no?
> Now, how I can get the ID using AutoInc, please?
> === BEGIN CODE ===
> procedure TghSQLdbQuery.ApplyRecUpdate(UpdateKind: TUpdateKind);
> I: Integer;
> LastId: NativeInt;
> Fld: TField;
> if UpdateKind <> ukInsert then
> for I := 0 to Fields.Count -1 do
> Fld := Fields.Fields[I]
> if Fld.IsNull and
> ((Fld.DataType = ftAutoInc) or (LowerCase(Fld.FieldName) =
> 'id') and (Fld is TNumericField)) then
> La stId=FLib.GetLastAutoIncValue
> if LastId <= 0 then
> === END CODE ===
>  https://github.com/mdbs99/Greyhound
> Marcos Douglas
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
More information about the fpc-pascal