コード例 #1
0
        /**
         * Returns the previous record from a given
         * record in the record array
         * @param {IDRecord} record
         * @returns {IDRecord}
         */
        private IDRecord GetPreviousRecord(IDRecord record)
        {
            IDRecord result = null;
            var      index  = DRecords.IndexOf(record);

            if (index > -1 && index - 1 > 0)
            {
                result = DRecords[index] as IDRecord;
            }
            return(result);
        }
コード例 #2
0
        /**
         * Checks whether a given record position contains a
         * given instance type.
         * @param recordNum
         * @param recordInstanceType
         */
        public bool IsExpectedRecord(int recordNum, IDRecord recordInstanceType)
        {
            var isExpected = false;
            var inRange    = (recordNum <= DRecords.Count && recordNum >= 0);

            //TODO: Investigate instace comparison
            if (inRange && (DRecords[recordNum] == recordInstanceType))
            {
                isExpected = true;
            }

            return(isExpected);
        }
コード例 #3
0
        public string ToSql()
        {
            var sql = new StringBuilder();

            /**
             * Iterate the array on loopback for each type, that´s the most system
             * efficient and readable, don´t get confused by compiler masturbations
             * and smart array functions, they will boil down to something much
             * worse if you look behind the curtain.
             */

            /*
             * sql = ParseInsert(sql);
             * sql = ParseSelect(sql);
             * sql = ParseSelectAll(sql);
             * sql = ParseUpdate(sql);
             * sql = ParseSet(sql);
             * sql = ParseFrom(sql);
             * sql = ParseLeftJoin(sql);
             * sql = ParseWhere(sql);
             * sql = ParseAnd(sql);
             * sql = ParseOrderBy(sql);
             * sql = ParseLimit(sql);
             */

            IDRecord prevRecord = null;
            IDRecord currRecord = null;
            IDRecord nextRecord = null;

            for (var i = 0; i < DRecords.Count; i++)
            {
                prevRecord = currRecord;

                if (nextRecord != null)
                {
                    sql.Append(Const.SPACE);
                }

                nextRecord = i + 1 < DRecords.Count ? DRecords[i + 1] : null;

                currRecord = DRecords[i];


                if (currRecord is DSelect)
                {
                    sql.Append((currRecord as DSelect).ToSql());
                }

                if (currRecord is DSelectAll)
                {
                    sql.Append((currRecord as DSelectAll).ToSql());
                }

                if (currRecord is DFrom)
                {
                    var isSecond = (prevRecord is DFrom);
                    sql.Append((currRecord as DFrom).ToSql(isSecond));
                }

                if (currRecord is DWhere)
                {
                    var isSecond = (prevRecord is DWhere);
                    sql.Append((currRecord as DWhere).ToSql(isSecond));
                }

                if (currRecord is DInsert)
                {
                    sql.Append((currRecord as DInsert).ToSql());
                    break;
                }

                if (currRecord is DUpdate)
                {
                    sql.Append((currRecord as DUpdate).ToSql());
                }

                if (currRecord is DLimit)
                {
                    sql.Append((currRecord as DLimit).ToSql());
                }
            }

            return(sql.ToString());
        }