On 03/01/2018 03:57, Lionel Elie Mamane wrote:
> Hi,
>
> Where is ':' a valid character in Firebird SQL? In particular, is it
> ever valid outside of "-delimited identifiers and '-delimited strings?
>
> Context: In the LibreOffice integration of Firebird, we would like to
> allow users to use named parameters, that is things like ':foo' instead
> of '?' (without the single quotes). E.g.
>
>  SELECT foo, bar FROM qux WHERE item_year = :year
>
> instead of
>
>  SELECT foo, bar FROM qux WHERE item_year = ?
>
> Which means we have to go through the SQL statement passed by the user
> and replace such ':foo' parameters by '?' before giving the SQL
> statement to Firebird.
>
> I'd like to avoid completely parsing the SQL statement for that,
> mainly so that the SQL statement is not modified by the LibreOffice
> SQL parser (and in particular quoting keywords it doesn't know as
> identifiers). So I'm hoping to simply go through the string, keep
> track of single and double quotes, and replace any word (outside of
> quotes) that starts with ':' by '?'. This wouldn't work for
> e.g. PostgreSQL because of its cast syntax (namely 'data::type'), but
> is it OK for Firebird?
>
>
:foo is a valid syntax in Firebird inside PSQL code, i.e., stored
procedures, triggers, execute block.

Example:

execute block returns (foo integer)
as
begin
    select 1 from rdb$database into :foo;
    suspend;
end

It's also valid for input parameters:

execute block (bar integer = ?) returns (foo integer)
as
begin
    select 1 from rdb$database where 1 = :bar into :foo;
    suspend;
end


Adriano


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to