Is there a B4A standard to define column names as lowercase in SQLite (or any database used by B4A)?
I only ask this because I keep shooting myself in the foot.
Today I defined my column names as global constants and I use these constants in my code. Now I can use cCustomerNo instead of hard coding the column name as "CustomerNo" throughout my program. Not only will this reduce errors caused by a typo, but it makes for renaming the column name much easier at a later date.
Then I got a (not so) brilliant idea today. I used a global replace to remove the ".ToLowerCase" from all of my maps that store column information because now I will use the column name constant which has the correct case. This means I no longer have to look at ugly code like:
Map.Get(cCustomerNo.ToLowerCase) or Map.Put(cCustomerNo.ToLowerCase, Value)
and instead use:
Map.Get(cCustomerNo) or Map.Put(cCustomerNo, Value)
which I find a lot more readable. Then I discovered this "brilliant" idea has left me with a few less toes on my left foot.
Why you ask? Well I forgot the DBUtils code uses:
locRowMap.Put(locCursor.GetColumnName(i).ToLowerCase, locCursor.GetString2(i))
to return column values in the map. (The column names are set to lowercase in the map.)
Ok, after I realized this, I discover my left shoe don't fit as tightly as they did before (toes are missing).
My alternative are:
TIA
I only ask this because I keep shooting myself in the foot.
Today I defined my column names as global constants and I use these constants in my code. Now I can use cCustomerNo instead of hard coding the column name as "CustomerNo" throughout my program. Not only will this reduce errors caused by a typo, but it makes for renaming the column name much easier at a later date.
Then I got a (not so) brilliant idea today. I used a global replace to remove the ".ToLowerCase" from all of my maps that store column information because now I will use the column name constant which has the correct case. This means I no longer have to look at ugly code like:
Map.Get(cCustomerNo.ToLowerCase) or Map.Put(cCustomerNo.ToLowerCase, Value)
and instead use:
Map.Get(cCustomerNo) or Map.Put(cCustomerNo, Value)
which I find a lot more readable. Then I discovered this "brilliant" idea has left me with a few less toes on my left foot.
Why you ask? Well I forgot the DBUtils code uses:
locRowMap.Put(locCursor.GetColumnName(i).ToLowerCase, locCursor.GetString2(i))
to return column values in the map. (The column names are set to lowercase in the map.)
Ok, after I realized this, I discover my left shoe don't fit as tightly as they did before (toes are missing).
My alternative are:
- Put the .ToLowerCase back into each of my Map.Get/Map.Put statements and chalk it up to lessons learned.
- Write my own MapStr class that automatically executes .ToLowerCase when referring to the map key which is always a string in this case.
- Change all of my column names in the database to lowercase as well as my column name constants. Then I can do away with ".ToLowerCase" when referring to column names.
- Change DBUtils to return the case sensitive version of the column name. This may cause problems down the line if Erel updates DBUtils with new subs that expect the column names to be in lower case or if other libraries reference DBUtils and expect the column names to be returned in lower case.
TIA