Andy,
Starting a new thread title related to CursorAdapter NULLS...
>Andy Davies said
>...I've recently
had some problems with adding records to ca cursors - append blank works on
the cursor side but this causes problems where the backend logic expects
null values.
There are a couple of solutions to your problem about backend database
expecting CursorAdapter to send NULLs.
1) If you are using VFP9, your CursorSchema property can include a DEFAULT
clause after each field definition, just as you can do with CREATE CURSOR.
So if the field in the backend database is Nullable, you can do:
oCA.CursorSchema=[myfield c(10) default null, myfield2 c(25) default ""] etc
This will put NULL into the field when you APPEND BLANK -- without the
DEFAULT clause, APPEND BLANK will blank the field. (The cursor field is
already NULLABLE if the backend database it relates to is nullable -- you
can check that with DISP STRU on the cursor).
This will work IF your program can work with NULLs. However, if you want to
work with blanks but send NULLs to the backend for empty fields, you need to
use the CA's ConversionFunc property (works with VFP8 or VFP9). It takes
pairs of fieldname funcname with pairs separated from other pairs by commas.
The funcname (which should NOT include parens) can be ANY function that
takes the field it is paired with as a single parameter and returns a value
that will be sent as the field's value to the backend. ANY function means
your own UDF or method call or any built-in function that takes one param.
So, in my CursorAdapter base class (caBase), I have this function:
FUNCTION EmptyToNull(tuValue)
* if value passed is empty, convert it to NULL
IF EMPTY(tuValue)
RETURN .NULL.
ELSE
RETURN tuValue
ENDIF
ENDFUNC
And in individual subclasses of caBase or in instances of caBAse where I set
up the properties programmatically, I can put an entry into ConversionFunc
like this:
ConversionFunc = "date_apprd THIS.EmptyToNull, country THIS.EmptyToNull"
The ConversionFunc is then used by CA as it creates the Insert or Update
statement for you when you TableUpdate(). Note that the fieldname should be
specified as the cursor's fieldname, not the backend database fieldname if
they are different.
David Stevenson
http://talkingfox.blogspot.com
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.20/737 - Release Date: 3/28/2007
4:23 PM
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.