SELECT * translated into QBSelect / QueryBuilder

Questions, tips and tricks and techniques for scripting in Servoy

SELECT * translated into QBSelect / QueryBuilder

Postby deezzub » Thu Aug 28, 2014 2:24 pm

How can I write SELECT * as QBSelect (QueryBuilder)?

I found out, that I can use query.result.add( query.columns.index ) as SELECT index, but is seems not to work like this: query.result.add( query.columns[ '*' ] ).

How can I get all columns with the QueryBuilder?
deezzub
 
Posts: 328
Joined: Tue May 28, 2013 3:02 pm
Location: Oldenburg, Germany

Re: SELECT * translated into QBSelect / QueryBuilder

Postby ROCLASI » Fri Aug 29, 2014 6:43 pm

Hi Sebastian,

It seems the QueryBuilder doesn't support the SELECT * syntax. You need to name every column you want to query which is a pain.
You could file a feature request for this.

In the mean time you could use the following method to get all columns:
Code: Select all
/**
  * @param {QBSelect} _oSelect
  */
function getAllColumns(_oSelect) {
    /** @type {Array<String>} */
    var _aNames = _oSelect.columns['allnames'];
    _aNames.map(function(_sName) {
        _oSelect.result.add(_oSelect.getColumn(_sName));
    });
    // no need to return anything since it was passed as a reference
}

Then you just call it like so:
Code: Select all
getAllColumns(query);


Hope this helps.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium


Return to Methods

Who is online

Users browsing this forum: No registered users and 13 guests