Forums

Unfortunately no one can be told what FluxBB is - you have to see it for yourself.

You are not logged in.

#1 2009-06-28 22:24:57

artoodetoo
Member
From: Far-Far-Away
Registered: 2008-05-11
Posts: 227

Length of varchar fields

FluxBB 1.4, MySQL

I don't understand why the real length of varchar fields in database is significantly greater then program limits.
May be in the past (non-unicode) versions of engine and db it was sensible. But not now!

Let's the test: create table with utf-8 string field and then do some measurement

CREATE TABLE `test` (
  `id` int(10) NOT NULL auto_increment,
  `username` varchar(25) NOT NULL default '',
  `note` text NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


INSERT INTO `test`(username) VALUES ('(ффффффффффффффффффффффффф)');

I've try to insert too long username to check real limit.
There is a string constant with 25 russian 2-byte characters and 2 1-byte ASCII characters. Or 52 bytes.
MySql tuncates strings to fit field. So, result must be 25 utf-8 character length.

SELECT username, length( username ) 
FROM `test`

"(фффффффффффффффффффффффф", 49
That's right! It is 49 byte length or 25 (unicode) character length.

Now look into fluxbb register.php code:

if (pun_strlen($username) > 25)
    message($lang_common['Bad request']);

It limits username to 25 utf-8 characters. But why everywhere in
users.username, online.ident, posts.poster …
every field is 200 character length. For what?

The same thing is topics.subject field. It is 255 chars in table and 70 chars program limit.
We can easily decrease field length in install.php and will have no problem, IMHO.

Last edited by artoodetoo (2009-06-28 22:27:22)


I'm not a fan of FluxBB way anymore.

Offline

#2 2009-06-28 23:37:07

Dave
Guest

Re: Length of varchar fields

There's nothing to be gained by changing the length of the varchar definitions.  By design varchar columns will only consume as much space as is required.  Even if a column is defined as 255 if you only insert 10 characters that's all the space that will be consumed.

#3 2009-06-29 03:52:36

Smartys
Former Developer
Registered: 2008-04-27
Posts: 3,139
Website

Re: Length of varchar fields

artoodetoo: You're exactly right. A lot of the current lengths had to do with previous, non UTF-8 limits. However, as Dave pointed out, no extra space is being taken up. It's something to think about for 2.0, but not something that's worth worrying about for 1.4 (since it would involve quite a few changes for no tangible benefit)

Offline

Board footer

Powered by FluxBB