I have a client who insists on using some reserved words in their database that I’m rebuilding.
Instead of having the argument about best practice and losing their confidence I’d like to be able to add square brackets automatically around ALL entities/attributes when generating the SQL / ADO.
Is this possible?
(I note Toad will delimit entities/attribute values that have spaces so I assume it’s possible somehow).
what database do you use? Square brackets are default quotation for Microsoft SQL Server and in Toad Data Modeler is this option by default on. It is on Generator form [F9 from model] - Detail Settings tab - “Delimited Identifiers (Use Bracket)” checkbox.
I noticed bracketing option exists for SQL Server.
I’m generating for MS Access that as you know uses ADO.
My client has some ‘reserved words’ as table attributes. When generating tables, these attributes are double quoted so ADO does not throw an error.
However, those reserved words are not quoted when generating Views (in SQL) when using ADO.
An example field name is “Property” - ie. a field the client uses to describe a household etc. “Property” is an ADO reserved word so ADO throws an error.
Might we include the option “Delimited Identifiers (Use Brackets)” when generating for MS Access versions too?
My temporary solution is to edit the SQL DDL - but that’s tedious. I don’t wish to debate reserved words with my client just yet.
The existing package reads the same as your suggested edit:
function QuotedNameMA(ObjName)
{
if (ObjName.search(/\s+/) != -1)
//return "["+ObjName+"]"; // Safe copy of original return "["+ObjName+"]";
else
return ObjName;
}
I made a trivial edit, but cannot save the package since it’s held in the Toad install directory (“C:\Program…”) and Windows rejects user edits (without elevated rights to Administrator level).
Should I consider making a copy of the Package in an alternative folder and import it?
No wait...when I attempted to save the changed script "Message explorer" responded with "Package 'Generations for Microsoft Access' can't be saved".
But when I closed the edited script I was asked and confirmed to save changes to the Package - the changes were saved.
Nonetheless, that script you've identified doesn't seem to achieve what we hope - I changed it to output "XX[", saved it and ran the Generation, but that change doesn't appear in any generated output.
It’s look like Script is Saved, but package is not saved to HDD. Maybe Package can be readonly. Could you change it? Unfortunatelly package must be in install dir location. You can switch off UAC or install TDM to another location out of Program File.
My sugessted change it without if condition (It Always return ObjName with brackets):
function QuotedNameMA(ObjName)
{
return "["+ObjName+"]"; }
Hmmm, I edited/saved the package outside Toad to always return [ and ] - all Ok.
I closed/re-opened Toad and checked the script is loaded and then ran the generation for Access 2010.
However, ObjName was not returned as "[" & ObjName & "]" etc.
I tested this by changing the Generation script to "XXXX[" & ObjName etc, but that combination of "XX..." does not appear anywhere in the generated SQL.
I appreciate your efforts to resolve this since every ADO property not bracketed in SQL views will generate the same error - ouch.
I tested it on simple model with one Entity and one View. Both have attribute with name “Property”. See attachment there are in section “queries” brackets.
’ Create queries
'================
Sub CreateQueries()
Dim cmd As ADODB.Command
'=== Create query View1 ======
I’ve modified the QuotedNameMA function so it doesn’t test for spaces. I’ve confirmed it’s written to the same Package folder; but it just is not getting called. I’ve removed all previous Toad version so can’t be called from an earlier version.
I did add “XXX[” in the function return so I can track where QuotedNameMA was called, but nothing showed up. This suggests there’s something odd with where Toad is calling the package from?
When I bracket the “WaterTanks.Position” text the Append also works fine.
When I remove the “WaterTanks.Position” text the ADO Append works fine (“Position” is a reserved word)
Since I can’t get the bracketing to work in QuotedNameMA function, perhaps it could be set to use brackets for all objects - which of course your suggested changes intends?
If you have Windows with UAC, that it is not works of virtualstore. You can check if exists folder “c:\users<username>\Appdata\local\Virtual Store\Program Files”. If Contain any subfolder of it our package, than it can be problem. VirtualStore is Windows mechanisms for write to Program Files Folder. More you can find on internet.
Do you have default settings in Generator?
Toad Data Modeler Load packages only from two locations. One is for System Packages and it is located in INSTALLDIR\Packages\System and other is for User Packages( you can find exactly path in Settings-Options-Path-Advanced-Path to Advanced (need Expert Mode)).