Meta Cache and table names with spaces
Our software adds a table at run-time to a report using TdaQueryDataView,
TdaSQL & TdaTable (taken from one of your old tech tips). This table is
different for each user that logs in and is joined to the key table in our
database which all reports must have. By joining these 2 tables together at
run-time, I can ensure that the current user only sees records that he or
she has access to.
The name of this table changes according to the name of the user. So if John
logs in, it becomes Employee_John. If Fred Blogs logs in, it (unfortunately)
becomes Employee_Fred Blogs (note the space in the name).
The table is added at run-time using the TdaSQL.AddTable method, and then
the join is created using the TdaTable.AddTableJoin method. However, if the
table name contains a space, this fails with:
TdaMetaCache.GetFields: unable to find table Employee_Fred Blogs in cache.
AddTableJoin calls CreateFieldForTable.
CreateFieldForTable calls TdaMetaDataManager.GetFields
(daMetaDataManager.pas)
gMetaDataManager.GetFields calls TdaMetaData.GetFields (daMetaData.pas)
TdaMetaData.GetFields calls TdaMetaCache.GetTableForName
In TdaMetaCache.GetTableForName, it iterates through the table names held in
the cache. I noted that Employee_Fred Blogs is stored in the cache as
"Employee_Fred Blogs" (i.e. with double quotes, presumably because it
contains a space). This causes the line:
if (CompareText(lsTableName, aTableName) = 0) then
to fail because the table name without quotes does not match the table name
with them.
I added this line, to strip out double quotes:
lsTableName := StringReplace(lsTableName, '"', '', [rfReplaceAll]);
and my software now works. Is this an oversight? Could this be corrected as
standard in the next version? Or is there another way of handling table
names with spaces?
Thanks,
J.
--
Jason Sweby
Software Development Manager,
Carval Computing Limited, Plymouth, UK
Payroll - HR - T&A - Access Control
TdaSQL & TdaTable (taken from one of your old tech tips). This table is
different for each user that logs in and is joined to the key table in our
database which all reports must have. By joining these 2 tables together at
run-time, I can ensure that the current user only sees records that he or
she has access to.
The name of this table changes according to the name of the user. So if John
logs in, it becomes Employee_John. If Fred Blogs logs in, it (unfortunately)
becomes Employee_Fred Blogs (note the space in the name).
The table is added at run-time using the TdaSQL.AddTable method, and then
the join is created using the TdaTable.AddTableJoin method. However, if the
table name contains a space, this fails with:
TdaMetaCache.GetFields: unable to find table Employee_Fred Blogs in cache.
AddTableJoin calls CreateFieldForTable.
CreateFieldForTable calls TdaMetaDataManager.GetFields
(daMetaDataManager.pas)
gMetaDataManager.GetFields calls TdaMetaData.GetFields (daMetaData.pas)
TdaMetaData.GetFields calls TdaMetaCache.GetTableForName
In TdaMetaCache.GetTableForName, it iterates through the table names held in
the cache. I noted that Employee_Fred Blogs is stored in the cache as
"Employee_Fred Blogs" (i.e. with double quotes, presumably because it
contains a space). This causes the line:
if (CompareText(lsTableName, aTableName) = 0) then
to fail because the table name without quotes does not match the table name
with them.
I added this line, to strip out double quotes:
lsTableName := StringReplace(lsTableName, '"', '', [rfReplaceAll]);
and my software now works. Is this an oversight? Could this be corrected as
standard in the next version? Or is there another way of handling table
names with spaces?
Thanks,
J.
--
Jason Sweby
Software Development Manager,
Carval Computing Limited, Plymouth, UK
Payroll - HR - T&A - Access Control
This discussion has been closed.
Comments
Thanks for the extensive description of the problem. I will research this
further and see how it can be solved. Are you using the DataDictionary? If
so, have you tried toggling the ValidateTableNames property to see if that
changes anything?
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Thanks for the swift reply. Yes, I am using the Data Dictionary (and am
adding the table to the dictionary after it is created); remember it all
works fine as long as there is no space in the table name.
I have the TppDataDictionary.ValidateTableNames property set to False for
performance reasons, there are over 300 tables in the database.
The single line I added to daMetaData.pas appears to have worked wonders.
J.