예제 #1
0
        /// <summary>
        /// Adds "SELECT columnlist" and "FROM tablename" to a CQL statement if they don't already exist for a POCO of Type T.
        /// </summary>
        public void AddSelect <T>(Cql cql)
        {
            // If it's already got a SELECT clause, just bail
            if (SelectRegex.IsMatch(cql.Statement))
            {
                return;
            }

            // Get the PocoData so we can generate a list of columns
            var pocoData   = _pocoDataFactory.GetPocoData <T>();
            var allColumns = pocoData.Columns.Select(Escape(pocoData)).ToCommaDelimitedString();

            // If it's got the from clause, leave FROM intact, otherwise add it
            cql.SetStatement(FromRegex.IsMatch(cql.Statement)
                                 ? string.Format("SELECT {0} {1}", allColumns, cql.Statement)
                                 : string.Format("SELECT {0} FROM {1} {2}", allColumns, Escape(pocoData.TableName, pocoData), cql.Statement));
        }
예제 #2
0
        /// <summary>
        /// Adds "SELECT columnlist" and "FROM tablename" to a CQL statement if they don't already exist for a POCO of Type T.
        /// </summary>
        public void AddSelect <T>(Cql cql)
        {
            // If it's already got a SELECT clause, just bail
            if (CqlGenerator.SelectRegex.IsMatch(cql.Statement))
            {
                return;
            }

            // Get the PocoData so we can generate a list of columns
            var pocoData   = _pocoDataFactory.GetPocoData <T>();
            var allColumns = pocoData.Columns.Select(CqlGenerator.EscapeFunc(pocoData)).ToCommaDelimitedString();

            var suffix = cql.Statement == string.Empty ? string.Empty : " " + cql.Statement;

            // If it's got the from clause, leave FROM intact, otherwise add it
            cql.SetStatement(CqlGenerator.FromRegex.IsMatch(cql.Statement)
                                 ? $"SELECT {allColumns}{suffix}"
                                 : $"SELECT {allColumns} FROM " +
                             $"{CqlGenerator.CqlIdentifierHelper.EscapeTableNameIfNecessary(pocoData, pocoData.KeyspaceName, pocoData.TableName)}" +
                             $"{suffix}");
        }