本文整理汇总了C#中CassandraContext.ExecuteQuery方法的典型用法代码示例。如果您正苦于以下问题:C# CassandraContext.ExecuteQuery方法的具体用法?C# CassandraContext.ExecuteQuery怎么用?C# CassandraContext.ExecuteQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CassandraContext
的用法示例。
在下文中一共展示了CassandraContext.ExecuteQuery方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BigDecimalTest
private static void BigDecimalTest()
{
using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
{
// arrange
db.ExecuteNonQuery("CREATE TABLE OfferReservation2 (KEY text PRIMARY KEY) WITH comparator = text AND default_validation = decimal");
db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key0', 1000000000000000000)");
db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key1', 0.25)");
db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key2', 2000000000000.1234)");
db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key3', -0.25)");
db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key4', -0.25122333)");
var actual = db.ExecuteQuery("SELECT * FROM OfferReservation2");
var results = actual.ToList();
var firstValue = (decimal)results.First(x => x.Key == "Key0")["MyColumn"];
var secondValue = (decimal)results.First(x => x.Key == "Key1")["MyColumn"];
var thirdValue = (decimal)results.First(x => x.Key == "Key2")["MyColumn"];
var fourthValue = (decimal)results.First(x => x.Key == "Key3")["MyColumn"];
var fifthValue = (decimal)results.First(x => x.Key == "Key4")["MyColumn"];
ConsoleHeader("Returned data from Big Decimal Test");
ConsoleHeader(firstValue.ToString());
ConsoleHeader(secondValue.ToString());
ConsoleHeader(thirdValue.ToString());
ConsoleHeader(fourthValue.ToString());
ConsoleHeader(fifthValue.ToString());
}
}
示例2: CreateColumnFamilyWithTimestampOperator
private static void CreateColumnFamilyWithTimestampOperator()
{
using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
{
db.ExecuteNonQuery("CREATE TABLE TestCF2 (KEY text PRIMARY KEY) WITH comparator=timestamp AND default_validation=text;");
DateTimeOffset UnixStart = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
DateTimeOffset TimeNow = DateTimeOffset.UtcNow;
var columnName2 = Convert.ToInt64(Math.Floor((TimeNow - UnixStart).TotalMilliseconds));
var columnName1 = columnName2 + 5000;
db.ExecuteNonQuery(string.Format("INSERT INTO TestCF2 (KEY, {0}, {1}) VALUES ('Key1', 'Value1', 'Value2')", columnName1, columnName2));
List<ICqlRow> rows = db.ExecuteQuery("SELECT * FROM TestCF2 WHERE KEY = 'Key1'").ToList();
DateTime value1 = rows[0].Columns[1].ColumnName.GetValue<DateTime>();
DateTime value2 = rows[0].Columns[2].ColumnName.GetValue<DateTime>();
ConsoleHeader("Returned data from db for timestamp comparator");
ConsoleHeader(value1.ToString());
ConsoleHeader(value2.ToString());
}
}
示例3: Init
public void Init()
{
_context = new CassandraContext(keyspace: DummiesKeySpace, host: "localhost");
if (!_context.KeyspaceExists(DummiesKeySpace))
{
var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
{
Name = DummiesKeySpace,
}, _context);
keyspace.TryCreateSelf();
_context.ExecuteQuery(
@"
CREATE COLUMNFAMILY Dummies (
KEY ascii PRIMARY KEY,
Blob blob
);");
_context.SaveChanges();
}
_dummies = _context.GetColumnFamily("Dummies");
}
示例4: CreateColumnFamilyWithUUIDOperator
private static void CreateColumnFamilyWithUUIDOperator()
{
using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
{
db.ExecuteNonQuery("CREATE TABLE TestCF (KEY text PRIMARY KEY) WITH comparator=uuid AND default_validation=text;");
Guid columnName1 = GuidGenerator.GenerateTimeBasedGuid(DateTime.Now);
Guid columnName2 = GuidGenerator.GenerateTimeBasedGuid(DateTime.Now);
db.ExecuteNonQuery(string.Format("INSERT INTO TestCF (KEY, {0}, {1}) VALUES ('Key1', 'Value1', 'Value2')", columnName1, columnName2));
List<ICqlRow> rows = db.ExecuteQuery("SELECT * FROM TestCF WHERE KEY = 'Key1'").ToList();
Guid value = rows[0].Columns[1].ColumnName.GetValue<Guid>();
ConsoleHeader("Returned data from db");
ConsoleHeader(value.ToString());
}
}
示例5: TombstoneTest
private static void TombstoneTest()
{
using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
{
db.ExecuteNonQuery("CREATE TABLE OfferReservation (KEY int PRIMARY KEY) WITH comparator = text AND default_validation = float");
db.ExecuteNonQuery("INSERT INTO OfferReservation (KEY, '25:100') VALUES (5, 0.25)");
db.ExecuteNonQuery("INSERT INTO OfferReservation (KEY, '25:101') VALUES (5, 0.25)");
db.ExecuteNonQuery("DELETE '25:100' FROM OfferReservation WHERE KEY = 5");
List<ICqlRow> rows = db.ExecuteQuery("SELECT '25:100' FROM OfferReservation WHERE KEY = 5").ToList();
}
}
示例6: ReadAllPosts
private static void ReadAllPosts()
{
using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
{
var key = "first-blog-post";
var tagsFamily = db.GetColumnFamily("Tags");
// get the post back from the database
ConsoleHeader("getting 'first-blog-post'");
// query using CQL
var posts = db.ExecuteQuery("SELECT * FROM Posts LIMIT 25");
// query using API
dynamic tags = tagsFamily.Get(key).FirstOrDefault();
// show details
ConsoleHeader("showing post");
foreach (dynamic post in posts)
{
Console.WriteLine(
String.Format("=={0} by {1}==\n{2}",
post.Title,
post.Author,
post.Body
));
}
// show tags
ConsoleHeader("showing tags");
foreach (var tag in tags)
Console.WriteLine(String.Format("{0}:{1}", tag.ColumnName, tag.ColumnValue));
}
}
示例7: GetJob
public static CassandraJob GetJob(CassandraContext db, int hide_time_sec)
{
loop:
dynamic job = null;
for (int i = 0; i < 1000; i++)
{
var jobs = db.ExecuteQuery(SelectCQL_Main(1000)).ToArray();
var mx = jobs.Length < 1000 ? jobs.Length - 1 : 1000;
if (mx == -1)
break;
job = jobs[rnd.Value.Next(mx)];
if (job["hidden_till"] < ToUnixTime(DateTimeOffset.UtcNow))
break;
}
if (job != null)
{
var myID = Guid.NewGuid();
var ret = new CassandraJob(job, myID);
db.ExecuteNonQuery(HideRowCQL_Trans(ret.GetID(), ret.GetAckID()));
var cnt = db.ExecuteQuery(SelectCQL_Trans(ret.GetID(), 1000)).ToArray();
var counter = cnt.First()["count"];
if (counter > 1)
{
db.ExecuteNonQuery(DeleteRowCQL_Trans(ret.GetID()));
goto loop;
}
if (counter == 0)
goto loop;
db.ExecuteNonQuery(HideRowCQL_Main2(ret.GetID(), hide_time_sec,ret.GetLogic(),ret.GetCommand()));
return ret;
}
else
return null;
}
示例8: Test
//.........这里部分代码省略.........
while (true)
{
var job = GetJob(db, 10);
if (job != null)
{
Console.Write("-");
if (job.GetLogic() == null || job.GetCommand() == null)
Console.WriteLine("Error");
DeleteJob(db, job);
}
else
{
lock (alive_monitor)
{
if (!alive_condition)
return;
else
Monitor.Wait(alive_monitor, TimeOut_Sec * 1000);
}
}
}
}
finally
{
Console.Write("(~" + thrNo + ")");
}
});
threads.Add(thr);
thr.Start();
}
for (int tI = 0; tI < ThreadCount2; tI++)
{
int thrNo = tI;
var thr = new Thread(() =>
{
Console.Write("<*" + thrNo + ">");
try
{
CassandraContext db = new CassandraContext(new ConnectionBuilder(keyspace: KeyspaceName, server: Server, cqlVersion: CqlVersion.Cql3, pooling: usePooling));
lock (thrStarted_monitor)
{
thrStarted_cnt++;
Monitor.PulseAll(thrStarted_monitor);
}
while (true)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 100; i++)
sb.AppendLine(Guid.NewGuid().ToString());
AddJob(db, sb.ToString(), Guid.NewGuid().ToString());
Console.Write("+");
Thread.Sleep(100);
lock (alive_monitor)
{
if (!alive_condition)
return;
}
}
}
finally
{
Console.Write("<~" + thrNo + ">");
}
});
threads.Add(thr);
thr.Start();
}
while (true)
{
lock (thrStarted_monitor)
{
Monitor.Wait(thrStarted_monitor);
if (thrStarted_cnt == ThreadCount+ThreadCount2)
break;
}
}
//wait for ten minutes
Thread.Sleep(TestTimeInMinutes * 60 * 1000);
lock (alive_monitor)
{
alive_condition = false;
Monitor.PulseAll(alive_monitor);
}
foreach (var thr in threads)
{
thr.Join();
}
var j = main_db.ExecuteQuery(SelectCQL_Main(1)).ToArray();
var c = main_db.ExecuteQuery(SelectCQL_Trans(1)).ToArray();
if (j.Count() > 0 || c.Count() > 0)
Console.WriteLine("Error");
Console.WriteLine("Finished");
}