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


C# SimpleStatement类代码示例

本文整理汇总了C#中SimpleStatement的典型用法代码示例。如果您正苦于以下问题:C# SimpleStatement类的具体用法?C# SimpleStatement怎么用?C# SimpleStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: BatchMixedStatements

        public void BatchMixedStatements()
        {
            foreach (var protocolVersion in ProtocolVersionSupported)
            {
                //Use all possible protocol versions
                Cluster.MaxProtocolVersion = protocolVersion;
                //Use a local cluster
                var localCluster = Cluster.Builder().AddContactPoint(IpPrefix + "1").Build();
                var localSession = localCluster.Connect("tester");
                var tableName = "table" + Guid.NewGuid().ToString("N").ToLower();
                CreateTable(tableName);

                var simpleStatement =
                    new SimpleStatement(String.Format("INSERT INTO {0} (id, label, number) VALUES ({1}, {2}, {3})", tableName, 1, "label", 2));
                var ps = localSession.Prepare(string.Format(@"INSERT INTO {0} (id, label, number) VALUES (?, ?, ?)", tableName));
                var batchStatement = new BatchStatement();
                var expectedValues = new List<object[]> {new object[] {1, "label", 2}, new object[] {1, "test", 2}};

                batchStatement.Add(ps.Bind(new object[] {1, "test", 2}));
                batchStatement.Add(simpleStatement);

                var rs = localSession.Execute("SELECT * FROM " + tableName);
                VerifyData(rs, expectedValues);
            }
        }
开发者ID:rasmus-s,项目名称:csharp-driver,代码行数:25,代码来源:BatchStatements.cs

示例2: TokenAware_TargetPartition_NoHops

        public void TokenAware_TargetPartition_NoHops()
        {
            // Setup
            PolicyTestTools policyTestTools = new PolicyTestTools();
            ITestCluster testCluster = TestClusterManager.CreateNew(3);
            testCluster.Builder = Cluster.Builder().WithLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()));
            testCluster.InitClient();

            // Test
            policyTestTools.TableName = TestUtils.GetUniqueTableName();
            policyTestTools.CreateSchema(testCluster.Session, 1);
            var traces = new List<QueryTrace>();
            for (var i = -10; i < 10; i++)
            {
                var partitionKey = BitConverter.GetBytes(i).Reverse().ToArray();
                var statement = new SimpleStatement(String.Format("INSERT INTO " + policyTestTools.TableName + " (k, i) VALUES ({0}, {0})", i))
                    .SetRoutingKey(new RoutingKey() { RawRoutingKey = partitionKey })
                    .EnableTracing();
                var rs = testCluster.Session.Execute(statement);
                traces.Add(rs.Info.QueryTrace);
            }
            //Check that there weren't any hops
            foreach (var t in traces)
            {
                //The coordinator must be the only one executing the query
                Assert.True(t.Events.All(e => e.Source.ToString() == t.Coordinator.ToString()), "There were trace events from another host for coordinator " + t.Coordinator);
            }
        }
开发者ID:jorgebay,项目名称:csharp-driver,代码行数:28,代码来源:LoadBalancingPolicyShortTests.cs

示例3: RequestHandlerRetryDecisionTest

        public void RequestHandlerRetryDecisionTest()
        {
            var statement = new SimpleStatement("SELECT WILL FAIL");
            var request = Session.GetRequest(statement);
            var requestHandler = new RequestHandler<RowSet>(Session, request, statement);

            //Using default retry policy the decision will always be to rethrow on read/write timeout
            var expected = RetryDecision.RetryDecisionType.Rethrow;
            var decision = requestHandler.GetRetryDecision(new ReadTimeoutException(ConsistencyLevel.Quorum, 1, 2, true));
            Assert.AreEqual(expected, decision.DecisionType);
            
            decision = requestHandler.GetRetryDecision(new WriteTimeoutException(ConsistencyLevel.Quorum, 1, 2, "SIMPLE"));
            Assert.AreEqual(expected, decision.DecisionType);

            decision = requestHandler.GetRetryDecision(new UnavailableException(ConsistencyLevel.Quorum, 2, 1));
            Assert.AreEqual(expected, decision.DecisionType);

            decision = requestHandler.GetRetryDecision(new Exception());
            Assert.AreEqual(expected, decision.DecisionType);

            //Expecting to retry when a Cassandra node is Bootstrapping/overloaded
            expected = RetryDecision.RetryDecisionType.Retry;
            decision = requestHandler.GetRetryDecision(new OverloadedException(null));
            Assert.AreEqual(expected, decision.DecisionType);
            decision = requestHandler.GetRetryDecision(new IsBootstrappingException(null));
            Assert.AreEqual(expected, decision.DecisionType);
            decision = requestHandler.GetRetryDecision(new TruncateException(null));
            Assert.AreEqual(expected, decision.DecisionType);
        }
