James Bott wrote:Horizon,How Can I define autoincrement field in DBFCDX.
Define it with the type "+"
James
Thank you James. Is it possible to set a number to autoincrement field as a starting number?
James Bott wrote:Horizon,How Can I define autoincrement field in DBFCDX.
Define it with the type "+"
James
Is it possible to set a number to autoincrement field as a starting number?
James Bott wrote:Hakan,Is it possible to set a number to autoincrement field as a starting number?
I don't believe there is a command for that. You could try adding one less records than the starting number you want, then doing a table TRUNCATE command (or ZAP if you are using the ADORDD) and see if that works. I suspect it will just start at 1 again. Maybe you could delete all but the last record.
Keep in mind the things that Reinaldo mentioned previously in this thread about all the different issues with using autoincrement fields as IDs. The table can end up with new numbers in the field in several circumstances.
James
Update: Sorry, I was thinking you were asking about SQL instead of DBFCDX. I don't know the answer for DBFCDX as I just discovered there was an autoincrement fieldtype recently myself, so I have not worked with them.
DbFieldInfo( DBS_COUNTER, 1, 10) //Set autoincremt to 10
DbFieldInfo( DBS_STEP, 1, 4) //Set Step to 4
DbFieldInfo( DBS_COUNTER, 1, 10) //Set autoincremt to 10
James Bott wrote:I am guessing that sets the next number to be 10?
James
//-------------------------------------------------
//
DECLARE @num INTEGER ;
DECLARE @rv INTEGER ;
DECLARE @numrows INTEGER ;
DECLARE @c CUROSR AS SELECT [sequence], [rowversion] FROM sequences WHERE table = :table AND field = :field;
@numrows = 0 ;
WHILE @numrows=0 DO
OPEN @c;
FETCH @c;
@rv = @c.rowversion ;
@num = @c.rowversion + 1 ;
CLOSE @c;
//if rowversion has changed then someone else has updated the record.
UPDATE Sequences SET [Sequence] = @num WHERE [rowversion] = @rv;
@numrows = ::stmt.UpdateCount ;
END;
SELECT @num FROM system.iota ;
//-------------------------------------------------
oRs:Open("select ID FROM TABLE1",oCon)
wid:=oRs:Fields("ID"):Value +1
oRs:Fields("ID"):Value :=wid
try
oRs:update //if it has been changed in underlying data by others it will fail
catch
if oRs:Fields("ID"):Value <> wid
//update fail
endif
end
oRs:Open("select ID FROM TABLE1",oCon)
wid:=oRs:Fields("ID"):Value+1
UPDATE TABLE1 SET ID=widwhere ID = wid -1
oRs:Resync //in this table no one can delete records otherwise this might fail
if oRs:Fields("ID"):Value <> wid
//update fail
endif
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 10 guests