Page 1 of 1

Problem with AUTO_INCREMENT field

Posted: Thu 19 Apr 2012 08:02
by Orwo
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.

Posted: Thu 19 Apr 2012 11:04
by AndreyZ
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.

Posted: Thu 19 Apr 2012 11:18
by Orwo

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;

Posted: Tue 24 Apr 2012 12:15
by AlexP
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

Re: Problem with AUTO_INCREMENT field

Posted: Wed 25 Apr 2012 18:21
by zat
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.