AXForum  
Вернуться   AXForum > Прочие обсуждения > Курилка
DAX
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 01.06.2012, 10:16   #1  
Murlin is offline
Murlin
Возьми свет!!!
Аватар для Murlin
Самостоятельные клиенты AX
Злыдни
 
291 / 32 (2) +++
Регистрация: 22.09.2008
Адрес: Тюмень, Рашан Федерашан
Цитата:
Сообщение от AP-1055D Посмотреть сообщение
Как переделать запрос в DAX выражение?
X++:
static str buildStringQuery(Query   query)
{
    int         i;
    str         result;
    ;
    for (i=1;i<=query.dataSourceCount();i++)
    {
        if (result)
            result = result + strfmt("\n");
        result = result + WorkFlowFunctions::buildDataSourceStr(query.dataSourceNo(i));
    }
    return result;
}
 
static str buildDataSourceStr(QueryBuildDataSource     qbds)
{
    container           c;
    str                 result = "";
    int                 i;
    str                 s,s1;
    boolean             whereB = false;
    tableName           tableName;
    tableName           newTableName;
    ;
    c = str2con_ru(qbds.toString()," WHERE ");
    s = conpeek(c,1);
    c = str2con_ru(s," NOTEXISTS JOIN ");
    s = conpeek(c,1);
    c = str2con_ru(s," EXISTST JOIN ");
    s = conpeek(c,1);
    c = str2con_ru(s," OUTER JOIN ");
    s = conpeek(c,1);
    c = str2con_ru(s," JOIN ");
    s = conpeek(c,1);
    s = s + " ";
    tableName = tableid2name(qbds.table());
    newTableName = strfmt("%1%2",tableName,qbds.uniqueId());
    s = strreplace(s,strfmt(" FROM %1 ",tableName),strfmt(" from %1 ",newTableName));
    if (qbds.linkCount())
    {
        s1 = WorkFlowFunctions::buildLinkStr(qbds);
        if ((s1) &&
            (!whereB))
        {
            s = s + strfmt(" where \n");
            whereB = true;
        }
        s = s + s1;
    }
    if (qbds.rangeCount())
    {
        s1 = WorkFlowFunctions::buildRangeStr(qbds);
        if ((s1) &&
            (!whereB))
        {
            s = s + strfmt(" where\n");
            whereB = true;
        }
        else
        if (s1)
            s = s + strfmt(" &&\n");
        s = s + s1;
    }
    if (qbds.id() > 1)
    {
        switch (qbds.joinMode())
        {
            case JoinMode::ExistsJoin:
                    s1 = " exists join ";
                    break;
            case JoinMode::InnerJoin:
                    s1 = " join ";
                    break;
            case JoinMode::NoExistsJoin:
                    s1 = " notexists join ";
                    break;
            case JoinMode::OuterJoin:
                    s1 = " outer join ";
                    break;
        }
        s = strreplace(s,"SELECT ",s1);
    }
    return s;
}
static str buildLinkStr(QueryBuildDataSource  qbds)
{
    int             i;
    str             s;
    str             result = "";
    QueryBuildLink  qbl;
    TableName       tableName;
    TableName       linkedTableName;
    TableName       newTableName;
    TableName       newLinkedTableName;
    container       c;
    ;
    if (qbds.id() > 1)
    {
        tableName = tableid2name(qbds.table());
        linkedTableName = tableid2name(qbds.parentDataSource().table());
        newTableName = strfmt("%1%2",tableName,qbds.uniqueId());
        newLinkedTableName = strfmt("%1%2",linkedTableName,qbds.parentDataSource().uniqueId());
        for (i=1;i<=qbds.linkCount();i++)
        {
            qbl = qbds.link(i);
            c = str2con_ru(qbl.toString(),"\\");
            s = conpeek(c,conlen(c));
            s = strreplace(s,tableName+".",newTableName+".");
            s = strreplace(s,linkedTableName+".",newLinkedTableName+".");
            if (result)
                result = result + strfmt(" &&\n");
            result = result + strfmt("(%1)",s);
        }
    }
    return result;
}
static str buildRangeStr(QueryBuildDataSource   qbds)
{
    int             i,j,iPos;
    str             result,res = "";
    QueryBuildRange qbr;
    str             fieldName,newFieldName;
    ListIterator    listIterator;
    str             s;
    ;
    for (i=1;i<=qbds.rangeCount();i++)
    {
        qbr =   qbds.range(i);
        if (qbr.value() == SysQuery::valueUnlimited())
            continue;
        fieldName = fieldid2name(qbds.table(),qbr.field());
        newFieldName = strfmt("%1%2.%3",tableid2name(qbds.table()),qbds.uniqueId(),fieldName);
        listIterator = new ListIterator(WorkFlowFunctions::processRange(qbr));
        result = "";
        while (listIterator.more())
        {
            if (result)
                result = result + " ";
            s = listIterator.value();
            if (s like "N'*'")
                result = result + s;
            else
            if (s == fieldName)
                result = result + newFieldName;
            else
            if (s == "OR")
                result = result + strfmt("||\n");
            else
            if (s == "NOT")
                result = result + "!";
            else
            if (s == "AND")
                result = result + strfmt("&&\n");
            else
            if (s == "=")
                result = result + "==";
            else
            if (fieldName2id(qbds.table(),s))
                result = result + strfmt("%1%2.%3",tableid2name(qbds.table()),qbds.uniqueId(),s);
            else
                result = result + s;
            listIterator.next();
        }
        if (res)
            res = res + strfmt(" &&\n");
        result = strreplace(result," N'","'");
        res = res + strfmt("(%1)",result);
    }
    return res;
}
Зачем это нужно сам не знаю
__________________
Axapta 3.0 sp 5 Oracle
Диплом Интернет-Университета Информационных Технологий: Основы бухгалтерского учета
Я могу взорвать вам мозг!!!
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Прайс на лицензии MS DAX UNRW Детская 1 08.09.2009 16:36
в качестве эксперимента теги dax* заменены на теги ax* mazzy Обсуждение форума 8 16.06.2009 13:16
Привествуем нового модератора в разделе DAX: DreamCreator mazzy Информация для участников 0 24.04.2009 15:59
Привествуем нового модератора в разделе DAX: sukhanchik mazzy Информация для участников 2 21.04.2009 21:31
Нужен сосед программист DAX для Совместного съема жилья :) Andrew Akhmetov Курилка 28 25.11.2008 17:53

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 01:18.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.