예제 #1
0
        public string ReadJoinAGG(Match joinMatch)
        {
            string listAgg = string.Empty;

            // get join meta
            string joinPack      = joinMatch.Groups ["JOIN_PACK"].Value;
            string joinAttrName  = joinMatch.Groups ["JOIN_ATTR_NAME"].Value;
            string joinTableName = joinMatch.Groups ["JOIN_TABLE_NAME"].Value;

            joinTableName = string.IsNullOrEmpty(joinTableName) ? joinAttrName : joinTableName;

            CaptureCollection joinValCaps = joinMatch.Groups ["JOIN_VALUES"].Captures;

            foreach (Capture cap in joinValCaps)
            {
                Match attrMatch = Regex.Match(cap.Value, DBPatternHelper.GetQueryAttrPattern());
                if (attrMatch.Success == true)
                {
                    string attrName = attrMatch.Groups ["ATTR_NAME"].Value;
                    string colName  = attrMatch.Groups ["COL_NAME"].Value;
                    if (string.IsNullOrEmpty(listAgg))
                    {
                        listAgg = $"'\"{attrName}\":' || '\"' || {joinAttrName}.{colName} || '\"'";
                    }
                    else
                    {
                        listAgg += $" || ',' || '\"{attrName}\":' || '\"' || {joinAttrName}.{colName} || '\"'";
                    }
                }
            }
            listAgg = string.IsNullOrEmpty(listAgg) ? listAgg : "LISTAGG(('{' || " + listAgg + " || '}'), ',')";
            return(string.IsNullOrEmpty(listAgg) ? null : ((joinPack == "1") ? listAgg : $"('[' || {listAgg} || ']')") + " AS " + "JOIN_" + joinAttrName);
        }
예제 #2
0
        // detect JOIN by VIEW (SELECT) or JOIN by TABLE
        public bool IsReadJoinByView(Match joinMatch)
        {
            //check JOIN PACK
            string joinPack = joinMatch.Groups ["JOIN_PACK"].Value;

            //defaul join pack is all
            joinPack = string.IsNullOrEmpty(joinPack) ? "ALL" : joinPack;
            if (joinPack.ToUpper() != "ALL")
            {
                return(true);
            }
            //check Join Values has functions
            CaptureCollection joinValCaps = joinMatch.Groups ["JOIN_VALUES"].Captures;

            foreach (Capture cap in joinValCaps)
            {
                Match attrMatch = Regex.Match(cap.Value, DBPatternHelper.GetQueryAttrPattern());
                if (attrMatch.Success == true)
                {
                    CaptureCollection anoCaps = attrMatch.Groups ["ANOTATIONS"].Captures;
                    foreach (Capture anoCap in anoCaps)
                    {
                        Match anoMatch = Regex.Match(anoCap.Value, DBPatternHelper.GetQueryAttrAnotationPattern());
                        if (anoMatch.Success == true)
                        {
                            string anoName = anoMatch.Groups ["ANOTATION_NAME"].Value;
                            switch (anoName.ToUpper())
                            {
                            case "MIN":
                            case "MAX":
                            case "COUNT":
                            case "SUM":
                            case "AVG":
                                return(true);

                            default:
                                return(false);
                            }
                        }
                    }
                }
            }
            return(false);
        }
예제 #3
0
        public void ReadAttributeParser(string attrStr, Match objMatch)
        {
            // Get object value
            string objName      = objMatch.Groups ["OBJ_NAME"].Value;
            string objTableName = objMatch.Groups ["OBJ_TABLE_NAME"].Value;

            objTableName = string.IsNullOrEmpty(objTableName) ? objName : objTableName;

            // Parser Attribute
            Match attrMatch = Regex.Match(attrStr, DBPatternHelper.GetQueryAttrPattern());

            if (attrMatch.Success == true)
            {
                string attrName   = attrMatch.Groups ["ATTR_NAME"].Value;
                string colDeclare = attrMatch.Groups ["COL_NAME"].Value;
                colDeclare = string.IsNullOrEmpty(colDeclare) ? attrName : colDeclare;
                string colName   = colDeclare;
                bool   mustGroup = true;

                if (!string.IsNullOrEmpty(attrName))
                {
                    // 1. Anotaion parser
                    CaptureCollection anoCaps = attrMatch.Groups ["ANOTATIONS"].Captures;
                    foreach (Capture anoCap in anoCaps)
                    {
                        Match anoMatch = Regex.Match(anoCap.Value, DBPatternHelper.GetQueryAttrAnotationPattern());
                        if (anoMatch.Success == true)
                        {
                            string anoName = anoMatch.Groups ["ANOTATION_NAME"].Value.ToUpper();
                            string anoMeta = anoMatch.Groups ["ANOTATION_META"].Value.ToUpper();

                            switch (anoName)
                            {
                            case "COUNT":
                            case "SUM":
                            case "MIN":
                            case "MAX":
                            case "AVG":
                                colName = anoName + "(" + objName + "." + colName + ")";
                                if (!string.IsNullOrEmpty(anoMeta))
                                {
                                    anoMeta = $"{colName}{anoMeta}";
                                    if (string.IsNullOrEmpty(this.Having))
                                    {
                                        this.Having = $"HAVING {anoMeta}";
                                    }
                                    else
                                    {
                                        this.Having += $" AND {anoMeta}";
                                    }
                                }
                                // Calculator Funcs don't GROUP BY
                                mustGroup = false;
                                break;

                            case "DISTINCT":
                                colName = anoName + " " + objName + "." + colName;
                                break;

                            case "ORDER":
                                string orderVal = attrName;
                                switch (anoMeta)
                                {
                                case "DESC":
                                    orderVal += $" {anoMeta}";
                                    break;

                                default:
                                    break;
                                }

                                if (string.IsNullOrEmpty(this.OrderBy))
                                {
                                    this.OrderBy = $"ORDER BY {orderVal}";
                                }
                                else
                                {
                                    this.OrderBy += $", {orderVal}";
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }

                    //check must GROUP
                    if (mustGroup)
                    {
                        if (string.IsNullOrEmpty(this.GroupBy))
                        {
                            this.GroupBy = $"GROUP BY {objName}.{colDeclare}";
                        }
                        else
                        {
                            this.GroupBy += $", {objName}.{colDeclare}";
                        }
                    }

                    // 2. Name Parser
                    attrName = (colName != colDeclare ? colName : objName + "." + colName) + " AS " + (this.IsJoinView ? colDeclare : attrName);
                    if (string.IsNullOrEmpty(this.Select))
                    {
                        this.Select = $"SELECT {attrName}";
                    }
                    else
                    {
                        this.Select += $", {attrName}";
                    }
                }
            }
            else
            {
                Console.WriteLine("Attributes not match!");
            }
        }