The idea was to distinguish between
db.table.insert(field=None) # None
and
db.table.insert(field=[]) # "||"
The latter comes from the fact that [1,2,3] gets serialized as "|1|2|3|".
So we can search for "|2|" using string matching.
You may be able to fix this using a custom validator. I need to think about
this. Can I see the model?
Massimo
On Wednesday, 25 September 2013 11:11:47 UTC-5, REM wrote:
>
> Thanks for your response. I appreciate it!
>
> This is part of a legacy DB. I am moving my company from using PHP on the
> web to web2py and I would like to avoid doing a lot of re-hacking on the
> perl program which does all of the heavy lifting (or hacking on the
> millions of records already in the DB). I've always proceeded from the (to
> me, logical) standpoint that any db field in my dbases will either contain
> some sort of usable data value or NULL and, so far I've never encountered
> any reason to act otherwise.
>
> In any case, I don't presume to know everything about dbases, and I
> certainly don't know what myriad web2py design decisions had to be juggled
> to arrive at using '||' instead of NULL in these cases. It just seems
> unnecessary to insert '||' when we already have NULL - which is more to the
> point.
>
> I reckon I'll just hack around it later in perl.
>
> Again, sincere thanks!!
>
> And an extra 57 space dollars for your kind assistance :)
>
>
>
>
> On Wednesday, September 25, 2013 10:20:27 AM UTC-4, Massimo Di Pierro
> wrote:
>>
>> There is a function in dal.py
>>
>> def bar_encode(items):
>> return '|%s|' % '|'.join(bar_escape(item) for item in items if
>> str(item).strip())
>>
>> I guess one could override it but it may break something in web2py. Why?
>>
>>
>>
>> On Tuesday, 24 September 2013 23:51:27 UTC-5, REM wrote:
>>>
>>> I am inserting data into my trusty mysql db using SQLFORM. One of the
>>> form elements is a drop-down list of states. The behavior I wish to happen
>>> is to either insert a |normal|list|of|states| or, if nothing is selected,
>>> NULL. However, when nothing is selected, it is inserting ||, and I can't
>>> seem to do anything to change that. How can I get the NULL behavior I want?
>>>
>>> Here's the relevant field definition:
>>>
>>> Field('states_active', 'list:string', length=150, default='',
>>> required=False, notnull=False, label='Active States',
>>> requires=IS_IN_SET([('AL', 'Alabama'), ('AK', 'Alaska'),
>>> ('AZ', 'Arizona'), ('AR', 'Arkansas'), ('CA', 'California'), ('CO',
>>> 'Colorado'), ('CT', 'Connecticut'), ('DE', 'Delaware'), ('FL', 'Florida'),
>>> ('GA', 'Georgia'), ('HI', 'Hawaii'), ('ID', 'Idaho'), ('IL', 'Illinois'),
>>> ('IN', 'Indiana'), ('IA', 'Iowa'), ('KS', 'Kansas'), ('KY', 'Kentucky'),
>>> ('LA', 'Louisiana'), ('ME', 'Maine'), ('MD', 'Maryland'), ('MA',
>>> 'Massachusetts'), ('MI', 'Michigan'), ('MN', 'Minnesota'), ('MS',
>>> 'Mississippi'), ('MO', 'Missouri'), ('MT', 'Montana'), ('NE', 'Nebraska'),
>>> ('NV', 'Nevada'), ('NH', 'New Hampshire'), ('NJ', 'New Jersey'), ('NM',
>>> 'New Mexico'), ('NY', 'New York'), ('NC', 'North Carolina'), ('ND', 'North
>>> Dakota'), ('OH', 'Ohio'), ('OK', 'Oklahoma'), ('OR', 'Oregon'), ('PA',
>>> 'Pennsylvania'), ('RI', 'Rhode Island'), ('SC', 'South Carolina'), ('SD',
>>> 'South Dakota'), ('TN', 'Tennessee'), ('TX', 'Texas'), ('UT', 'Utah'),
>>> ('VT', 'Vermont'), ('VA', 'Virginia'), ('WA', 'Washington'), ('WV', 'West
>>> Virginia'), ('WI', 'Wisconsin'), ('WY', 'Wyoming'), ('DC', 'Washington
>>> DC')], multiple=True, zero='SELECT ACTIVE STATES')
>>> ),
>>>
>>> From reading a somewhat-related post on NULL and SQLFORM, I thought I
>>> could get what I want with the advised default='', but it behaves just as
>>> it did when I had set default=None. I tried wrapping the IS_IN_SET() within
>>> IS_EMPTY_OR() and that made no difference also.
>>>
>>>
>>> 1oo space dollars for an answer to preserve the remainder of my hair!!
>>>
>>>
>>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.