PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > Default Value 0 - rephrase
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Default Value 0 - rephrase

Réponse
 
LinkBack Outils de la discussion
Vieux 19/12/2007, 17h35   #1
Pierre Gilquin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Default Value 0 - rephrase

Thanks to the people who answer me in my previous thread, I can now rephrase
my problem :

I have a table A defined by :

create table A (
id bigint(9) NOT NULL ,
col bigint(9) NOT NULL ,
PRIMARY KEY (`id`)
)

if I insert a row with command : insert into a(id,col) values (1,null);
I get the correct exception :ERROR 1048: Column 'col' cannot be null

If I use the command : insert into a(id) values (1);
the row is create with value (1,0).

It seems to me that mysql is faulty for the second case. Do you agree with
me ?
What can I do for get rid of this default value and get an exception for
every command ?

Thanks in avance

Pierre



  Réponse avec citation
Vieux 19/12/2007, 18h35   #2
lark
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Default Value 0 - rephrase

== Quote from Pierre Gilquin (inconnue@bluewin.ch)'s article
> Thanks to the people who answer me in my previous thread, I can now rephrase
> my problem :
> I have a table A defined by :
> create table A (
> id bigint(9) NOT NULL ,
> col bigint(9) NOT NULL ,
> PRIMARY KEY (`id`)
> )
> if I insert a row with command : insert into a(id,col) values (1,null);
> I get the correct exception :ERROR 1048: Column 'col' cannot be null
> If I use the command : insert into a(id) values (1);
> the row is create with value (1,0).
> It seems to me that mysql is faulty for the second case. Do you agree with
> me ?
> What can I do for get rid of this default value and get an exception for
> every command ?
> Thanks in avance
> Pierre


my suggestion is to create a trigger for this table for any insert and/or update
operations. good catch!

--
POST BY: lark with PHP News Reader ;o)
  Réponse avec citation
Vieux 19/12/2007, 20h05   #3
J.O. Aho
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Default Value 0 - rephrase

Pierre Gilquin wrote:

> create table A (
> id bigint(9) NOT NULL ,
> col bigint(9) NOT NULL ,
> PRIMARY KEY (`id`)
> )
> If I use the command : insert into a(id) values (1);
> the row is create with value (1,0).
> It seems to me that mysql is faulty for the second case. Do you agree with
> me ?


No, I can't agree with you. NULL != 0

NULL is "VOID", and ZERO is a value which is included in the INT and that
means you got a value all within the specification you gave when you created
the table.


> What can I do for get rid of this default value and get an exception for
> every command ?


Suggest you would use a function which then is used to insert the value to the
table.


--

//Aho
  Réponse avec citation
Vieux 20/12/2007, 11h44   #4
Martijn Tonies
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Default Value 0 - rephrase


> Thanks to the people who answer me in my previous thread, I can now

rephrase
> my problem :
>
> I have a table A defined by :
>
> create table A (
> id bigint(9) NOT NULL ,
> col bigint(9) NOT NULL ,
> PRIMARY KEY (`id`)
> )
>
> if I insert a row with command : insert into a(id,col) values (1,null);
> I get the correct exception :ERROR 1048: Column 'col' cannot be null
>
> If I use the command : insert into a(id) values (1);
> the row is create with value (1,0).
>
> It seems to me that mysql is faulty for the second case. Do you agree with
> me ?


So, given that you don't have a DEFAULT clause, you're expecting
an exception? This is fair and one of the long annoying things with MySQL,
it just takes the "default" for the datatype when defined as NOT NULL.

> What can I do for get rid of this default value and get an exception for
> every command ?


You can get this exception if you use a different "sql mode", one that is
more strict. I believe MySQL 5 uses the more strict mode by default.

Check the documentation on sql mode, here's the reference for 5.1:
http://dev.mysql.com/doc/refman/5.1/...sql-modes.html

to get you an idea.


--
Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle &
MS SQL Server
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com


  Réponse avec citation
Vieux 20/12/2007, 11h45   #5
Martijn Tonies
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Default Value 0 - rephrase


> > create table A (
> > id bigint(9) NOT NULL ,
> > col bigint(9) NOT NULL ,
> > PRIMARY KEY (`id`)
> > )
> > If I use the command : insert into a(id) values (1);
> > the row is create with value (1,0).
> > It seems to me that mysql is faulty for the second case. Do you agree

with
> > me ?

>
> No, I can't agree with you. NULL != 0
>
> NULL is "VOID", and ZERO is a value which is included in the INT and that
> means you got a value all within the specification you gave when you

created
> the table.


Yes, except that the OP did NOT insert a 0, but MySQL "assumed" a default
of 0 because the column is defined as "not null".


--
Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle &
MS SQL Server
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com


  Réponse avec citation
Vieux 20/12/2007, 12h09   #6
Pierre Gilquin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Default Value 0 - rephrase

Thanks for you useful suggestion.

Pierre

"Martijn Tonies" <m.tonies@upscene.removethis.com> a écrit dans le message
de news: 476a4779$0$26876$e4fe514c@dreader27.news.xs4all.nl ...
>
>> Thanks to the people who answer me in my previous thread, I can now

> rephrase
>> my problem :
>>
>> I have a table A defined by :
>>
>> create table A (
>> id bigint(9) NOT NULL ,
>> col bigint(9) NOT NULL ,
>> PRIMARY KEY (`id`)
>> )
>>
>> if I insert a row with command : insert into a(id,col) values (1,null);
>> I get the correct exception :ERROR 1048: Column 'col' cannot be null
>>
>> If I use the command : insert into a(id) values (1);
>> the row is create with value (1,0).
>>
>> It seems to me that mysql is faulty for the second case. Do you agree
>> with
>> me ?

>
> So, given that you don't have a DEFAULT clause, you're expecting
> an exception? This is fair and one of the long annoying things with MySQL,
> it just takes the "default" for the datatype when defined as NOT NULL.
>
>> What can I do for get rid of this default value and get an exception for
>> every command ?

>
> You can get this exception if you use a different "sql mode", one that is
> more strict. I believe MySQL 5 uses the more strict mode by default.
>
> Check the documentation on sql mode, here's the reference for 5.1:
> http://dev.mysql.com/doc/refman/5.1/...sql-modes.html
>
> to get you an idea.
>
>
> --
> Martijn Tonies
> Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle
> &
> MS SQL Server
> Upscene Productions
> http://www.upscene.com
> My thoughts:
> http://blog.upscene.com/martijn/
> Database development questions? Check the forum!
> http://www.databasedevelopmentforum.com
>
>



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h48.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12447 seconds with 14 queries