Subject | RE: [firebird-support] String with added string-variable |
---|---|
Author | Helen Borrie |
Post date | 2012-05-24T20:49:55Z |
At 04:26 AM 25/05/2012, Svein Erling Tysvær wrote:
stmtxt = 'select 1 from rdb$database where exists(SELECT *
FROM RDB$RELATION_FIELDS
WHERE RDB$RELATION_NAME = T_DT
and RDB$FIELD_NAME = ' || '''' || fname || '''';
(That's 4 apostrophes concatenated each side of the variable.)
Or try avoiding the doubled apostrophes altogether:
...
declare variable fname varchar(31);
...
i = 1;
while (i< 7) do
begin
fname = case
when i = 1 then ascii_val(39) || f1 || ascii_val(39)
when i = 2 then ascii_val(39) || f2 || ascii_val(39)
-- etcetera
end
idexists = 0;
stmtxt = 'select 1 from rdb$database where exists(SELECT * FROM
RDB$RELATION_FIELDS
WHERE RDB$RELATION_NAME = 'T_DT'
and RDB$FIELD_NAME = ' || fname;
execute statement stmtxt into :idexists;
if(idexists = 0) then
...
end
>Still not enough apostrophes (I needed six apostrophes when I did my test, but I only used apostrophes around a constant and didn't use any concatenation so you need more than me). TryMissing a concat somewhere, it seems...
>
>stmtxt = 'select 1 from rdb$database where exists(SELECT *
>FROM RDB$RELATION_FIELDS
>WHERE RDB$RELATION_NAME = T_DT
> and RDB$FIELD_NAME = ''''''' || fname || '''''''';
>
>(so seven apostrophes before fname and eight after to get the six apostrophes that I successfully used)
stmtxt = 'select 1 from rdb$database where exists(SELECT *
FROM RDB$RELATION_FIELDS
WHERE RDB$RELATION_NAME = T_DT
and RDB$FIELD_NAME = ' || '''' || fname || '''';
(That's 4 apostrophes concatenated each side of the variable.)
Or try avoiding the doubled apostrophes altogether:
...
declare variable fname varchar(31);
...
i = 1;
while (i< 7) do
begin
fname = case
when i = 1 then ascii_val(39) || f1 || ascii_val(39)
when i = 2 then ascii_val(39) || f2 || ascii_val(39)
-- etcetera
end
idexists = 0;
stmtxt = 'select 1 from rdb$database where exists(SELECT * FROM
RDB$RELATION_FIELDS
WHERE RDB$RELATION_NAME = 'T_DT'
and RDB$FIELD_NAME = ' || fname;
execute statement stmtxt into :idexists;
if(idexists = 0) then
...
end