本文整理汇总了C#中Session.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# Session.Execute方法的具体用法?C# Session.Execute怎么用?C# Session.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Session
的用法示例。
在下文中一共展示了Session.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateChart
public Chart CreateChart(string code)
{
code = "Chart CreateChart() { Chart chart = new Chart(); " + code + " return chart; }";
session = engine.CreateSession();
session.Execute(code);
return (Chart) session.Execute("CreateChart()");
}
示例2: createSchema
public static void createSchema(Session session, int replicationFactor)
{
session.Cluster.WaitForSchemaAgreement(
session.Execute(String.Format(TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT, TestUtils.SIMPLE_KEYSPACE, replicationFactor), ConsistencyLevel.All).QueriedHost);
session.ChangeKeyspace(TestUtils.SIMPLE_KEYSPACE);
session.Cluster.WaitForSchemaAgreement(
session.Execute(String.Format("CREATE TABLE {0} (k int PRIMARY KEY, i int)", TABLE)).QueriedHost);
}
示例3: createMultiDCSchema
public static void createMultiDCSchema(Session session, int dc1RF = 1, int dc2RF = 1)
{
session.Cluster.WaitForSchemaAgreement(
session.Execute(String.Format(TestUtils.CREATE_KEYSPACE_GENERIC_FORMAT, TestUtils.SIMPLE_KEYSPACE, "NetworkTopologyStrategy", string.Format("'dc1' : {0}, 'dc2' : {1}", dc1RF, dc2RF))).QueriedHost);
session.ChangeKeyspace(TestUtils.SIMPLE_KEYSPACE);
session.Cluster.WaitForSchemaAgreement(
session.Execute(String.Format("CREATE TABLE {0} (k int PRIMARY KEY, i int)", TABLE)).QueriedHost);
}
示例4: mixedDurationTestCCM
public void mixedDurationTestCCM()
{
if (CCMCluster != null)
CCMCluster.Discard();
CCMCluster = CCMBridge.CCMCluster.Create(3, Cluster.Builder());
cluster = CCMCluster.Cluster;
session = CCMCluster.Session;
session.CreateKeyspace("large_data", ReplicationStrategies.CreateSimpleStrategyReplicationProperty(3));
session.ChangeKeyspace("large_data");
session.Cluster.WaitForSchemaAgreement(
session.Execute(String.Format("CREATE TABLE {0} (k INT, i INT, PRIMARY KEY(k, i))", "wide_rows")).QueriedHost);
session.Cluster.WaitForSchemaAgreement(
session.Execute(String.Format("CREATE TABLE {0} (k INT, i INT, PRIMARY KEY(k, i))", "wide_batch_rows")).QueriedHost);
session.Cluster.WaitForSchemaAgreement(
session.Execute(String.Format("CREATE TABLE {0} (k INT, i BLOB, PRIMARY KEY(k, i))", "wide_byte_rows")).QueriedHost);
session.Cluster.WaitForSchemaAgreement(
session.Execute(String.Format("CREATE TABLE {0} (k int PRIMARY KEY, i text)", "large_text")).QueriedHost);
// Create the extra wide table definition
StringBuilder tableDeclaration = new StringBuilder();
tableDeclaration.Append("CREATE TABLE wide_table (");
tableDeclaration.Append("k INT PRIMARY KEY");
for (int i = 0; i < 330; ++i)
{
tableDeclaration.Append(String.Format(", {0} INT", createColumnName(i)));
}
tableDeclaration.Append(")");
session.Cluster.WaitForSchemaAgreement(
session.Execute(tableDeclaration.ToString()).QueriedHost
);
Random rndm = new Random(DateTime.Now.Millisecond);
try
{
for (int i = 0; i < 10; ++i)
{
switch ((int)rndm.Next(0,5))
{
case 0: testWideRows(); break;
case 1: testWideBatchRows(); break;
case 2: testByteRows(); break;
case 3: testLargeText(); break;
case 4: testWideTable(); break;
default: break;
}
}
}
catch (Exception e)
{
CCMCluster.ErrorOut();
throw e;
}
finally
{
CCMCluster.Discard();
}
}
示例5: ExecutePreparedQuery
internal static void ExecutePreparedQuery(Session session, PreparedStatement prepared, object[] values, ConsistencyLevel consistency = ConsistencyLevel.Default, string messageInstead = null)
{
if (messageInstead != null)
Console.WriteLine("CQL<\t" + messageInstead);
else
Console.WriteLine("CQL< Executing Prepared Query:\t");
session.Execute(prepared.Bind(values).SetConsistencyLevel(consistency));
Console.WriteLine("CQL> (OK).");
}
示例6: Execute
public IOpohoReportCommand Execute(Session session)
{
try
{
var result = session.Execute(_code);
if (result is IOpohoReportCommand) return result as IOpohoReportCommand;
return null;
}
catch (Exception ex)
{
return new ReportStringCommand(ex.Message);
}
}
示例7: AssertCompilationError
internal static void AssertCompilationError(Session session, string code, params DiagnosticDescription[] expectedDiagnostics)
{
bool noException = false;
try
{
session.Execute(code);
noException = true;
}
catch (CompilationErrorException e)
{
e.Diagnostics.Verify(expectedDiagnostics);
e.Diagnostics.Any(d => d.Severity == DiagnosticSeverity.Error && e.Message == d.ToString());
}
Assert.False(noException);
}
示例8: Execute
protected virtual object Execute(string code, Session session)
{
return session.Execute(code);
}
示例9: parallelInsertTestGeneric
public void parallelInsertTestGeneric(int nThreads, int cpCon)
{
CCMBridge.ReusableCCMCluster.Setup(1);
string datacenter = "datacenter1";
long constDelayMS = 100;
int queryTimeout = 50000;
int coreConnectionPerHost = 64;
int maxConnectionPerHost = 64;
CCMBridge.ReusableCCMCluster.Build(initialize(datacenter, constDelayMS, queryTimeout, coreConnectionPerHost, maxConnectionPerHost,cpCon));
Session = CCMBridge.ReusableCCMCluster.Connect("tester");
Console.WriteLine("Start parallel insert test (" + nThreads + " , " + cpCon + ")");
string keyspaceName = "testkeyspace1" + nThreads + "x" + cpCon;
// Console.WriteLine("Creating keyspace");
Session.Cluster.WaitForSchemaAgreement(
Session.Execute(
string.Format(@"CREATE KEYSPACE {0}
WITH replication = {{ 'class' : 'SimpleStrategy', 'replication_factor' : 1 }};"
, keyspaceName)));
Session.ChangeKeyspace(keyspaceName);
string tableName = "testtable";
try
{
Session.Cluster.WaitForSchemaAgreement(
Session.Execute(string.Format(@"CREATE TABLE {0}(
tweet_id int,
author text,
body text,
isok boolean,
PRIMARY KEY(tweet_id))", tableName)));
}
catch (AlreadyExistsException)
{ }
// Console.WriteLine("Prepare statement");
PreparedStatement insertPrep = Session.Prepare("INSERT INTO " + tableName + @" (
tweet_id,
author,
isok,
body)
VALUES (?,?,?,?);");
// Console.WriteLine("Insert Values");
int RowsNo = 100000;
int stepSize = RowsNo / nThreads;
Thread[] tasks = new Thread[nThreads];
object monit = new object();
int readyCnt = 0;
for (int i = 0; i < nThreads; i++)
{
var startIndex = i * stepSize;
var endIndex = (i + 1) * stepSize;
tasks[i] = new Thread(() =>
{
lock (monit)
{
readyCnt++;
Monitor.Wait(monit);
}
insertRange(insertPrep, startIndex, endIndex);
});
tasks[i].Start();
}
Stopwatch t = Stopwatch.StartNew();
lock (monit)
{
while (true)
{
if (readyCnt < nThreads)
{
Monitor.Exit(monit);
Thread.Sleep(100);
Monitor.Enter(monit);
}
else
{
t.Restart();
Monitor.PulseAll(monit);
break;
}
}
}
foreach (var task in tasks)
task.Join();
Console.WriteLine("Avg query response time " + ((double)totalElapsedTime) / (double)RowsNo + "ms");
Console.WriteLine("Avg single insert time " + ((double)t.ElapsedMilliseconds) / (double)RowsNo + "ms");
//using (var res = Session.Execute(string.Format(@"SELECT COUNT(*) FROM {0} LIMIT {1}", tableName, RowsNo + 100), ConsistencyLevel.Quorum))
//{
// var cnt = res.GetRows().FirstOrDefault().GetValue<long>(0);
// Assert.Equal(RowsNo, cnt);
//}
Session.Execute(string.Format(@"DROP TABLE {0};", tableName));
//.........这里部分代码省略.........
示例10: ExecuteBuildsAndExecutesCommandNotInTransaction
public void ExecuteBuildsAndExecutesCommandNotInTransaction()
{
var sqlQuery = new SqlQuery("");
var result = 1;
var mockCommand = new Mock<IDbCommand>();
mockCommand.Setup(x => x.ExecuteNonQuery()).Returns(result);
mockCommand.As<IDisposable>().Setup(x => x.Dispose());
var mockSqlDialect = new Mock<ISqlDialect>();
var mockDbDriver = new Mock<IDbDriver>();
mockDbDriver.Setup(x => x.GetConnection(ConnectionScope.PerTransaction)).Returns(new Mock<IDbConnection>().Object);
mockDbDriver.Setup(x => x.BuildCommand(It.IsNotNull<SqlQuery>())).Returns(mockCommand.Object);
var session = new Session(
ConnectionScope.PerTransaction,
mockSqlDialect.Object,
mockDbDriver.Object,
new IListener[0]);
Assert.Equal(result, session.Execute(sqlQuery));
mockDbDriver.VerifyAll();
mockCommand.VerifyAll();
}
示例11: Execute
protected virtual void Execute(string code, Session session)
{
session.Execute(code);
}
示例12: createMultiDCSchema
private void createMultiDCSchema(Session session)
{
session.Execute(String.Format(TestUtils.CREATE_KEYSPACE_GENERIC_FORMAT, TestUtils.SIMPLE_KEYSPACE, "NetworkTopologyStrategy", "'dc1' : 1, 'dc2' : 1"));
session.ChangeKeyspace(TestUtils.SIMPLE_KEYSPACE);
session.Execute(String.Format("CREATE TABLE {0} (k int PRIMARY KEY, i int)", TABLE));
}
示例13: ExecuteSyncQuery
internal static void ExecuteSyncQuery(Session session, string query, List<object[]> expectedValues = null, ConsistencyLevel consistency = ConsistencyLevel.Default, string messageInstead = null)
{
if (messageInstead != null)
Console.WriteLine("CQL<\t" + messageInstead);
else
Console.WriteLine("CQL< Query:\t" + query);
if (expectedValues != null)
using (var ret = session.Execute(query, consistency))
valueComparator(ret, expectedValues);
using (var ret = session.Execute(query, consistency))
ret.PrintTo(stream: Console.Out, cellEncoder: CellEncoder);
Console.WriteLine("CQL> Done.");
}
示例14: ExecuteSyncNonQuery
internal static IPAddress ExecuteSyncNonQuery(Session session, string query, string messageInstead = null, ConsistencyLevel consistency = ConsistencyLevel.Default)
{
if (messageInstead != null)
Console.WriteLine("CQL<\t" + messageInstead);
else
Console.WriteLine("CQL< Query:\t" + query);
var ret = session.Execute(query, consistency);
Console.WriteLine("CQL> (OK).");
return ret.Info.QueriedHost;
}
示例15: ExecuteThrowsObjectDisposedExceptionIfDisposed
public void ExecuteThrowsObjectDisposedExceptionIfDisposed()
{
var session = new Session(
ConnectionScope.PerTransaction,
new Mock<ISqlDialect>().Object,
new Mock<IDbDriver>().Object,
new IDeleteListener[0],
new IInsertListener[0],
new IUpdateListener[0]);
using (session)
{
}
Assert.Throws<ObjectDisposedException>(() => session.Execute(new SqlQuery("SELECT")));
}