开发者ID:Virus-X,项目名称:csharp-driver,代码行数:29,代码来源:RequestHandlerTests.cs

示例4: RequestHandler_GetRequest_SimpleStatement_Default_QueryOptions_Are_Used

 public void RequestHandler_GetRequest_SimpleStatement_Default_QueryOptions_Are_Used()
 {
     var stmt = new SimpleStatement("DUMMY QUERY");
     Assert.AreEqual(0, stmt.PageSize);
     Assert.Null(stmt.ConsistencyLevel);
     var request = (QueryRequest)RequestHandler<RowSet>.GetRequest(stmt, 2, GetConfig());
     Assert.AreEqual(DefaultQueryOptions.GetPageSize(), request.PageSize);
     Assert.AreEqual(DefaultQueryOptions.GetConsistencyLevel(), request.Consistency);
 }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:9,代码来源:RequestHandlerTests.cs

示例5: SimpleStatementNamedValuesNotSpecifiedTest

        public void SimpleStatementNamedValuesNotSpecifiedTest()
        {
            var insertQuery = String.Format("INSERT INTO {0} (float_sample, text_sample, bigint_sample, id) VALUES (:MY_float, :my_TexT, :my_BIGint, :id)", AllTypesTableName);
            var statement = new SimpleStatement(insertQuery);

            Assert.Throws<InvalidQueryException>(() => Session.Execute(
                statement.Bind(
                    new {id = Guid.NewGuid(), my_bigint = 1L })));
        }
开发者ID:rasmus-s,项目名称:csharp-driver,代码行数:9,代码来源:ParameterizedStatementsTests.cs

示例6: Parallel_Insert_And_Select_Sync

        public void Parallel_Insert_And_Select_Sync()
        {
            var originalTraceLevel = Diagnostics.CassandraTraceSwitch.Level;
                        ITestCluster testCluster = TestClusterManager.GetTestCluster(3);
            Diagnostics.CassandraTraceSwitch.Level = TraceLevel.Warning;
            testCluster.Builder = Cluster.Builder().WithRetryPolicy(DowngradingConsistencyRetryPolicy.Instance);
            testCluster.InitClient();

            ISession session = testCluster.Session;
            string uniqueKsName = "keyspace_" + Randomm.RandomAlphaNum(10);
            session.Execute(@"CREATE KEYSPACE " + uniqueKsName +
                            " WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};");
            TestUtils.WaitForSchemaAgreement(testCluster.Cluster);
            session.ChangeKeyspace(uniqueKsName);

            string tableName = "table_" + Guid.NewGuid().ToString("N").ToLower();
            session.Execute(String.Format(TestUtils.CREATE_TABLE_TIME_SERIES, tableName));
            TestUtils.WaitForSchemaAgreement(testCluster.Cluster);

            var insertQuery = String.Format("INSERT INTO {0} (id, event_time, text_sample) VALUES (?, ?, ?)", tableName);
            var insertQueryPrepared = session.Prepare(insertQuery);
            var selectQuery = String.Format("SELECT * FROM {0} LIMIT 10000", tableName);

            const int rowsPerId = 1000;
            object insertQueryStatement = new SimpleStatement(insertQuery);
            if (CassandraVersion.Major < 2)
            {
                //Use prepared statements all the way as it is not possible to bind on a simple statement with C* 1.2
                insertQueryStatement = session.Prepare(insertQuery);
            }
            var actionInsert = GetInsertAction(session, insertQueryStatement, ConsistencyLevel.Quorum, rowsPerId);
            var actionInsertPrepared = GetInsertAction(session, insertQueryPrepared, ConsistencyLevel.Quorum, rowsPerId);
            var actionSelect = GetSelectAction(session, selectQuery, ConsistencyLevel.Quorum, 10);

            //Execute insert sync to have some records
            actionInsert();
            //Execute select sync to assert that everything is going OK
            actionSelect();


            var actions = new List<Action>();
            for (var i = 0; i < 10; i++)
            {
                //Add 10 actions to execute
                actions.AddRange(new[] {actionInsert, actionSelect, actionInsertPrepared});
                actions.AddRange(new[] {actionSelect, actionInsert, actionInsertPrepared, actionInsert});
                actions.AddRange(new[] {actionInsertPrepared, actionInsertPrepared, actionSelect});
            }
            //Execute in parallel the 100 actions
            var parallelOptions = new ParallelOptions();
            parallelOptions.TaskScheduler = new ThreadPerTaskScheduler();
            parallelOptions.MaxDegreeOfParallelism = 300;
            Parallel.Invoke(parallelOptions, actions.ToArray());
            Parallel.Invoke(actions.ToArray());
            Diagnostics.CassandraTraceSwitch.Level = originalTraceLevel;
        }
