Problem with AUTO_INCREMENT field

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Orwo
Posts: 2
Joined: Thu 19 Apr 2012 07:40

Problem with AUTO_INCREMENT field

Post by Orwo » Thu 19 Apr 2012 08:02

We've got a problem.
I make a record in MySQL (ver 5.5.22), MyDAC (7.1.6), Delphi XE2:

Code: Select all

  MyQuery.Edit;
  www:='test';
  MyQuery.Post;
I'm not using field "id_domain". Type оf id_domain is "AUTO_INCREMENT"

In the log of dbMonitor showing:

Code: Select all

INSERT INTO domains
  (id_domain, www)
VALUES
  (?, ?)
id_domain=NULL
www="www.test.ru"

and than:

Code: Select all

SELECT id_domain AS _0, ...
FROM domains
WHERE
  id_domain IS NULL
The program give an error: Refresh failed. 0 records found.

SQL code in component TMyQuery:

Code: Select all

SELECT DISTINCT domains.*,
      client.name as clientname,
      manager.fio,
      users.fio as seofio

FROM domains
	LEFT JOIN `manager` on (domains.id_manager = manager.id_manager)
	LEFT JOIN `users` on (domains.id_seomanager = users.id)
	LEFT JOIN `client` on (domains.id_client=client.id_client)

ORDER By WWW
So, what I should do for solving this problem.

AndreyZ

Post by AndreyZ » Thu 19 Apr 2012 11:04

Hello,

It seems that you are using your own SQL statements. Please try clearing the SQLInsert, SQLUpdate, SQLDelete, SQLRefresh, and SQLLock properties of the TMyQuery component, and check if the problem persists. If it does, please specify the script to create the domains table.

Orwo
Posts: 2
Joined: Thu 19 Apr 2012 07:40

Post by Orwo » Thu 19 Apr 2012 11:18

Code: Select all

CREATE TABLE IF NOT EXISTS `domains` (
  `id_domain` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `id_client` int(11) NOT NULL,
  `is_active` varchar(1) DEFAULT NULL,
  `www` varchar(50) NOT NULL,
  `sinonim` varchar(150) DEFAULT NULL,

  `user_new` varchar(12) NOT NULL,
  `date_new` datetime NOT NULL,
  `user_edit` varchar(12) DEFAULT NULL,
  `date_edit` datetime DEFAULT NULL,
  PRIMARY KEY (`id_domain`),
  KEY `id_client` (`id_client`),
  KEY `www` (`www`)
) ENGINE=MyISAM  DEFAULT CHARSET=cp1251 AUTO_INCREMENT=187 ;
SQLInsert, SQLUpdate, SQLDelete, SQLRefresh, and SQLLock were cleared already;

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Tue 24 Apr 2012 12:15

Hello,

We cannot reproduce your problem. When using MyQuery with the default settings, the INSERT script is generated correctly, and only the changed fields are included into it. Please send a small sample demonstrating the problem, including the scripts for creating all tables, that are used in the query, to alexp*devart*com

zat
Posts: 23
Joined: Tue 21 Jun 2011 13:08

Re: Problem with AUTO_INCREMENT field

Post by zat » Wed 25 Apr 2012 18:21

Orwo wrote:We've got a problem.
I make a record in MySQL (ver 5.5.22), MyDAC (7.1.6), Delphi XE2:

Code: Select all

  MyQuery.Edit;
  www:='test';
  MyQuery.Post;
I'm not using field "id_domain". Type оf id_domain is "AUTO_INCREMENT"

In the log of dbMonitor showing:

Code: Select all

INSERT INTO domains
  (id_domain, www)
VALUES
  (?, ?)
...
may be need use this code ?

Code: Select all

INSERT INTO domains
  (www)
VALUES
  ("www.xxx.com")
When use autoincrement in DB-field, this field update by the SQL-server.

Post Reply