Hey guys,thanks for the information and your support.

Using the implementation of Java (postet byMark Rotteveel), the source code 
from the Firebird server 
(https://searchcode.com/codesearch/view/25432247/)andwith support of 
mycolleagues at work, I could understand the process and can now also read 
aliases from a statement.
It is important that before the "isc_dsql_sql_info"with 
"isc_info_sql_relation_alias"is called, the statementmust be prepared oder 
executed.
I solved my problem like this (tested with Firebird 2.1.5.18497 and Firebird 
2.5.3.26778):

-- code start --

IBS status;
char result[4096];

char itemsReq[] =
{
// byte order little endian
//c = 1 byte
//h = 2 byte
//d = 4 byte
//s = n bytes string not terminated

isc_info_sql_select, // result = c type
isc_info_sql_describe_vars, // result = c type + h package length + d parameter 
count
isc_info_sql_relation_alias, // result = c type + h package length + s alias + 
c unknown
};

isc_dsql_sql_info(status.Self(), &mHandle, sizeof(itemsReq), itemsReq, 
sizeof(result), result);

if (status.Errors()) throw SQLExceptionImpl(status,
"TableAliases", _("isc_dsql_sql_info failed."));

auto GetStrings = [] (char *buffer, char token, char subtoken) -> 
std::vector<std::string>
{
char *p = buffer;

if (*p != token)
throw LogicExceptionImpl("GetStrings", _("Token not found."));

// the first byte is isc_info_sql_select that consists of one byte without 
length
++p;

auto FindToken = [] (char token, char *aBuffer) -> char*
{
if (aBuffer == nullptr)
return nullptr;

char* p = aBuffer;

while (*p != isc_info_end)
{
int len;

if (*p == token)
return p;

len = (*gds.Call()->m_vax_integer)(p + 1, 2);
p += (len + 3);
}

return nullptr;
};

std::vector<std::string> results;
std::string strData;

while ((p = FindToken(subtoken, p)) != nullptr)
{
int len;
len = (*gds.Call()->m_vax_integer)(p+1, 2);
strData = std::string(p+3, len);

// skip the string
p += 3 + len;

if (*p == isc_info_sql_describe_end)
++p;

results.push_back(strData);
}

return results;
};

std::vector<std::string> aliases = GetStrings(result, isc_info_sql_select, 
isc_info_sql_relation_alias);

-- code end -- This may not be the best implementation, but I wanted to share 
my results with all the interested it.With best regards,

Rudolf
Am 16. Dezember 2014, hat Vlad Khorsun <hv...@users.sf.net> geschrieben:
> 16.12.2014 11:13, Mark Rotteveel wrote:
> > On Tue, 16 Dec 2014 11:03:39 +0200, Vlad Khorsun <<hv...@users.sf.net>>
> > wrote:
> > > 16.12.2014 10:27, Rudolf Grauberger wrote:
> > > > I would like to read the table aliases,
> > > > 
> > > After call of isc_dsql_prepare() you'll have XSQLDA structure filled
> > > with all
> > > info, including known relation aliases. Read IB6 "API Guide", chapter
> > > "Working
> > > with Dynamic SQL". Guide is available here:
> > > 
> > > http://www.firebirdsql.org/en/reference-manuals/
> > > 
> > The XSQLDA doesn't include the relation alias, only the relation name (and
> > the column name and alias). So you need to to use sql_info to obtain the
> > relation_alias; isc_info_sql_relation_alias was also only added in Firebird
> > 2.
> > 
> You right, i forget about it. Hope, your link helps Rudolf.
> 
> Regards,
> Vlad
> 
> 
> 
> ------------------------------------------------------------------------------
> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> with Interactivity, Sharing, Native Excel Exports, App Integration & more
> Get technology previously reserved for billion-dollar corporations, FREE
> <http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk>
> Firebird-Devel mailing list, web interface at 
> <https://lists.sourceforge.net/lists/listinfo/firebird-devel>
>
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to