Keep in mind two things:
1. The default character encoding for DataObjects is UTF-8
2. With MySQL's VARCHAR(n), n is the # of *chars* under the current
character encoding the field can contain. This is not the same as the # of
*bytes* it can contain.
VARCHAR's maximum size is 64kb bytes - 1 (probably for a NULL/EOR indicator).
Since MySQL will use 3 bytes to store each UTF-8 character, n's maximum is
actually 21,844 (under DO default encoding).
So, be wary of specifying text-related field sizes that come close to defined
field byte-width-maximums - things like "property String, :length => 64 * 1024"
won't work for this reason.
cheers,
--jordan
On Apr 15, 2011, at 5:31 AM, Jonathan Stott wrote:
> In an RDBMS at least, String typically maps to VARCHAR(n). n is the
> length of the property, which is 50 by default in DataMapper. That
> can be controlled by the :length option, the maximum length is a
> database specific limit. I think it's 64kb for MySQL, for example.
>
> Text columns map to a TEXT column type, (or MEDIUMTEXT, etc), with a
> default size of (iirc) 64kb, and potentially (again, database
> specific) storing gb. They're also lazily loaded by default in
> DataMapper, which can result in extra queries, but more efficient
> fetches for e.g. index pages.
>
> I'd definitely make the :salt, :name and :email properties String, not
> Text. Perhaps with a different :length setting than the default or
> perhaps not. Message is a matter of taste, but probably Text.
> Specifying the :length is almost always a good idea, just from a
> sanity check perspective, though in the case of the :salt field, won't
> actually save any storage.
>
> Regards
> Jon
>
> On 15 April 2011 12:58, DAZ <[email protected]> wrote:
>> Thanks for pointing this out Jon, I didn't realise there was a string
>> property. I've just been looking at the docs, but can't find what the
>> upper limit for the string type is (or what the difference between a
>> String and Text actually is).
>>
>> In this case the :salt property will always be a 2-character string.
>> It's used to add some randomness to the short-urls I'm building.
>>
>> I've also got fields of :email and :name that I think should probably
>> be of type String too.
>>
>> There's also a 'message' filed, but that could be long so Text is
>> probably better, yes?
>>
>> On a related matter, does it help adding a length argument such
>> as :length => 2 to these properties?
>>
>> cheers,
>>
>> DAZ
>>
>> On Apr 15, 10:35 am, Jonathan Stott <[email protected]> wrote:
>>> Just as a more DataMapper question, what's the purpose of this field?
>>> A Text column is intended for storing large quantities of text, up to
>>> many kb/mb. If it's just going to store a short string, a String
>>> column will be smaller and faster.
>>>
>>> Regards
>>> Jon
>>>
>>> On 15 April 2011 10:16, DAZ <[email protected]> wrote:
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>> Thanks postmodern - that works perfectly now. How come?
>>>
>>>> cheers,
>>>
>>>> DAZ
>>>
>>>> On Apr 15, 10:17 am, postmodern <[email protected]> wrote:
>>>>> Put a proc { |model,property| } around that default.
>>>
>>>>> On 04/15/2011 02:06 AM, DAZ wrote:
>>>
>>>>>> Hi,
>>>
>>>>>> I have the following property that I want to create a 2-digit random
>>>>>> string when a resource gets created:
>>>
>>>>>> property :salt, Text, :default => rand(9).to_s +
>>>>>> (1+rand(8)).to_s
>>>
>>>>>> In development on my local machine this works fine, but in production
>>>>>> (on Heroku) this gives the same value for resources created at around
>>>>>> the same time.
>>>
>>>>>> Anybody know why this might be and a possible workaround?
>>>
>>>>>> cheers,
>>>
>>>>>> DAZ
>>>
>>>>> signature.asc
>>>>> < 1KViewDownload
>>>
>>>> --
>>>> You received this message because you are subscribed to the Google Groups
>>>> "DataMapper" group.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected].
>>>> For more options, visit this group
>>>> athttp://groups.google.com/group/datamapper?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "DataMapper" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/datamapper?hl=en.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "DataMapper" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/datamapper?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.