当前位置: 首页>>代码示例>>C#>>正文


C# QueryRequest.AddNamedParameter方法代码示例

本文整理汇总了C#中Couchbase.N1QL.QueryRequest.AddNamedParameter方法的典型用法代码示例。如果您正苦于以下问题:C# QueryRequest.AddNamedParameter方法的具体用法?C# QueryRequest.AddNamedParameter怎么用?C# QueryRequest.AddNamedParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Couchbase.N1QL.QueryRequest的用法示例。


在下文中一共展示了QueryRequest.AddNamedParameter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadAsync

        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);
                

        }
开发者ID:akkadotnet,项目名称:Akka.Persistence.CouchBase,代码行数:33,代码来源:CouchBaseDbSnapshotStore.cs

示例2: RunQuery

        private void RunQuery(string query, IDictionary<string,object> parameters = null)
        {
            edtResults.Text = query + "\r\n\r\nRunning...";
            tabControl.Enabled = false;

            Task.Run(async () =>
            {
                var bucket = ClusterHelper.GetBucket("beer-sample");

                var queryRequest = new QueryRequest(query);

                if (parameters != null)
                {
                    queryRequest.AddNamedParameter(parameters.ToArray());
                };

                var result = await
                    bucket.QueryAsync<dynamic>(queryRequest);
                if (!result.Success)
                {
                    if (result.Errors != null && result.Errors.Count > 0)
                    {
                        return result.Errors.First().Message;
                    }
                    else if (result.Exception != null)
                    {
                        return string.Format("{0}\r\n\r\n{1}\r\n{2}", query, result.Exception.Message,
                            result.Exception.StackTrace);
                    }
                    else
                    {
                        return "Unknown Error";
                    }
                }
                else if (result.Rows != null)
                {
                    var sb = new StringBuilder();
                    sb.AppendFormat("{0}\r\n\r\n{1} rows returned\r\n\r\n", query, result.Rows.Count);

                    foreach (var row in result.Rows)
                    {
                        sb.AppendLine(row.ToString());
                    }

                    return sb.ToString();
                }
                else
                {
                    return query + "\r\n\r\n0 row returned";
                }
            })
                .ContinueWith(task =>
                {
                    BeginInvoke(new Action(() =>
                    {
                        if (task.IsFaulted)
                        {
                            edtResults.Text = string.Format("{0}\r\n\r\n{1}\r\n{2}", query, task.Exception.Message,
                                task.Exception.StackTrace);
                        }
                        else
                        {
                            edtResults.Text = task.Result;
                        }

                        tabControl.Enabled = true;
                    }));
                });
        }
开发者ID:brantburnett,项目名称:N1QlInjection,代码行数:69,代码来源:MainForm.cs

示例3: postAttendance

        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);
                        }
//.........这里部分代码省略.........
开发者ID:irfanshah41,项目名称:webhookexample,代码行数:101,代码来源:Service1.svc.cs

示例4: DeleteAsync

        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);
        }
开发者ID:akkadotnet,项目名称:Akka.Persistence.CouchBase,代码行数:24,代码来源:CouchBaseDbSnapshotStore.cs

示例5: DeletePermanentlyMessages

        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);
        }
开发者ID:akkadotnet,项目名称:Akka.Persistence.CouchBase,代码行数:27,代码来源:CouchBaseDbSnapshotStore.cs


注:本文中的Couchbase.N1QL.QueryRequest.AddNamedParameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。