Пример #1
0
        private LinqSQLParser(string sql, ObjectTypeConstants type)
        {
            if ((sql == null) || (sql == string.Empty))
            {
                throw new Exception("SQL cannot be empty.");
            }

            this.FieldList = new List <LinqSQLField>();
            sql            = sql.Replace("] AS [value]\r", "]\r");
            _type          = type;
            _sql           = sql;

            //Parse the string into SELECT, FROM, WHERE
            var index        = sql.IndexOf("\r\nFROM") + 2;
            var selectClause = sql.Substring(0, index).Replace("\r\n", " ");

            index = sql.IndexOf("\r\nWHERE");
            if (index == -1)
            {
                index = sql.Length;
            }
            var fromClause = sql.Substring(selectClause.Length - 1, index - selectClause.Length + 1).Replace("\r\n", " ").Trim();

            fromClause   = fromClause.Substring(5, fromClause.Length - 5).Trim();
            selectClause = selectClause.Trim();
            fromClause   = fromClause.Trim();

            index = sql.IndexOf("\r\nWHERE");
            if (index != -1)
            {
                _whereClause = sql.Substring(index + 2, sql.Length - index - 2).Replace("\r\n", " ");
                _whereClause = _whereClause.Substring(6, _whereClause.Length - 6);
            }

            ParseFrom(fromClause);
            ParseSelect(selectClause);
            RemapParentChild();
        }
Пример #2
0
        public static string GetRemappedLinqSql(LinqSQLFromClause tableInfo, string whereClause, LinqSQLFromClauseCollection fromLinkList, ObjectTypeConstants type)
        {
            if (type == ObjectTypeConstants.Table)
            {
                switch (tableInfo.TableName)
                {
                case "ConfigSetting": return(Gravitybox.gFileSystem.EFDAL.Entity.ConfigSetting.GetRemappedLinqSql(whereClause, tableInfo.Alias, fromLinkList));

                case "Container": return(Gravitybox.gFileSystem.EFDAL.Entity.Container.GetRemappedLinqSql(whereClause, tableInfo.Alias, fromLinkList));

                case "FileStash": return(Gravitybox.gFileSystem.EFDAL.Entity.FileStash.GetRemappedLinqSql(whereClause, tableInfo.Alias, fromLinkList));

                case "Tenant": return(Gravitybox.gFileSystem.EFDAL.Entity.Tenant.GetRemappedLinqSql(whereClause, tableInfo.Alias, fromLinkList));
                }
            }
            if (type == ObjectTypeConstants.View)
            {
            }
            if (type == ObjectTypeConstants.StoredProcedure)
            {
            }
            throw new Exception("Table not found '" + tableInfo.TableName + "'.");
        }
Пример #3
0
 public static LinqSQLParser Create(string sql, ObjectTypeConstants type)
 {
     return(new LinqSQLParser(sql, type));
 }
        public static string GetRemappedLinqSql(LinqSQLFromClause tableInfo, string whereClause, LinqSQLFromClauseCollection fromLinkList, ObjectTypeConstants type)
        {
            if (type == ObjectTypeConstants.Table)
            {
                switch (tableInfo.TableName)
                {
                case "CanadaPostalCode": return(Gravitybox.GeoLocation.EFDAL.Entity.CanadaPostalCode.GetRemappedLinqSql(whereClause, tableInfo.Alias, fromLinkList));

                case "City": return(Gravitybox.GeoLocation.EFDAL.Entity.City.GetRemappedLinqSql(whereClause, tableInfo.Alias, fromLinkList));

                case "State": return(Gravitybox.GeoLocation.EFDAL.Entity.State.GetRemappedLinqSql(whereClause, tableInfo.Alias, fromLinkList));

                case "Zip": return(Gravitybox.GeoLocation.EFDAL.Entity.Zip.GetRemappedLinqSql(whereClause, tableInfo.Alias, fromLinkList));
                }
            }
            if (type == ObjectTypeConstants.View)
            {
            }
            if (type == ObjectTypeConstants.StoredProcedure)
            {
            }
            throw new Exception("Table not found '" + tableInfo.TableName + "'.");
        }