Skip to main content



      Home
Home » Modeling » EMF » [CDO] SQL query results
[CDO] SQL query results [message #662162] Tue, 29 March 2011 11:00 Go to next message
Eclipse UserFriend
Hi,

I would like to run SQL queries on the CDO store and return several columns from the database. Unfortunately the CDOQuery returns only the first column when running the query.

Is there a reason why the SQLQueryHandler returns only the first column as a result of an SQL query even if not a CDO object query is run (SQLQueryHandler.CDO_OBJECT_QUERY is set to false)?

The code that returns the result in SQLQueryHandler.executeQuery() is the following:

if (objectQuery)
{
CDOID result = idHandler.getCDOID(resultSet, 1);
context.addResult(result);
}
else
{
Object result = resultSet.getObject(1);
context.addResult(result);
}


Would it make sense to change it to something like this?

if (objectQuery)
{
CDOID result = idHandler.getCDOID(resultSet, 1);
context.addResult(result);
}
else
{
int columnCount = resultSet.getMetaData().getColumnCount();

if (columnCount == 1)
{
Object result = resultSet.getObject(1);
context.addResult(result);
}
else
{
Object[] results = new Object[columnCount];
for (int i = 0; i < columnCount; i++)
{
results[i] = resultSet.getObject(i+1);
}
context.addResult(results);
}
}

If the query is not a CDOObject query, the client is probably interested in all of the queried fields.

Regards,
Szabolcs


Re: [CDO] SQL query results [message #662253 is a reply to message #662162] Tue, 29 March 2011 17:21 Go to previous messageGo to next message
Eclipse UserFriend
Hi Szabolcs,

I guess we just didn't do it because nobody asked for it in the past. Maybe because the transport protocol is not prepared to deliver arrays of arbitrary objects. Seems you've already played with the code, are you willing to open a bugzilla and attach a patch including some test cases? I'll be back from California next week and could review it then...

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper



Am 29.03.2011 08:00, schrieb Szabolcs Bardy:
> Hi,
>
> I would like to run SQL queries on the CDO store and return several columns from the database. Unfortunately the CDOQuery returns only the first column when running the query.
>
> Is there a reason why the SQLQueryHandler returns only the first column as a result of an SQL query even if not a CDO object query is run (SQLQueryHandler.CDO_OBJECT_QUERY is set to false)?
>
> The code that returns the result in SQLQueryHandler.executeQuery() is the following:
>
> if (objectQuery)
> {
> CDOID result = idHandler.getCDOID(resultSet, 1);
> context.addResult(result);
> }
> else
> {
> Object result = resultSet.getObject(1);
> context.addResult(result);
> }
>
>
> Would it make sense to change it to something like this?
>
> if (objectQuery)
> {
> CDOID result = idHandler.getCDOID(resultSet, 1);
> context.addResult(result);
> }
> else
> {
> int columnCount = resultSet.getMetaData().getColumnCount();
>
> if (columnCount == 1)
> {
> Object result = resultSet.getObject(1);
> context.addResult(result);
> }
> else
> {
> Object[] results = new Object[columnCount];
> for (int i = 0; i < columnCount; i++)
> {
> results[i] = resultSet.getObject(i+1);
> }
> context.addResult(results);
> }
> }
>
> If the query is not a CDOObject query, the client is probably interested in all of the queried fields.
>
> Regards,
> Szabolcs
>
>
>
Re: [CDO] SQL query results [message #662395 is a reply to message #662253] Wed, 30 March 2011 10:28 Go to previous message
Eclipse UserFriend
Hi Eike,

thanks for your answer.

I created a new bugzilla entry (https://bugs.eclipse.org/bugs/show_bug.cgi?id=341363), attached the proposed patch and a test case.

Regards,
Szabolcs
Previous Topic:[CDO] recover from lost connection
Next Topic:Extend an core Ecore model
Goto Forum:
  


Current Time: Wed Jul 23 08:04:40 EDT 2025

Powered by FUDForum. Page generated in 0.07339 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top