2.2.7.9.1 QueryResult::Build


Description

Create a query


Search origin object within given dataset

Syntax

int Build( LPCSTR lpcszExp, DWORD dwCntrl = 0, LPCSTR lpcszFilterFunc = NULL )


int Build( vector<string> & vs, QUERYRESULTBUILD nType )

Parameters

lpcszExp
[input] query expression.
Syntax:
SELECT Objects FROM Range WHERE Condition
keyword type keywords
Query select, from, where, and, or, not, like, casesensitive
Object datasheet, worksheet, matrixsheet, graphlayer, folder, book, workbook, matrixbook, graphbase, graph, layout, notes, column, column_y column_z, matrixobject, dataset, loosedataset, virtualmatrix, functionplot, namedrange
Range project, activefolder, favoritefolder, recursive, shortcut, embeded
Property _type, _sname, _lname, _datasettype, _comments, _visible, column_p, column_d, column_[UserParameter]
_datasettype dep, indep
Dateset type v ( Virtual Matrix ), r ( Named Range ), f ( Function Plot ), l ( Loose Dataset ), n ( Normal )
Column Designation x, y, z, e, l, m, n
dwCntrl
[input] if dwCntrl = QUERYRESULTBUILDCTRNL_KEEP_LAST_RESULT, it will keep last query's result
lpcszFilterFunc
[input] filter function name


vs
[input] dataset names
nType
[input] origin object type

Return

Number of found objects


Number of found objects

Examples

EX1

This example shows how to use the filter function
BOOL HasData(OriginObject& obj, QUERYRESULTS_FILTER_ELEMENTTYPE nType)
{
    if ( QUERYRESULTS_FILTER_ELEMENTTYPE__LAYER != nType )
        return TRUE;
    Worksheet wks;
    wks = (Worksheet)obj;
    if(!wks)
        return TRUE;
    
    matrix mat;
    mat.CopyFromWks(wks);
    mat.RemoveEmptyRows();
    return mat.GetNumCols() > 0;
}

void Build_ex()
{
    QueryResult qr;
    
    Project.Open();
    vector<string> vsFiles = {"Counts", "Inset"};
    
    out_str("Find Y columns( no col(C) ):");
    for(int ii = 0; ii < vsFiles.GetSize(); ii++)
    {
        //---prepare wks
        string strFile = GetAppPath(TRUE) + "Samples\\Graphing\\" + vsFiles[ii] + ".dat";
        ASCIMP ai;
        if( 0 == AscImpReadFileStruct(strFile, &ai) )
        {
            Worksheet wks;
            wks.Create();
            wks.ImportASCII(strFile, ai);
        }
        //---
        string strSQL;
        strSQL.Format("select COLUMN from [%s] where _SNAME != 'C' and _TYPE == Y", vsFiles[ii]);
        int nRet = qr.Build(strSQL, QUERYRESULTBUILDCTRNL_KEEP_LAST_RESULT);
        out_int("nRet=", nRet);
    }
    out_int("size=", qr.Size());
    
    vector<string> vsNames;
    qr.GetNames(vsNames, QUERYRESULTNAME_RANGE);
    for(ii = 0; ii < vsNames.GetSize(); ii++)
    {
        out_str( vsNames[ii] );
    }
    
    vector<string> vsInfo;
    qr.GetColInfo(vsInfo, QUERYRESULTCOL_VALUE, 1);
    for(ii = 0; ii < vsInfo.GetSize(); ii++)
    {
        out_str( vsInfo[ii] );
    }
    
    qr.Clear();
    
    out_str("\nFind wks has data:");
    qr.Build("Select WORKSHEET from ACTIVEFOLDER", 0, "HasData");
    vsNames.SetSize(0);;
    qr.GetNames(vsNames, QUERYRESULTNAME_SNAME);
    for(ii = 0; ii < vsNames.GetSize(); ii++)
    {
        out_str( vsNames[ii] );
    }
}


EX2

This example is about int Build( vector<string> & vs, QUERYRESULTBUILD nType )
//prepare workbooks Book1, Book2
void Build_vs_ex()
{    
    QueryResult qr;
    vector<string> vs = {"Book1_A", "Book2_B"};
    QUERYRESULTBUILD nObjectType = QUERYRESULTBUILD_COLUMN;
    int nRet = qr.Build(vs, nObjectType);
    out_int("", nRet);
}

EX3

This example shows the Where condition allow different objects
select COLUMN from Project where Book_SName like "Book*" and Sheet_SName like "Sheet1" and Column_LName like "YCO*"

EX4

This example is about column's user parameter, and numeric comparison
select COLUMN from Project where Column_[ASD] like "*2*" or Column_D2 > 3

EX5

This example shows the usage of keyword _Visible
Select Column from Project where _Visible = false

EX6

This example shows how to get the corresponding X column
Select Column_Y from Project where _SName like "D"

Remark

See Also

Header to Included

origin.h