Subject | Re: [IBO] TIBOTable and field names that require quoting. |
---|---|
Author | Helen Borrie |
Post date | 2006-09-26T15:49:44Z |
At 01:12 AM 27/09/2006, you wrote:
1. For masterlinking a query to work automatically in the TDataset
architecture, the fieldnames of the primary key in the master set
must have exactly the same names as the linking foreign key fields in
the detail; otherwise you must write the WHERE clause for the detail
set yourself and supply your own valid parameter names.
2. The other half of the problem is that parameter names are
actually Delphi identifiers. For that reason, you cannot have quotes
or spaces in the identifiers.
So - even if the names of the linking keys match, you don't have a
way to use those fieldnames the way Delphi uses them for forming
parameter names - as you can see from the generated SQL.
In short, you need to provide the WHERE clause for the detail set
yourself, using for the parameter name any string that is a valid
Delphi identifier. Here's an example of what you could supply:
SELECT SCHED$.*
FROM SCHED$
WHERE SCHED$."Acc ID" = :Acc_ID
AND SCHED$."Serv ID" = :Serv_ID
ORDER BY SCHED$."Acc ID" ASC
, SCHED$."Serv ID" ASC
Provided you have the Datasource property properly set on the detail
query AND the Fieldnames of the key fields are identical, the object
will take care of assigning values to the parameters. If the
Fieldnames of the key fields are different, e.g. unquoted, or
different names, then you will need to do the assignment in the
master set's AfterScroll event.
Helen
>I've found another instance where this runs aground.OK, you seem to have two problems here.
>
>I have a table named SCHED$ which has a number of fields, but two of
>them are "Acc ID" and "Serv ID". This table has a master table
>which contributes values for these two fields so that the
>corresponding data can be located. This seems to be handled by
>adding a WHERE clause with appropriate params. But the SQL
>generated doesn't account for the quoting on the fields, so I get
>this error:
>
>ISC ERROR CODE:335544569
>
>ISC ERROR MESSAGE:
>Dynamic SQL Error
>SQL error code = -104
>Token unknown - line 3, char 42
>ID
>
>and this SQL:
>
>SELECT ALL SCHED$.*
>FROM SCHED$
>WHERE SCHED$."Acc ID" = ? /* Acc */ ID
> AND SCHED$."Serv ID" = ? /* Serv */ ID
>ORDER BY SCHED$."Acc ID" ASC
> , SCHED$."Serv ID" ASC
>
>I'm going to try to work around this, but I thought you'd like to
>know.
1. For masterlinking a query to work automatically in the TDataset
architecture, the fieldnames of the primary key in the master set
must have exactly the same names as the linking foreign key fields in
the detail; otherwise you must write the WHERE clause for the detail
set yourself and supply your own valid parameter names.
2. The other half of the problem is that parameter names are
actually Delphi identifiers. For that reason, you cannot have quotes
or spaces in the identifiers.
So - even if the names of the linking keys match, you don't have a
way to use those fieldnames the way Delphi uses them for forming
parameter names - as you can see from the generated SQL.
In short, you need to provide the WHERE clause for the detail set
yourself, using for the parameter name any string that is a valid
Delphi identifier. Here's an example of what you could supply:
SELECT SCHED$.*
FROM SCHED$
WHERE SCHED$."Acc ID" = :Acc_ID
AND SCHED$."Serv ID" = :Serv_ID
ORDER BY SCHED$."Acc ID" ASC
, SCHED$."Serv ID" ASC
Provided you have the Datasource property properly set on the detail
query AND the Fieldnames of the key fields are identical, the object
will take care of assigning values to the parameters. If the
Fieldnames of the key fields are different, e.g. unquoted, or
different names, then you will need to do the assignment in the
master set's AfterScroll event.
Helen