Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Datenbanken (https://www.delphipraxis.net/15-datenbanken/)
-   -   Delphi Problem mit "NOT NULL - Feld" (https://www.delphipraxis.net/69122-problem-mit-not-null-feld.html)

Angel4585 10. Mai 2006 14:42

Datenbank: MySQL • Version: 5 • Zugriff über: ZEOS

Problem mit "NOT NULL - Feld"
 
Hallo zusammen,

Ich habe eine Tabelle mit diesem Befahle angelegt(nur ein Beispiel):

SQL-Code:
CREATE TABLE IF NOT EXISTS Tabellenname(
Feld VARCHAR(100) NOT NULL
)
wenn ich jetzt den Datensatz anlege, nichts in das Feld reinschreibe und speichere, funktioniert alles bestens => Es kommt eine Fehlermeldung.

Wenn ich jetzt allerdings etwas in das Feld reinschreibe, den Datensatz abspeichere(keine Fehlermeldung), danach den datensatz lade und NICHTS reinschreibe, bzw. das was drinsteht rausmache und speichere, kommt auch keine Fehlermeldung, obwohl ja nichtsmehr drinsteht. Ist der Wert in diesem Fall nicht NULL und müsste nicht eine Fehlermeldung kommen?

MfG :angel:

DevilsCamp 10. Mai 2006 14:46

Re: Problem mit "NOT NULL - Feld"
 
Wie genau speicherst du den Datensatz ab? Kannst du mal den SQL-Befehl hier posten?

Angel4585 10. Mai 2006 14:56

Re: Problem mit "NOT NULL - Feld"
 
garnicht mit SQL.

Ich arbeite mit den ZEOS Komponenten und mache dies einfach über das Post der Query.

mkinzler 10. Mai 2006 15:05

Re: Problem mit "NOT NULL - Feld"
 
Wenn du den Inhalt eines Edits löschtst hast du einen Leerstring und keinen NULL-Wert

Angel4585 10. Mai 2006 15:09

Re: Problem mit "NOT NULL - Feld"
 
und wie bekomme ich da einen NULL-Wert hin?

DevilsCamp 10. Mai 2006 15:10

Re: Problem mit "NOT NULL - Feld"
 
Wieso willst du da einen NULL-Wert? Den hast du doch schon per Definition ausgeschlossen...

Angel4585 10. Mai 2006 15:11

Re: Problem mit "NOT NULL - Feld"
 
na ich will ne Meldung wenn nichts in dem Feld drin steht.

Edit: Also ein Leer-String soll quasi als NULL gewertet werden

mkinzler 10. Mai 2006 15:12

Re: Problem mit "NOT NULL - Feld"
 
Dann überprüfr das doch beim Verlassen des DBEdits oder vor dem Post.

Kedariodakon 10. Mai 2006 15:46

Re: Problem mit "NOT NULL - Feld"
 
Dann erstell die tabelle damit:
SQL-Code:
Feld Varchar( 100 ) Not Null Check ( Feld <> '' )
Bye Keda

Angel4585 10. Mai 2006 18:32

Re: Problem mit "NOT NULL - Feld"
 
Zitat:

Zitat von Kedariodakon
Dann erstell die tabelle damit:
SQL-Code:
Feld Varchar( 100 ) Not Null Check ( Feld <> '' )
Bye Keda

Kann ich direkt hier ne Frage zu diesem Check stellen oder soll ich dafür en neuen Thread aufmachen?

Ich mach einfach mal

Kann ich da auch sowas machen:

SQL-Code:
CREATE TABLE IF NOT EXISTS Tabelle(
Feld1 INTEGER DEFAULT "1" CHECK(Feld1 < 20),
Feld2 INTEGER DEFAULT "1" CHECK(Feld2 < (Feld1 * 20)),
Feld3 INTEGER DEFAULT "1" CHECK(Feld3 < (Feld1 * 20)),
Feld4 INTEGER DEFAULT "1" CHECK(Feld4 < (Feld1 * 20)),
Feld5 INTEGER DEFAULT "1" CHECK(Feld5 < (Feld1 * 20))
)
oder iss das zuviel für MySQL?

Kedariodakon 10. Mai 2006 23:46

Re: Problem mit "NOT NULL - Feld"
 
hmm das weiß ich nicht, teste es doch einfach :wink:
Reponse wär dann nicht schlecht, falls mal wer ein ähnliches Problem hat...

Bye Keda

Hansa 10. Mai 2006 23:58

Re: Problem mit "NOT NULL - Feld"
 
So ungefähr geht das :

http://www.ibexpert.info/documentati...raint/738.html

Angel4585 11. Mai 2006 05:04

Re: Problem mit "NOT NULL - Feld"
 
Also ich habe jetzt mit INSERT was eingefügt was durchb das CHECK eigentlich ausgeschlossen werden sollte und es wurde trotzdem in die Tabelle geschrieben. Muss ich das anders reinschreiben oder funktioniert das vllt einfach nur nicht mit MySQL?

Hansa dein Beispiel bezieht sich ja auf Firebird aber was ist mit MySQL?

mkinzler 11. Mai 2006 05:22

Re: Problem mit "NOT NULL - Feld"
 
Ich glaube die Firma MySql hat auch ne Homepage, auf der sie ihren Systax erklären.

Angel4585 12. Mai 2006 07:11

Re: Problem mit "NOT NULL - Feld"
 
Zitat:

Zitat von Bill K. von MySQL.com
MySQL accepts CHECK constraint syntax in the CREATE TABLE statement, and gives no error. But MySQL does not store any information for the constraint, and does not enforce the constraint.

Similarly for foreign key constraints when using MyISAM tables.

IMHO, this is a bad decision on the part of the makers of MySQL. They did it so that users could import schema definitions from other RDBMS that make use of these features, without editing their DDL scripts. But it causes users to have a false impression that a given constraint has been defined in the schema.

As an alternative, if you use MySQL 5.0 you can write a trigger that changes your Field1 to NULL if someone attempts to insert a value of "". That way, the NOT NULL constraint on that column will be violated and the operation will be aborted.

CREATE TRIGGER noblank_field1 BEFORE INSERT ON Tablename
FOR EACH ROW BEGIN
IF NEW.Field1 = "" THEN
SET NEW.Field1 = NULL;
END IF;
END

(Also make a similar trigger BEFORE UPDATE.)

If you use a version of MySQL earlier than 5.0, triggers are not implemented. You would have to enforce the rule in application code.

--
Regards,
Bill K.



Alle Zeitangaben in WEZ +1. Es ist jetzt 12:24 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz