Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

support quoting of table names in LINQ-to-CQL3 fixes #102 and leaves …

…4 failing tests for #107
  • Loading branch information...
commit 6edd84cbaf2a16a1c3f6e047345169e0be4c9f6b 1 parent 5f7c914
@nberardi nberardi authored
View
6 src/Linq/CqlObjectQuery.cs
@@ -56,7 +56,8 @@ IEnumerator IEnumerable.GetEnumerator()
/// <returns></returns>
public IEnumerator<T> GetEnumerator()
{
- var result = CqlQueryEvaluator.GetCql(Expression);
+ var cqlVersion = _family.Context.ConnectionBuilder.CqlVersion;
+ var result = CqlQueryEvaluator.GetCql(Expression, cqlVersion);
var fluentObjects = _family.Context.ExecuteQuery(result);
var serializer = ObjectSerializerFactory.Get(typeof(T));
@@ -114,7 +115,8 @@ public IQueryProvider Provider
/// <returns></returns>
public override string ToString()
{
- return CqlQueryEvaluator.GetCql(Expression);
+ var cqlVersion = _family.Context.ConnectionBuilder.CqlVersion;
+ return CqlQueryEvaluator.GetCql(Expression, cqlVersion);
}
}
}
View
6 src/Linq/CqlQuery.cs
@@ -45,7 +45,8 @@ IEnumerator IEnumerable.GetEnumerator()
/// <returns></returns>
public IEnumerator<ICqlRow> GetEnumerator()
{
- var result = CqlQueryEvaluator.GetCql(Expression);
+ var cqlVersion = _provider.Context.ConnectionBuilder.CqlVersion;
+ var result = CqlQueryEvaluator.GetCql(Expression, cqlVersion);
return Provider.Context.ExecuteQuery(result).GetEnumerator();
}
@@ -105,7 +106,8 @@ IQueryProvider IQueryable.Provider
/// <returns></returns>
public override string ToString()
{
- return CqlQueryEvaluator.GetCql(Expression);
+ var cqlVersion = _provider.Context.ConnectionBuilder.CqlVersion;
+ return CqlQueryEvaluator.GetCql(Expression, cqlVersion);
}
}
}
View
15 src/Linq/CqlQueryEvaluator.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
+using FluentCassandra.Connections;
using FluentCassandra.Types;
using FluentCassandra.ObjectSerializer;
@@ -13,6 +14,7 @@ namespace FluentCassandra.Linq
internal class CqlQueryEvaluator
{
private string _columnFamily;
+ private string _cqlVersion;
private CassandraColumnFamilySchema _schema;
internal CqlQueryEvaluator()
@@ -26,7 +28,7 @@ public string Query
get
{
var select = Fields;
- var from = _columnFamily;
+ var from = QuoteIfNessisary(_columnFamily);
var where = WhereCriteria;
var orderBy = OrderBy;
var limit = LimitCount;
@@ -46,6 +48,14 @@ public string Query
}
}
+ private string QuoteIfNessisary(string s)
+ {
+ if (_cqlVersion == CqlVersion.Cql3)
+ return '"' + s + '"';
+
+ return s;
+ }
+
private IList<string> SelectFieldsArray { get; set; }
private IList<string> OrderByFieldsArray { get; set; }
@@ -185,9 +195,10 @@ private string GetPropertyName(Expression exp)
#region Expression Parsing
- public static string GetCql(Expression expression)
+ public static string GetCql(Expression expression, string cqlVersion)
{
var eval = new CqlQueryEvaluator();
+ eval._cqlVersion = cqlVersion;
eval.Evaluate(expression);
return eval.Query;
View
2  src/Linq/ICassandraColumnFamilyInfo.cs
@@ -3,7 +3,7 @@
namespace FluentCassandra.Linq
{
- public interface ICassandraColumnFamilyInfo
+ internal interface ICassandraColumnFamilyInfo
{
string FamilyName { get; }
CassandraColumnFamilySchema GetSchema();
View
40 test/FluentCassandra.Tests/Bugs/Issue61SuperColumnRangeSliceKeyBackwards.cs
@@ -30,40 +30,38 @@ public void Test_GetRangeSlice()
// create column family using API
_db.TryDropColumnFamily("supercolumns");
- keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema
- {
- FamilyName = "supercolumns",
- FamilyType = ColumnType.Super,
- KeyValueType = CassandraType.UTF8Type,
- SuperColumnNameType = CassandraType.TimeUUIDType,
- ColumnNameType = CassandraType.UTF8Type,
- DefaultColumnValueType = CassandraType.UTF8Type
- });
+ keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
+ FamilyName = "supercolumns",
+ FamilyType = ColumnType.Super,
+ KeyValueType = CassandraType.UTF8Type,
+ SuperColumnNameType = CassandraType.TimeUUIDType,
+ ColumnNameType = CassandraType.UTF8Type,
+ DefaultColumnValueType = CassandraType.UTF8Type
+ });
- InsertData("testKey");
+ InsertData("testKey");
// act
- var actual = _db.GetSuperColumnFamily("supercolumns").Get().TakeKeys(5);
+ var actual = _db.GetSuperColumnFamily("supercolumns").Get().TakeKeys(5);
// assert
Assert.NotNull(actual);
Assert.Equal(1, actual.Count());
- Assert.Equal("testKey", actual.First().Key.ToString());
+ Assert.Equal("testKey", actual.First().Key.ToString());
}
public void InsertData(string key)
{
var productFamily = _db.GetSuperColumnFamily("supercolumns");
- var post = productFamily.CreateRecord(key);
- _db.Attach(post);
-
- for (int i = 0; i < 4; i++)
- {
- dynamic d = post.CreateSuperColumn(GuidGenerator.GenerateTimeBasedGuid(DateTimeOffset.Now.Subtract(TimeSpan.FromSeconds(i))));
- d.columnone = Guid.NewGuid().ToString();
- d.columntwo = Guid.NewGuid().ToString();
- }
+ var post = productFamily.CreateRecord(key);
+ _db.Attach(post);
+
+ for (int i = 0; i < 4; i++) {
+ dynamic d = post.CreateSuperColumn(GuidGenerator.GenerateTimeBasedGuid(DateTimeOffset.Now.Subtract(TimeSpan.FromSeconds(i))));
+ d.columnone = Guid.NewGuid().ToString();
+ d.columntwo = Guid.NewGuid().ToString();
+ }
_db.SaveChanges();
}
View
6 test/FluentCassandra.Tests/Linq/LinqToCqlObjectsTests.cs
@@ -23,10 +23,10 @@ public class User
public LinqToCqlObjectsTests()
{
- var keyspaceName = ConfigurationManager.AppSettings["TestKeySpace"];
- var server = new Server(ConfigurationManager.AppSettings["TestServer"]);
+ var keyspaceName = ConfigurationManager.AppSettings["TestKeySpace"];
+ var server = new Server(ConfigurationManager.AppSettings["TestServer"]);
- _db = new CassandraContext(keyspace: keyspaceName, server: server);
+ _db = new CassandraContext(new ConnectionBuilder(keyspace: keyspaceName, server: server, cqlVersion: CqlVersion.Cql));
_family = _db.GetColumnFamily<AsciiType>("Users");
}
View
2  test/FluentCassandra.Tests/Linq/LinqToCqlTests.cs
@@ -18,7 +18,7 @@ public LinqToCqlTests()
var keyspaceName = ConfigurationManager.AppSettings["TestKeySpace"];
var server = new Server(ConfigurationManager.AppSettings["TestServer"]);
- _db = new CassandraContext(keyspace: keyspaceName, server: server);
+ _db = new CassandraContext(new ConnectionBuilder(keyspace: keyspaceName, server: server, cqlVersion: CqlVersion.Cql));
_family = _db.GetColumnFamily<AsciiType>("Users");
}
View
12 test/FluentCassandra.Tests/Operations/Cql3Test.cs
@@ -45,14 +45,11 @@ public void TestLinq()
{
// arrange
var insertQuery = @"INSERT INTO ""Users"" (""Id"", ""Name"", ""Email"", ""Age"") VALUES (23, '" + new String('X', 200) + "', 'test@test.com', 43)";
-
- // act
_db.ExecuteNonQuery(insertQuery);
+ // act
var table = _db.GetColumnFamily("Users");
-
var q = from row in table select row;
-
var actual = q.ToList();
// assert
@@ -60,21 +57,18 @@ public void TestLinq()
}
/// <summary>
- /// Count() is not woriking
+ /// Count() is not working
/// </summary>
[Fact]
public void TestLinq_CountDoNotWork()
{
// arrange
var insertQuery = @"INSERT INTO ""Users"" (""Id"", ""Name"", ""Email"", ""Age"") VALUES (23, '" + new String('X', 200) + "', 'test@test.com', 43)";
-
- // act
_db.ExecuteNonQuery(insertQuery);
+ // act
var table = _db.GetColumnFamily("Users");
-
var q = from row in table select row;
-
var actualCount = q.Count();
// assert
View
2  test/FluentCassandra.Tests/Operations/CqlTest.cs
@@ -11,7 +11,7 @@ public class CqlTest : IUseFixture<CassandraDatabaseSetupFixture>, IDisposable
public void SetFixture(CassandraDatabaseSetupFixture data)
{
- var setup = data.DatabaseSetup();
+ var setup = data.DatabaseSetup(cqlVersion: CqlVersion.Cql);
_db = setup.DB;
}
Please sign in to comment.
Something went wrong with that request. Please try again.