Subject | Re: [firebird-support] Upper case behaviour |
---|---|
Author | Eugen.Konkov@aldec.com |
Post date | 2007-12-05T11:23:57Z |
another case.
Let's suppose you support two and more objects to have same name case sensively
create table aA ( ... );
create table aa ( ... );
Both queries will create two databse tables 'aA' and 'aa'
Notice that I have not used quotes to create tables
and if you will preserve case there no conflict! (there no SQL ERROR: table 'aa' is aready exists)
now suppose that I allow such names 'aA' and 'aa'
so if I allow I MUST BE responsible while write such queries
select * from AA; MUST RESULT
SQL ERROR: table 'AA' is ambiguous
but
select * from aa; must be OK
select * from aA; must also be OK
(see algorith at the bottom)
doing such queries I am not resposible for my actions here
so I repeat.
AS I ALLOW same names in database like 'aa' and 'aA'
I MUST be responsible for that and must use quoting
select * from "aa";
select * from "aA";
Because of this is RARE case and 99% no not use such names as 'aa' and 'aA'
in database WILL BE only unique names when uppercasing them
A, B, AA, AB, BA and so on
so that WILL SAFE to leave object names case-preserve instead of UPPERCASE
that WILL SAFE also to do next:
create table myTable (...);
select * from mytable;
select * from MYTABLE;
select * from myTable;
select * from "myTable";
all of this MUST mean THE SAME!!
BUT:
select * from "mytable" must mean exact 'mytable'
select * from "MYTABLE" must mean exact 'MYTABLE'
See next algorithm to do with quotes
if (objectName.isQuoted) {
//objectName is equal "myTable"
match ( dbObject, objectName ) // matches as is without any convertions: 'myTable' == 'myTable'
}
else {
//objectName is equal to 'myTable' or 'mytable' or 'MYTABLE' all is unquoted
match ( UPPERCASE(dbObjectName), UPPERCASE(objectName) )
// you UPPERCASE database object names and names in query so
// UPPERCASE( 'myTable' ) == UPPERCASE( 'myTable' )
// UPPERCASE( 'myTable' ) == UPPERCASE( 'mytable' )
// UPPERCASE( 'myTable' ) == UPPERCASE( 'MYTABLE' )
// for speed purpose you can cache anywhere uppercased name for database object
match( dbObjectName.uppercased , UPPERCASE(objectName) )
}
I think this is VERY SAFE. If not please give well explaned example
Regards,
Eugen Konkov
[Non-text portions of this message have been removed]
Let's suppose you support two and more objects to have same name case sensively
create table aA ( ... );
create table aa ( ... );
Both queries will create two databse tables 'aA' and 'aa'
Notice that I have not used quotes to create tables
and if you will preserve case there no conflict! (there no SQL ERROR: table 'aa' is aready exists)
now suppose that I allow such names 'aA' and 'aa'
so if I allow I MUST BE responsible while write such queries
select * from AA; MUST RESULT
SQL ERROR: table 'AA' is ambiguous
but
select * from aa; must be OK
select * from aA; must also be OK
(see algorith at the bottom)
doing such queries I am not resposible for my actions here
so I repeat.
AS I ALLOW same names in database like 'aa' and 'aA'
I MUST be responsible for that and must use quoting
select * from "aa";
select * from "aA";
Because of this is RARE case and 99% no not use such names as 'aa' and 'aA'
in database WILL BE only unique names when uppercasing them
A, B, AA, AB, BA and so on
so that WILL SAFE to leave object names case-preserve instead of UPPERCASE
that WILL SAFE also to do next:
create table myTable (...);
select * from mytable;
select * from MYTABLE;
select * from myTable;
select * from "myTable";
all of this MUST mean THE SAME!!
BUT:
select * from "mytable" must mean exact 'mytable'
select * from "MYTABLE" must mean exact 'MYTABLE'
See next algorithm to do with quotes
if (objectName.isQuoted) {
//objectName is equal "myTable"
match ( dbObject, objectName ) // matches as is without any convertions: 'myTable' == 'myTable'
}
else {
//objectName is equal to 'myTable' or 'mytable' or 'MYTABLE' all is unquoted
match ( UPPERCASE(dbObjectName), UPPERCASE(objectName) )
// you UPPERCASE database object names and names in query so
// UPPERCASE( 'myTable' ) == UPPERCASE( 'myTable' )
// UPPERCASE( 'myTable' ) == UPPERCASE( 'mytable' )
// UPPERCASE( 'myTable' ) == UPPERCASE( 'MYTABLE' )
// for speed purpose you can cache anywhere uppercased name for database object
match( dbObjectName.uppercased , UPPERCASE(objectName) )
}
I think this is VERY SAFE. If not please give well explaned example
Regards,
Eugen Konkov
[Non-text portions of this message have been removed]