Statement() 공개 메소드

Sets a N1QL statement to be executed.
Will erase a previous optimization of a statement using Prepared.
statement
public Statement ( string statement ) : IQueryRequest
statement string Any valid N1QL statement for a POST request, or a read-only N1QL statement (SELECT, EXPLAIN) for a GET request.
리턴 IQueryRequest
        protected override Task<SelectedSnapshot> LoadAsync(string persistenceId, SnapshotSelectionCriteria criteria)
        {

            // Create a Query with dynamic parameters
            string N1QLQueryString = "select `" + _CBBucket.Name + "`.* from `" + _CBBucket.Name + "` where DocumentType = 'SnapshotEntry' AND PersistenceId = $PersistenceId ";

            IQueryRequest N1QLQueryRequest = new QueryRequest()
                    .AddNamedParameter("PersistenceId", persistenceId);

            string N1QLQueryOrderByClauseString = "ORDER BY SequenceNr DESC";
            
            if (criteria.MaxSequenceNr > 0 && criteria.MaxSequenceNr < long.MaxValue)
            {
                N1QLQueryString += "AND SequenceNr <= $limit ";
                N1QLQueryOrderByClauseString = "ORDER BY SequenceNr DESC,";
                N1QLQueryRequest.AddNamedParameter("limit",criteria.MaxSequenceNr);
            }

            if (criteria.MaxTimeStamp != DateTime.MinValue && criteria.MaxTimeStamp != DateTime.MaxValue)
            {
                N1QLQueryString += " AND Timestamp <= $timelimit ";
                N1QLQueryOrderByClauseString = "ORDER BY Timestamp DESC,";
                N1QLQueryRequest.AddNamedParameter("timelimit", criteria.MaxTimeStamp.Ticks.ToString());
            }

            N1QLQueryString += N1QLQueryOrderByClauseString.TrimEnd(',') + " LIMIT 1"; 

            N1QLQueryRequest.Statement(N1QLQueryString).AdHoc(false);

            return taskLoadAsync(N1QLQueryRequest);
                

        }
예제 #2
0
        public List<string> postAttendance(string email, string user_id, string timeIn, int location)
        {
            var queryRequest = new QueryRequest();
            DateTime TimeIn = DateTime.Now;
            List<string> values = new List<string>();
            TimeSpan work;
            try
            {
                if (timeIn.CompareTo("") != 0)
                {

                    TimeIn = DateTime.Parse(HttpUtility.UrlDecode(timeIn));
                }
                string userCond = "";
                userCond = " and user_id=$user_id ";
                if (user_id != null && !user_id.Equals(""))
                {

                    queryRequest.AddNamedParameter("user_id", user_id);

                }
                else if (email != null && !email.Equals(""))
                {
                    queryRequest.AddNamedParameter("email", email);

                    var queryGetUserId = new QueryRequest();
                    queryGetUserId.Statement("SELECT META(Testing).id AS id FROM `Testing`  WHERE email=$email")
                        .AddNamedParameter("email", email);
                    IQueryResult<dynamic> resultId = bucket.Query<dynamic>(queryGetUserId);
                    if (resultId.Rows.Count() > 0)
                    {
                        JObject userAttendanceData = JsonConvert.DeserializeObject<JObject>(resultId.Rows.ElementAt(0) + "");
                        values.Add(userAttendanceData["id"].ToString());
                        queryRequest.AddNamedParameter("user_id", userAttendanceData["id"].ToString());
                        user_id = userAttendanceData["id"].ToString();
                    }
                    else
                    {
                        values.Add("No User Found");
                        return values;
                    }
                }
                else
                {
                    values.Add("No User Found");
                    return values;
                }
                string dat=TimeIn.ToString("yyyy-MM-dd");
                UserAttendance newAttendance = null;
                queryRequest.Statement("SELECT META(Testing).id AS id,* FROM `Testing` WHERE date=$date2 " + userCond)
                        .AddNamedParameter("date2",dat );

                IQueryResult<dynamic> result = bucket.Query<dynamic>(queryRequest);

                if (result.Rows.Count() == 0)
                {
                    DateTime defTime = DateTime.Parse(TimeIn.ToString("yyyy/MM/dd") + "T17:00:00");
                    work = defTime.Subtract(TimeIn);
                    newAttendance = new UserAttendance
                   {
                       user_id = user_id,
                       date = dat,
                       marked_at = new List<DateTime>(),
                       time_in = TimeIn.ToString("yyyy-MM-ddTHH:mm:ss"),
                       time_out = "",
                       default_out = defTime.ToString(),
                       shifttotalhours = "8",
                       worktotalhours = work.Hours + ":" + work.Minutes,
                       doctype = "user_attendance",
                       channels = new[] { "attendance" },

                       client = "Esajee",
                       shiftId = "1",
                       shiftName = "Default",
                       location = location
                   };
                    newAttendance.marked_at.Add(TimeIn);
                    values.Add(user_id);
                    toServerPost(newAttendance, "","POST");
                }
                else
                {
                    JObject userAttendanceData = JsonConvert.DeserializeObject<JObject>(result.Rows.ElementAt(0)+ "");
                    string docId = "";
                    string revId = "";
                    docId = userAttendanceData["id"].ToString();
                    revId = userAttendanceData["Testing"]["_sync"]["rev"].ToString();
                    newAttendance = JsonConvert.DeserializeObject<UserAttendance>(JsonConvert.SerializeObject(userAttendanceData["Testing"]));
                    DateTime markTimeIn = DateTime.Parse(newAttendance.time_in);

                    if (newAttendance != null)
                    {

                        newAttendance.time_out = TimeIn.ToString("yyyy-MM-ddTHH:mm:ss");
                        TimeSpan work12 = TimeIn.Subtract(markTimeIn);
                        newAttendance.worktotalhours = work12.Hours + ":" + work12.Minutes;
                        if (newAttendance.marked_at != null)
                        {
                            newAttendance.marked_at.Add(TimeIn);
                        }
                        values.Add(toServerPost(newAttendance,docId + "?rev="+revId,"PUT"));
                    }
                    else
                    {
                        values.Add("View Not Working");
                    }

                }
            }
            catch (Exception re)
            {
                values.Add("Times convertion failed");
                return values;
            }
            return values;
        }
        protected override Task DeleteAsync(string persistenceId, SnapshotSelectionCriteria criteria)
        {
            string N1QLQueryString = "delete from `" + _CBBucket.Name + "` where DocumentType = 'SnapshotEntry' AND PersistenceId = $PersistenceId ";

            IQueryRequest N1QLQueryRequest = new QueryRequest()
                .AddNamedParameter("PersistenceId", persistenceId);


            if (criteria.MaxSequenceNr > 0 && criteria.MaxSequenceNr < long.MaxValue)
            {
                N1QLQueryString += " AND SequenceNr <= $limit ";
                N1QLQueryRequest.AddNamedParameter("limit", criteria.MaxSequenceNr);
            }

            if (criteria.MaxTimeStamp != DateTime.MinValue && criteria.MaxTimeStamp != DateTime.MaxValue)
            {
                N1QLQueryString += " AND Timestamp <= $timelimit ";
                N1QLQueryRequest.AddNamedParameter("timelimit", criteria.MaxTimeStamp.Ticks.ToString());
            }

            N1QLQueryRequest.Statement(N1QLQueryString).AdHoc(false);

            return _CBBucket.QueryAsync<dynamic>(N1QLQueryRequest);
        }
        private Task DeletePermanentlyMessages(SnapshotMetadata metadata)
        {
            string N1QLQueryString = "delete from `" + _CBBucket.Name + "` where DocumentType = 'SnapshotEntry' AND PersistenceId = $PersistenceId ";

            IQueryRequest N1QLQueryRequest = new QueryRequest()
                .AddNamedParameter("PersistenceId", metadata.PersistenceId)
                .AdHoc(false);



            if (metadata.SequenceNr > 0 && metadata.SequenceNr < long.MaxValue)
            {
                N1QLQueryString += " AND SequenceNr = $TargetSequenceId";
                N1QLQueryRequest.AddNamedParameter("TargetSequenceId", metadata.SequenceNr);

            }

            if (metadata.Timestamp != DateTime.MinValue && metadata.Timestamp != DateTime.MaxValue)
            {
                N1QLQueryString += " AND Timestamp = $TargetTimeStamp";
                N1QLQueryRequest.AddNamedParameter("TargetTimeStamp", metadata.Timestamp.Ticks.ToString());
            }

            N1QLQueryRequest.Statement(N1QLQueryString).AdHoc(false);

            return _CBBucket.QueryAsync<dynamic>(N1QLQueryRequest);
        }