On Sunday 29 August 2010 7:41:37 am Kevin wrote:
> > To illustrate in Field() you
> > have a length argument that puts a length constraint at the database
> > level i.e the actual field definition (CHAR(10)). At the form level you
> > also have IS_LENGTH which is used by SQLFORM to perform basically the
> > same function.
>
> Ah, but just as you wanted to do something that nobody else in the
> web2py community has needed yet (I'm sure more will over time), it may
> be that someone else will need something you haven't thought of -- in
> this particular case, the disparity between your idea of what field
> length definitions should be used for vs the behavior of most (all?)
> SQL RDBMS.  In everything I've used, it is not an error (or even
> necessarily a bad thing) to pass a 200 character string to a CHAR(50)
> field, since the string will simply be truncated to the length of 50.

Not only is it a bad thing but it is contrary to the SQL standard. It is the 
database editorializing without feedback. For instance:

instruction_field char(34)

field_str="To defuse this bomb cut green wire, but first apply jumper across 
red 
and white wires"

While one could say sentence structure is at fault here, the point is the above 
should not be truncated without notice.

>
> So you could have a field defined as:
>
> CREATE TABLE message (
>   id INT PRIMARY KEY,
>   short_description VARCHAR(50) UNIQUE NOT NULL,
>   content TEXT NOT NULL
> )
>
> This would allow you to do simple inserts like the following and have
> them work as expected (optimize when optimization is needed):
>
> db.message.insert(short_description=text, content=text)
>

Or 

db.message.insert(short_description=text[:50], content=text)

and maintain compatibility.

-- 
Adrian Klaver
[email protected]

Reply via email to