Add columns at query (QBSelect)

Questions and answers regarding general SQL and backend databases

Add columns at query (QBSelect)

Postby e.valstar » Mon Nov 17, 2014 10:08 pm

Hi All,
Sorry, I'm a bit 'green' in this part. Maybe one of you can help me.
I want to make a combination of 2 tables and from both tables of them I want a few fields. Like
SELECT o.pickup_date, t.order_number FROM transport_order o INNER JOIN transport t ON o.transport_id = t.transport_id WHERE o.pickup_date ..etc.

I figured this out:
Code: Select all
    /** @type {QBSelect<db:/test_db/transport_order>} */
    var query = databaseManager.createSelect('db:/test_db/transport_order');
    query.where.add(query.columns.pickup_date.between(pickUpDate_from,pickUpDate_to));

    /** @type {QBJoin<db:/test_db/transport>} */
    var transportJN = query.joins.add("db:/test_db/transport", JSRelation.INNER_JOIN);
    transportJN.on.add(query.columns.transport_id.eq(transportJN.columns.transport_id));
   
    query.result.add(transportJN.columns.order_number);
    var testFS = databaseManager.getFoundSet(query);
    application.output(testFS.getRecord(1).order_number);

For a reason or the other, I don't get the expected result (null)
I try this also without the relation, like:
Code: Select all
query.result.add(query.columns.pickup_date,"test");

but this also didn't get the column "test" in the foundset.

What I'm doing wrong?

Thanks in advance!
e.valstar
 
Posts: 8
Joined: Mon Nov 17, 2014 9:52 pm

Re: Add columns at query (QBSelect)

Postby j.boonstra » Tue Nov 18, 2014 10:56 am

The problem is that you cannot use the function databaseManager.getFoundSet for any arbitrary query. It must be a query which returns the primary key of the main table of the query. Try using databaseManager.getDataSetByQuery instead.
Jeroen boonstra
A10Tech
http://www.a10tech.nl
j.boonstra
 
Posts: 18
Joined: Fri Nov 14, 2014 3:25 pm

Re: Add columns at query (QBSelect)

Postby e.valstar » Tue Nov 18, 2014 6:33 pm

Thanks Jeroen,

This works fine, only I don't reach my final goal. I wanted to get a foundset so I can use excelexport like:
Code: Select all
var changedFile = plugins.excelxport.excelExport(testFS, ["order_number"], orgFile, "Test");


How can I fix this?

Thanks again.
e.valstar
 
Posts: 8
Joined: Mon Nov 17, 2014 9:52 pm

Re: Add columns at query (QBSelect)

Postby j.boonstra » Wed Nov 19, 2014 9:55 am

In that case have a look at databaseManager.createDataSourceByQuery.
Jeroen boonstra
A10Tech
http://www.a10tech.nl
j.boonstra
 
Posts: 18
Joined: Fri Nov 14, 2014 3:25 pm

Re: Add columns at query (QBSelect)

Postby e.valstar » Wed Nov 19, 2014 6:36 pm

Thanks for your fast reply Jeroen.

This didn't help.
The databaseManager.createDataSourceByQuery returns a String, while plugins.excelxport.excelExport needs a Object as first parameter.

Other solutions availible?
e.valstar
 
Posts: 8
Joined: Mon Nov 17, 2014 9:52 pm

Re: Add columns at query (QBSelect)

Postby j.boonstra » Thu Nov 20, 2014 9:48 am

e.valstar wrote:Thanks for your fast reply Jeroen.

This didn't help.
The databaseManager.createDataSourceByQuery returns a String, while plugins.excelxport.excelExport needs a Object as first parameter.

Other solutions availible?

Did you have a look at the documentation of this function? The string it returns is a datasource uri which you can use in databaseManager.getFoundSet(uri) to get the foundset object.
Jeroen boonstra
A10Tech
http://www.a10tech.nl
j.boonstra
 
Posts: 18
Joined: Fri Nov 14, 2014 3:25 pm

Re: Add columns at query (QBSelect)

Postby e.valstar » Thu Nov 20, 2014 1:33 pm

Thanks Jeroen,

This worked out!
And, now I readed the documentation of this function, and put it in the solution.

Thanks for your time.
e.valstar
 
Posts: 8
Joined: Mon Nov 17, 2014 9:52 pm


Return to SQL Databases

Who is online

Users browsing this forum: No registered users and 2 guests