mysql INSERT always gives 0 for auto_increment field
Post new topic   Reply to topic   Printer Friendly Page     Forum IndexHelp
Author Message
Eestlane
I18N / L10N Lead Dev


Joined: Apr 06, 2005
Posts: 1406
Location: Estonia

PostPost subject: mysql INSERT always gives 0 for auto_increment field
Posted: Wed Feb 24, 2010 9:41 pm
Reply with quote

Aside from other weird problems I have with Apache 2.2.11 + PHP 5.3.0 + MySQL 5.1.36 (or 5.1.40) I have following issue.

If making insert with $db->query, i.e Dragonfly admin message:
PHP:
$db->sql_query("INSERT INTO ".$prefix."_message (mid, title, content, date, expire, active, view, mlanguage) VALUES (DEFAULT, '$title', '$content', ".time().", $expire, $active, $view, '$language')"); 

The mid will be (tried to be) valued as 0, doesn't matter if 0 exists or doesn't exist (auto_increment starts by default with 1 anyway). The table is correct however, because not giving the default values at all, works:
PHP:
$db->sql_query("INSERT INTO ".$prefix."_message (title, content, date, expire, active, view, mlanguage) VALUES ('$title', '$content', ".time().", $expire, $active, $view, '$language')");
I actually think the last one is even better, as giving default values to undefined field names is automatic anyway, however the issue is, why doesn't it work with my setup?

Anyone else using same or close-to version of apache, php and mysql? I'm using wampserver, so they're on Windows XP SP2.


Eestlane's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.0.63/5.0.67/5.2.8/9.2.1
Back to top
View user's profile Send e-mail Visit poster's website
layingback
Forum Admin


Joined: Apr 19, 2004
Posts: 953

PostPost subject: Re: mysql INSERT always gives 0 for auto_increment field
Posted: Wed Feb 24, 2010 9:52 pm
Reply with quote

I have Apache 2.2.12 PHP 5.3.0 MySQL 5.1.37 - XAMPP on Ubuntu. Close enough?

If so, what test do you want me to run?

_________________
Pro_News: The complete module for Dragonfly - now available as version 3.3

layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
2.6 - 3.6 / 1.3.42 - 2.2.12 / 5.0.92 - 5.1.37 - 5.1.54 / 4.4.49 - 5.2.17 - 5.3 / 9.2.1
Back to top
View user's profile Visit poster's website
Eestlane
I18N / L10N Lead Dev


Joined: Apr 06, 2005
Posts: 1406
Location: Estonia

PostPost subject: Re: mysql INSERT always gives 0 for auto_increment field
Posted: Wed Feb 24, 2010 10:01 pm
Reply with quote

For example just adding a message from administration->Messages->Messages. To be sure add two messages (without deleting the first one first) and see if both will be added.

Eestlane's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.0.63/5.0.67/5.2.8/9.2.1
Back to top
View user's profile Send e-mail Visit poster's website
layingback
Forum Admin


Joined: Apr 19, 2004
Posts: 953

PostPost subject: Re: mysql INSERT always gives 0 for auto_increment field
Posted: Wed Feb 24, 2010 10:12 pm
Reply with quote

Seemed Ok. There was 1 message (mid = 1) already. Both mid 2 and mid 3 added without issue.

Guess you need someone on M$ OS?

_________________
Pro_News: The complete module for Dragonfly - now available as version 3.3

layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
2.6 - 3.6 / 1.3.42 - 2.2.12 / 5.0.92 - 5.1.37 - 5.1.54 / 4.4.49 - 5.2.17 - 5.3 / 9.2.1
Back to top
View user's profile Visit poster's website
Eestlane
I18N / L10N Lead Dev


Joined: Apr 06, 2005
Posts: 1406
Location: Estonia

PostPost subject: Re: mysql INSERT always gives 0 for auto_increment field
Posted: Wed Feb 24, 2010 10:21 pm
Reply with quote

Thanks for testing.

I assume the problem is something on my end, maybe I've messed up something somehow.


Eestlane's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.0.63/5.0.67/5.2.8/9.2.1
Back to top
View user's profile Send e-mail Visit poster's website
Eestlane
I18N / L10N Lead Dev


