[solved] MySQL AUTO_INCREMENT

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
cacofony
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 06.12.2006, 15:24
Location: Perth - Western Australia
Contact:

[solved] MySQL AUTO_INCREMENT

Post by cacofony »

Sorry if this has been asked but I search high and low and found nothing for ZeosLib 7.2

In past versions this would work for an AutoInc field, now it returns NULL and you need to call a Refresh to show the new ID's

TZQuery.Insert;
// set your fields
TZQuery.Post;
ID := TZQuery.FieldByName('myid').AsInteger;
miab3
Zeos Test Team
Zeos Test Team
Posts: 1310
Joined: 11.05.2012, 12:32
Location: Poland

Re: MySQL AUTO_INCREMENT

Post by miab3 »

For me, it works for MySQL 5.5.35:

Code: Select all

select * from tautoinc

procedure TForm1.Button8Click(Sender: TObject);
begin
ZQuery2.Insert;
ZQuery2.FieldByName('name1').AsString:='abc'+IntToStr(random(10000));
ZQuery2.Post;
Edit2.Text := IntToStr(ZQuery2.FieldByName('id1').AsInteger);
end;

CREATE TABLE tautoinc (
  id1   Integer(11) NOT NULL AUTO_INCREMENT,
  name1 NVarChar(20) COLLATE utf8_general_ci, 
  PRIMARY KEY (
      id1
  )
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE UNIQUE INDEX UK_master_autoinc 
 ON tautoinc(name1);
and ZEOS 7.2 (r3130):
http://svn.code.sf.net/p/zeoslib/code-0 ... sting-7.2/

Michal
cacofony
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 06.12.2006, 15:24
Location: Perth - Western Australia
Contact:

Re: MySQL AUTO_INCREMENT

Post by cacofony »

Ok, well I probably should of done a simple test like you did.

It now works but I still think an issue exists.

If you change your ID to UNSIGNED

ALTER TABLE `tautoinc`
CHANGE COLUMN `id1` `id1` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT FIRST;

It will no longer work.

I actually did not use UNSIGNED on purpose just many old tables designed in the old MySQL administrator where created like this. However I looked to see if it was a good or bad thing to do, below from mySQL website.

Use the UNSIGNED attribute if possible to allow a greater range. For example, if you use TINYINT, the maximum permissible sequence number is 127. For TINYINT UNSIGNED, the maximum is 255.

I will see if I can find a fix but some pointers would be great as I have really delved in to the depths of ZeosDBO.

I also can provide XE6 update s for 7.2 (3130) if needed?
cacofony
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 06.12.2006, 15:24
Location: Perth - Western Australia
Contact:

Re: MySQL AUTO_INCREMENT

Post by cacofony »

stLongWord can be autoinc and will be if UNSIGNED integer. (MySQL 5.6) Maybe it is different in other versions.

src\dbc\ZDbcMySqlResultSet.pas

Code: Select all

constructor TZMySQLCachedResolver.Create(PlainDriver: IZMySQLPlainDriver;
  Handle: PZMySQLConnect; Statement: IZMysqlStatement; Metadata: IZResultSetMetadata);

....

    if Metadata.IsAutoIncrement(I) and
      (Metadata.GetColumnType(I) in [stByte, stSmall, stInteger, stLong, stLongWord]) then
    begin
      FAutoColumnIndex := I;
      Break;
    end;
cacofony
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 06.12.2006, 15:24
Location: Perth - Western Australia
Contact:

Re: MySQL AUTO_INCREMENT

Post by cacofony »

Can confirm this is fixed in latest SVN. Nice work EgonHugeist
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Re: MySQL AUTO_INCREMENT

Post by EgonHugeist »

:chef: Thanx for your feedback
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
Post Reply