Mailing List Archive



Back to the month index Back to the list index

thoth@purplefrog.com
Tue, 01 Apr 1997 11:04:17 EST


Message-Id: <199704011604.LAA20981@aviator.cis.ufl.edu>
From: thoth@purplefrog.com
Subject: Re: [mSQL] Maybe a fix for incorrect NOT_NULL messages 
Date: Tue, 01 Apr 1997 11:04:17 EST

Larry Stone <lstone@gte.net> ,in message <> ,in message <3.0.32.19691231180000.00691860@mail.g
        te.net>, wrote:

> A number of people have recently complained about getting NOT_NULL
> constraint violations on INSERT statements, when the value being set was
> in fact not null. In 2.0B4, this was identified as being due to having
> TEXT fields in the table, and someone (I wish I could find his name
> again) posted a patch to msqldb.c which fixed the problem.

  I found a patch in the archives (
http://www.nexial.nl/cgi-bin/msqlview?3+9725+%22cannot%20be%20null%22 )
that I applied and it fixed the problem for me. I believe I have
re-located it.

-- 
Bob Forsman                                   thoth@gainesville.fl.us
           http://www.gainesville.fl.us/~thoth/

------- Forwarded Message

To: msql-list@bunyip.com Subject: [mSQL] Fix for Field "foo" cannot be null Date: Wed, 12 Feb 1997 23:05:51 -0500 From: "D.J. Gregor" <dj@gregor.com> Sender: owner-msql-list@bunyip.com Precedence: bulk Reply-To: msql-list@bunyip.com Errors-To: owner-msql-list@bunyip.com

Hello everyone,

I have tracked down the problem with the error 'field "foo" cannot be null' that happens when doing INSERTs on tables with TEXT fields. The problem has to do with the handling of the size of the TEXT fields, which has different characteristics than other fields. A temporary patch is included below.

(skip this paragraph if you don't care about details) Here are the details: In other fields, the size of the field is the same as the amount of space that is required in the database, excluding nulls. So, a field defined as CHAR(16) will take up 17 bytes in the database (16 bytes + 1 for NULL). The TEXT field requires the additional size of 4 bytes (maybe 8 on some sytems?) to point to 'overflow' data somewhere else. In the checkNullFields() function in msql/msqldb.c, it uses the defined length of the field (eg, 16 bytes in the case of a field defined as TEXT(16)), instead of the size of field in the database, to increment a pointer. This causes the pointer for a TEXT(16) field to be incremented 17 bytes (16 + 1 for null), where the _actual_ size of the field in the database is 21 bytes (16 + 4 for pointer, + 1 for null). When later fields are checked for NULLity, bad data is used for the check, and the 'cannot be null' error can pop up.

Below is a patch to _temporarily_ fix this problem. Please be advised that you should save your database, apply this patch, and re-load it after this patch is applied. You might not have to do this, but I'd be safe.

- djg

--
D.J. Gregor
dj@gregor.com

-- HERE'S THE PATCH --

--- orig/msql-2.0-B4/src/msql/msqldb.c Thu Jan 30 01:15:39 1997 +++ msql-2.0-B4/src/msql/msqldb.c Wed Feb 12 22:58:51 1997 @@ -475,9 +480,10 @@ ** Notes : */ -static int checkNullFields(cacheEntry,row) +static int checkNullFields(cacheEntry,row,flist) cache_t *cacheEntry; row_t *row; + int flist[]; { REG field_t *curField; REG int offset; @@ -485,11 +491,10 @@ msqlTrace(TRACE_IN,"checkNullFields()"); data = row->data; - offset = 0; curField = cacheEntry->def; - while(curField) + for(offset = 0; curField; offset++) { - if (!*(data + offset) && (curField->flags & NOT_NULL_FLAG)) + if (!*(data + flist[offset]) && (curField->flags & NOT_NULL_FLAG)) { sprintf(errMsg,BAD_NULL_ERROR, curField->name); msqlDebug(MOD_ERR,"Field \"%s\" cannot be null\n", @@ -497,7 +502,6 @@ msqlTrace(TRACE_OUT,"checkNullFields()"); return(-1); } - offset += curField->length + 1; curField = curField->next; } msqlTrace(TRACE_OUT,"checkNullFields()"); @@ -2120,7 +2124,7 @@ msqlTrace(TRACE_OUT,"msqlServerInsert()"); return(-1); } - if (checkNullFields(cacheEntry,row) < 0) + if (checkNullFields(cacheEntry,row,flist) < 0) { msqlTrace(TRACE_OUT,"msqlServerInsert()"); return(-1);

------- End of Forwarded Message -------------------------------------------------------------------------- To remove yourself from the Mini SQL mailing list send a message containing "unsubscribe" to "unsubscribe" to msql-list-request@bunyip.com. Send a message containing "info msql-list" to majordomo@bunyip.com for info on monthly archives of the list. For more help, mail owner-msql-list@bunyip.com NOT the msql-list!