Joined: Apr 06, 2005
Posts: 1406
Location: Estonia

PostPost subject: Re: mysql INSERT always gives 0 for auto_increment field
Posted: Wed Feb 24, 2010 11:50 pm
Reply with quote

Found the issue. If CPG_DEBUG has to be set to false in config.php.
I've not trailed down yet what exactly caused the real issue, however this was also what caused ALL my other issues (for example dragonflycms.org/Proje.../id=1103/)


Eestlane's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.0.63/5.0.67/5.2.8/9.2.1
Back to top
View user's profile Send e-mail Visit poster's website
Eestlane
I18N / L10N Lead Dev


Joined: Apr 06, 2005
Posts: 1406
Location: Estonia

PostPost subject: Re: mysql INSERT always gives 0 for auto_increment field
Posted: Wed Feb 24, 2010 11:51 pm
Reply with quote

Strip the "If" from my second sentence, I reconstructed the sentence while I wrote it.

Anyone can test if the issue will occur when setting CPG_DEBUG to true.


Eestlane's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.0.63/5.0.67/5.2.8/9.2.1
Back to top
View user's profile Send e-mail Visit poster's website
Eestlane
I18N / L10N Lead Dev


Joined: Apr 06, 2005
Posts: 1406
Location: Estonia

PostPost subject: Re: mysql INSERT always gives 0 for auto_increment field
Posted: Thu Feb 25, 2010 12:20 am
Reply with quote

Seems it was introduced with the latest includes/db/mysql.php

dragonflycms.org/cvs/h...=9.28-9.27


Eestlane's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.0.63/5.0.67/5.2.8/9.2.1
Back to top
View user's profile Send e-mail Visit poster's website
Eestlane
I18N / L10N Lead Dev


Joined: Apr 06, 2005
Posts: 1406
Location: Estonia

PostPost subject: Re: mysql INSERT always gives 0 for auto_increment field
Posted: Thu Feb 25, 2010 12:58 am
Reply with quote

You can further discuss it here:
dragonflycms.org/Proje...s/id=1112/


Eestlane's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.0.63/5.0.67/5.2.8/9.2.1
Back to top
View user's profile Send e-mail Visit poster's website
InspectorClueNo
Heavy poster


Joined: Mar 26, 2008
Posts: 215

PostPost subject: Re: mysql INSERT always gives 0 for auto_increment field
Posted: Thu Feb 25, 2010 6:32 am
Reply with quote

http://dragonflycms.org/Projects/bugs/id=1112/ wrote:
I'm not familiar with MySQL ISO standards, so why does debug mode need to be compliant with SQL-92 strict mode exactly?

- The only way to support multiple RDBMS is to stick with a standard.
- CPG_DEBUG is normally enabled in development stage or for general debugging porpoises.

So why so strict when CPG_DEBUG is enabled?
I think it should give the opportunity to get the code compliant while still keep the code working on production sites where CPG_DEBUG is disabled?

PostgreSQL will yell the error even when disabling CPG_DEBUG so this is a MySQL thing only since we all dev for MySQL.
Something that I want to point out is that PostgreSQL is just a tiny bit slower but way more scalable then MySQL.


InspectorClueNo's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
none available
Back to top
View user's profile Visit poster's website
DJ Maze
Developer


Joined: Apr 19, 2004
Posts: 5668
Location: http://tinyurl.com/5z8dmv

PostPost subject: Re: mysql INSERT always gives 0 for auto_increment field
Posted: Thu Feb 25, 2010 5:59 pm
Reply with quote

DEFAULT is the problem
Code:
VALUES (DEFAULT

DEFAULT takes the default value for the column as defined in the table field.
When a column is AUTO_INCREMENT de default should be NULL not 0.

In ISO SQL; 0, -1, -2 etc. are valid entries (MySQL bug here) So it tries to insert 0.

Either set default to NULL or set the value to NULL
PHP:
$db->sql_query("INSERT INTO ".$prefix."_message (mid, title, content, date, expire, active, view, mlanguage) VALUES (NULL, '$title', '$content', ".time().", $expire, $active, $view, '$language')");


According to the installer:
Code:
$tables['message'] = array(
	'mid' => array('Type' => 'SERIAL4', 'Null' => 0),

According to the mysqli_mngr.php:
Code:
'SERIAL4' => 'INT NOT NULL AUTO_INCREMENT'

The only real solution:
Database table should be fixed
Code:
ALTER TABLE cms_message MODIFY COLUMN mid INTEGER  NOT NULL DEFAULT NULL AUTO_INCREMENT;

So... InspectorClueNo is right CPG_DEBUG should stay on


DJ Maze's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Fedora 12 / 2.2.15 / 5.1.47 / 5.3.3 / CVS
Back to top
View user's profile Visit poster's website Yahoo Messenger
Eestlane
I18N / L10N Lead Dev


Joined: Apr 06, 2005
Posts: 1406
Location: Estonia

PostPost subject: Re: mysql INSERT always gives 0 for auto_increment field
Posted: Fri Feb 26, 2010 2:16 am
Reply with quote

This actually means editing lots of Dragonfly code.

Eestlane's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.0.63/5.0.67/5.2.8/9.2.1
Back to top
View user's profile Send e-mail Visit poster's website
DJ Maze
Developer


Joined: Apr 19, 2004
Posts: 5668
Location: http://tinyurl.com/5z8dmv

PostPost subject: Re: mysql INSERT always gives 0 for auto_increment field
Posted: Fri Feb 26, 2010 7:42 am
Reply with quote

no, this means editing the database
_________________
There are two paths, the short one and the long one.
When you choose the short path you will notice it takes longer then the long path.
So READ the FAQ and Wiki first Razz

DJ Maze's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Fedora 12 / 2.2.15 / 5.1.47 / 5.3.3 / CVS
Back to top
View user's profile Visit poster's website Yahoo Messenger
layingback
Forum Admin


Joined: Apr 19, 2004
Posts: 953

PostPost subject: Re: mysql INSERT always gives 0 for auto_increment field
Posted: Fri Feb 26, 2010 8:06 am
Reply with quote

As in updating via installer & cpg_inst.php's? As it affects several, if not all, modules. Eg. Pro_News seems to have copied News with auto_increment fields set to Null: No, Default: None.

Still a lot of code changes, even if neatly compartmentalised in install routines.

I guess my memory must be wrong on this, but I thought STRICT_TRANS_TABLES required '0' for Integer fields not NULL? Or you got cpg_inst/installer SQL errors?

_________________
Pro_News: The complete module for Dragonfly - now available as version 3.3

layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
2.6 - 3.6 / 1.3.42 - 2.2.12 / 5.0.92 - 5.1.37 - 5.1.54 / 4.4.49 - 5.2.17 - 5.3 / 9.2.1
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   Printer Friendly Page     Forum IndexHelp All times are GMT
Page 1 of 1


Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Dedicated Server & Bandwidth Sponsored by DedicatedNOW
User Info [x]

Welcome Anonymous

Nickname
Password
(Register)

Last CVS commits [x]

Languages [x]

Community [x]

Support for DragonflyCMS in a other languages:

Deutsch
Español

X-links [x]
UltraEdit Browse Happy logo Firefox MySQL PostgreSQL Valid CSS! Valid XHTML 1.0! Unicode Encoded Badge NukeBiz Resources Raven DragonflyCMS Dedicated Now InsideSupport Lampe Berger

Preview theme [x]
Each user can view the site with a different theme.
Themes marked with a * also change the forum look.


You are seeing squares or questionmarks on this page?

All content of this website is copyrighted by the Creative Commons NC-SA
The logos and trademarks used on this site are the property of their respective owners
We are not responsible for comments posted by our users, as they are the property of the poster.
Our server runs on a P3 1.2GHz with 512MB RAM with no accelerators
Support GoPHP5.org
This page generated in 1.0536 seconds with 19 DB Queries in 0.0461 seconds
Memory Usage: 3.03 MB
Interactive software released under GNU GPL, Code Credits, Privacy Policy