开发者ID:Virus-X,项目名称:csharp-driver,代码行数:56,代码来源:StressTests.cs

示例7: SimpleStatementSetTimestamp

 public void SimpleStatementSetTimestamp()
 {
     var timestamp = new DateTimeOffset(1999, 12, 31, 1, 2, 3, TimeSpan.Zero);
     var id = Guid.NewGuid();
     var insertStatement = new SimpleStatement(String.Format("INSERT INTO {0} (id, text_sample) VALUES (?, ?)", AllTypesTableName), id, "sample text");
     Session.Execute(insertStatement.SetTimestamp(timestamp));
     var row = Session.Execute(new SimpleStatement(String.Format("SELECT id, text_sample, writetime(text_sample) FROM {0} WHERE id = ?", AllTypesTableName), id)).First();
     Assert.NotNull(row.GetValue<string>("text_sample"));
     Assert.AreEqual(TypeCodec.ToUnixTime(timestamp).Ticks / 10, row.GetValue<object>("writetime(text_sample)"));
 }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:10,代码来源:ParameterizedStatementsTests.cs

示例8: SimpleStatement_Default_QueryOptions_Are_Used

 public void SimpleStatement_Default_QueryOptions_Are_Used()
 {
     var stmt = new SimpleStatement("DUMMY QUERY");
     Assert.AreEqual(0, stmt.PageSize);
     Assert.Null(stmt.ConsistencyLevel);
     var session = GetInstance();
     var request = (QueryRequest)session.GetRequest(stmt);
     Assert.AreEqual(DefaultQueryOptions.GetPageSize(), request.PageSize);
     Assert.AreEqual(DefaultQueryOptions.GetConsistencyLevel(), request.Consistency);
 }
开发者ID:Virus-X,项目名称:csharp-driver,代码行数:10,代码来源:SessionUnitTests.cs

示例9: Query_Payload_Test

 public void Query_Payload_Test()
 {
     var outgoing = new Dictionary<string, byte[]> { { "k1", Encoding.UTF8.GetBytes("value1") }, { "k2", Encoding.UTF8.GetBytes("value2") } };
     var stmt = new SimpleStatement("SELECT * FROM system.local");
     stmt.SetOutgoingPayload(outgoing);
     var rs = Session.Execute(stmt);
     Assert.NotNull(rs.Info.IncomingPayload);
     Assert.AreEqual(outgoing.Count, rs.Info.IncomingPayload.Count);
     CollectionAssert.AreEqual(outgoing["k1"], rs.Info.IncomingPayload["k1"]);
     CollectionAssert.AreEqual(outgoing["k2"], rs.Info.IncomingPayload["k2"]);
 }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:11,代码来源:CustomPayloadTests.cs

示例10: InternalExecuteAsync

 protected override Task<RowSet> InternalExecuteAsync()
 {
     if (_batchScript.Length == 0)
     {
         return TaskHelper.FromException<RowSet>(new RequestInvalidException("The Batch must contain queries to execute"));
     }
     string cqlQuery = GetCql();
     var stmt = new SimpleStatement(cqlQuery);
     this.CopyQueryPropertiesTo(stmt);
     return _session.ExecuteAsync(stmt);
 }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:11,代码来源:BatchV1.cs

示例11: RequestHandler_GetRequest_SimpleStatement_QueryOptions_Are_Used

 public void RequestHandler_GetRequest_SimpleStatement_QueryOptions_Are_Used()
 {
     var stmt = new SimpleStatement("DUMMY QUERY");
     Assert.AreEqual(0, stmt.PageSize);
     Assert.Null(stmt.ConsistencyLevel);
     var queryOptions = new QueryOptions().SetConsistencyLevel(ConsistencyLevel.LocalQuorum).SetPageSize(100);
     var request = (QueryRequest)RequestHandler<RowSet>.GetRequest(stmt, 2, GetConfig(queryOptions));
     Assert.AreEqual(100, request.PageSize);
     Assert.AreEqual(queryOptions.GetPageSize(), request.PageSize);
     Assert.AreEqual(queryOptions.GetConsistencyLevel(), request.Consistency);
     Assert.AreEqual(ConsistencyLevel.Any, request.SerialConsistency);
 }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:12,代码来源:RequestHandlerTests.cs

示例12: Warnings_With_Tracing_Test

 public void Warnings_With_Tracing_Test()
 {
     const string query = "BEGIN UNLOGGED BATCH INSERT INTO {0} (k, t) VALUES ('{1}', '{2}') APPLY BATCH";
     SimpleStatement insert = new SimpleStatement(String.Format(query, Table, "warn1", String.Join("", Enumerable.Repeat("a", 5 * 1025))));
     var rs = Session.Execute(insert.EnableTracing());
     
     Assert.NotNull(rs.Info.Warnings);
     Assert.NotNull(rs.Info.QueryTrace);
     Assert.AreEqual(1, rs.Info.Warnings.Length);
     StringAssert.Contains("batch", rs.Info.Warnings[0].ToLowerInvariant());
     StringAssert.Contains("exceeding", rs.Info.Warnings[0].ToLowerInvariant());
 }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:12,代码来源:ClientWarningsTests.cs

