Page 1 of 1

SELECT * translated into QBSelect / QueryBuilder

PostPosted: Thu Aug 28, 2014 2:24 pm
by deezzub
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?

Re: SELECT * translated into QBSelect / QueryBuilder

PostPosted: Fri Aug 29, 2014 6:43 pm
by ROCLASI
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.