[TYPO3-core] RFC #11142: DBAL: Column's default value is not properly quoted in CREATE TABLE

Xavier Perseguers typo3 at perseguers.ch
Sun Jun 21 09:16:00 CEST 2009


Hi Masi,

Martin Kutschker wrote:
> Xavier Perseguers schrieb:
>>
>> Solution:
>> ------------------------------------
>> It is clear that the only valid definition is the last one with an empty
>> default value. My patch removes the NOQUOTE attribute when default value
>> is not numeric and it results to a valid SQL:
> 
> Why don't you init like this:
> $noQuote = false;
> 
> Then you have a more natural condition (no negation):
> if (is_numeric($featureDef['value'][0])) { $noQuote = true; }

OK.

> But what happens if I have a VARCHAR with a numeric default (eg 5)? It
> will need the quotes.

Would be prettier and safer, that's true but not mandatory I guess.

> So I think the quoting should be based on the field type. No quotes for
> I,I1,I2,I3,I4,I8,F and N, possibly for L as well.

Here is the full list of available types (from code):

switch($meta) {
	case 'C': return 'VARCHAR';
	case 'X': return $this->typeX;
	case 'XL': return $this->typeXL;

	case 'C2': return 'NVARCHAR2';
	case 'X2': return 'NVARCHAR2(4000)';

	case 'B': return 'BLOB';

	case 'D':
	case 'T': return 'DATE';
	case 'L': return 'NUMBER(1)';
	case 'I1': return 'NUMBER(3)';
	case 'I2': return 'NUMBER(5)';
	case 'I':
	case 'I4': return 'NUMBER(10)';

	case 'I8': return 'NUMBER(20)';
	case 'F': return 'NUMBER';
	case 'N': return 'NUMBER';
	case 'R': return 'NUMBER(20)';
	default:
		return $meta;
}

Thus, you're right, best would be to test the field type and remove 
quotes for I, I1, I2, I4 (I3 does not exist), I8, F, N, L and R.

I make another patch for this (including noQuote stuff).

> And I fear due to the unfortunate structure of the classes also
> class.ux_t3lib_sqlparser.php has to be patched.

Well, no, it's not required but I would really like someone to 
re-synchronize both files as a few patches were applied to its friend 
class.ux_t3lib_sqlengine.php. I'll make a patch for this before I leave 
again, once last, for a week, tonight.

-- 
Xavier Perseguers
http://xavier.perseguers.ch/en

One contribution a day keeps the fork away


More information about the TYPO3-team-core mailing list