示例13: SimpleStatement_QueryOptions_Are_Used

 public void SimpleStatement_QueryOptions_Are_Used()
 {
     var stmt = new SimpleStatement("DUMMY QUERY");
     Assert.AreEqual(0, stmt.PageSize);
     Assert.Null(stmt.ConsistencyLevel);
     var queryOptions = new QueryOptions().SetConsistencyLevel(ConsistencyLevel.LocalQuorum).SetPageSize(100);
     var session = GetInstance(queryOptions);
     var request = (QueryRequest)session.GetRequest(stmt);
     Assert.AreEqual(100, request.PageSize);
     Assert.AreEqual(queryOptions.GetPageSize(), request.PageSize);
     Assert.AreEqual(queryOptions.GetConsistencyLevel(), request.Consistency);
     Assert.AreEqual(ConsistencyLevel.Any, request.SerialConsistency);
 }
开发者ID:Virus-X,项目名称:csharp-driver,代码行数:13,代码来源:SessionUnitTests.cs

示例14: EncodeDecodeTupleAsNestedTest

        public void EncodeDecodeTupleAsNestedTest()
        {
            var achievements = new List<Tuple<string, int>>
            {
                new Tuple<string, int>("What", 1),
                new Tuple<string, int>(null, 100),
                new Tuple<string, int>(@"¯\_(ツ)_/¯", 150)
            };
            var insert = new SimpleStatement("INSERT INTO users_tuples (id, achievements) values (?, ?)");
            Session.Execute(insert.Bind(31, achievements));
            var row = Session.Execute("SELECT * FROM users_tuples WHERE id = 31").First();

            Assert.AreEqual(achievements, row.GetValue<List<Tuple<string, int>>>("achievements"));
        }
开发者ID:rasmus-s,项目名称:csharp-driver,代码行数:14,代码来源:TupleTests.cs

示例15: Parallel_Insert_And_Select_Sync

        public void Parallel_Insert_And_Select_Sync()
        {
            var testCluster = TestClusterManager.GetNonShareableTestCluster(3, 1, true, false);
            using (var cluster = Cluster.Builder()
                                        .WithRetryPolicy(AlwaysRetryRetryPolicy.Instance)
                                        .AddContactPoint(testCluster.InitialContactPoint)
                                        .Build())
            {
                var session = cluster.Connect();
                var uniqueKsName = "keyspace_" + Randomm.RandomAlphaNum(10);
                session.Execute(@"CREATE KEYSPACE " + uniqueKsName +
                                " WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};");
                session.ChangeKeyspace(uniqueKsName);

                var tableName = "table_" + Guid.NewGuid().ToString("N").ToLower();
                session.Execute(String.Format(TestUtils.CREATE_TABLE_TIME_SERIES, tableName));

                var insertQuery = String.Format("INSERT INTO {0} (id, event_time, text_sample) VALUES (?, ?, ?)", tableName);
                var insertQueryPrepared = session.Prepare(insertQuery);
                var selectQuery = String.Format("SELECT * FROM {0} LIMIT 10000", tableName);

                const int rowsPerId = 1000;
                object insertQueryStatement = new SimpleStatement(insertQuery);
                if (CassandraVersion.Major < 2)
                {
                    //Use prepared statements all the way as it is not possible to bind on a simple statement with C* 1.2
                    insertQueryStatement = session.Prepare(insertQuery);
                }
                var actionInsert = GetInsertAction(session, insertQueryStatement, ConsistencyLevel.Quorum, rowsPerId);
                var actionInsertPrepared = GetInsertAction(session, insertQueryPrepared, ConsistencyLevel.Quorum, rowsPerId);
                var actionSelect = GetSelectAction(session, selectQuery, ConsistencyLevel.Quorum, 10);

                //Execute insert sync to have some records
                actionInsert();
                //Execute select sync to assert that everything is going OK
                actionSelect();


                var actions = new List<Action>();
                for (var i = 0; i < 10; i++)
                {
                    //Add 10 actions to execute
                    actions.AddRange(new[] {actionInsert, actionSelect, actionInsertPrepared});
                    actions.AddRange(new[] {actionSelect, actionInsert, actionInsertPrepared, actionInsert});
                    actions.AddRange(new[] {actionInsertPrepared, actionInsertPrepared, actionSelect});
                }
                //Execute in parallel the 100 actions
                TestHelper.ParallelInvoke(actions.ToArray());
            }
        }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:50,代码来源:StressTests.cs


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