test and bug fixes for data queries
This commit is contained in:
parent
3a9137fa08
commit
22ca94e36e
|
@ -102,7 +102,7 @@ void add_bool_constraint_to_query(Query &query, Predicate::Operator operatorType
|
||||||
void add_string_constraint_to_query(Query &query,
|
void add_string_constraint_to_query(Query &query,
|
||||||
Predicate::Operator op,
|
Predicate::Operator op,
|
||||||
Columns<String> &&column,
|
Columns<String> &&column,
|
||||||
std::string value) {
|
std::string &&value) {
|
||||||
bool case_sensitive = true;
|
bool case_sensitive = true;
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case Predicate::Operator::BeginsWith:
|
case Predicate::Operator::BeginsWith:
|
||||||
|
@ -127,7 +127,7 @@ void add_string_constraint_to_query(Query &query,
|
||||||
|
|
||||||
void add_string_constraint_to_query(realm::Query &query,
|
void add_string_constraint_to_query(realm::Query &query,
|
||||||
Predicate::Operator op,
|
Predicate::Operator op,
|
||||||
std::string value,
|
std::string &&value,
|
||||||
Columns<String> &&column) {
|
Columns<String> &&column) {
|
||||||
bool case_sensitive = true;
|
bool case_sensitive = true;
|
||||||
switch (op) {
|
switch (op) {
|
||||||
|
@ -145,22 +145,22 @@ void add_string_constraint_to_query(realm::Query &query,
|
||||||
void add_binary_constraint_to_query(Query &query,
|
void add_binary_constraint_to_query(Query &query,
|
||||||
Predicate::Operator op,
|
Predicate::Operator op,
|
||||||
Columns<Binary> &&column,
|
Columns<Binary> &&column,
|
||||||
std::string value) {
|
std::string &&value) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case Predicate::Operator::BeginsWith:
|
case Predicate::Operator::BeginsWith:
|
||||||
query.begins_with(column.m_column, value);
|
query.begins_with(column.m_column, BinaryData(value));
|
||||||
break;
|
break;
|
||||||
case Predicate::Operator::EndsWith:
|
case Predicate::Operator::EndsWith:
|
||||||
query.ends_with(column.m_column, value);
|
query.ends_with(column.m_column, BinaryData(value));
|
||||||
break;
|
break;
|
||||||
case Predicate::Operator::Contains:
|
case Predicate::Operator::Contains:
|
||||||
query.contains(column.m_column, value);
|
query.contains(column.m_column, BinaryData(value));
|
||||||
break;
|
break;
|
||||||
case Predicate::Operator::Equal:
|
case Predicate::Operator::Equal:
|
||||||
query.equal(column.m_column, value);
|
query.equal(column.m_column, BinaryData(value));
|
||||||
break;
|
break;
|
||||||
case Predicate::Operator::NotEqual:
|
case Predicate::Operator::NotEqual:
|
||||||
query.not_equal(column.m_column, value);
|
query.not_equal(column.m_column, BinaryData(value));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw std::runtime_error("Unsupported operator for binary queries.");
|
throw std::runtime_error("Unsupported operator for binary queries.");
|
||||||
|
@ -173,10 +173,10 @@ void add_binary_constraint_to_query(realm::Query &query,
|
||||||
Columns<Binary> &&column) {
|
Columns<Binary> &&column) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case Predicate::Operator::Equal:
|
case Predicate::Operator::Equal:
|
||||||
query.equal(column.m_column, value);
|
query.equal(column.m_column, BinaryData(value));
|
||||||
break;
|
break;
|
||||||
case Predicate::Operator::NotEqual:
|
case Predicate::Operator::NotEqual:
|
||||||
query.not_equal(column.m_column, value);
|
query.not_equal(column.m_column, BinaryData(value));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw std::runtime_error("Substring comparison not supported for keypath substrings.");
|
throw std::runtime_error("Substring comparison not supported for keypath substrings.");
|
||||||
|
|
|
@ -13,6 +13,7 @@ var testCases = require('./queryTests.json');
|
||||||
|
|
||||||
var typeConverters = {};
|
var typeConverters = {};
|
||||||
typeConverters[Realm.Types.DATE] = function(value) { return new Date(value); };
|
typeConverters[Realm.Types.DATE] = function(value) { return new Date(value); };
|
||||||
|
typeConverters[Realm.Types.DATA] = function(value) { return new Uint8Array(value); };
|
||||||
|
|
||||||
function runQuerySuite(suite) {
|
function runQuerySuite(suite) {
|
||||||
var realm = new Realm({schema: suite.schema});
|
var realm = new Realm({schema: suite.schema});
|
||||||
|
@ -84,6 +85,9 @@ module.exports = BaseTest.extend({
|
||||||
testStringQueries: function() {
|
testStringQueries: function() {
|
||||||
runQuerySuite(testCases.stringTests);
|
runQuerySuite(testCases.stringTests);
|
||||||
},
|
},
|
||||||
|
testBinaryQueries: function() {
|
||||||
|
runQuerySuite(testCases.binaryTests);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -202,6 +202,29 @@
|
||||||
["Disabled", "QueryCount", 4, "StringObject", "stringCol ENDSWITH[c] 'c'"],
|
["Disabled", "QueryCount", 4, "StringObject", "stringCol ENDSWITH[c] 'c'"],
|
||||||
["Disabled", "QueryCount", 2, "StringObject", "stringCol CONTAINS[c] 'B'"]
|
["Disabled", "QueryCount", 2, "StringObject", "stringCol CONTAINS[c] 'B'"]
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
"binaryTests" : {
|
||||||
|
"schema" : [{
|
||||||
|
"name": "BinaryObject",
|
||||||
|
"properties": [{ "name": "binaryCol", "type": "data" }]
|
||||||
|
}],
|
||||||
|
"objects": [
|
||||||
|
{ "type": "BinaryObject", "value": [[1, 100, 233, 255, 0]] },
|
||||||
|
{ "type": "BinaryObject", "value": [[1, 100]] },
|
||||||
|
{ "type": "BinaryObject", "value": [[100]] },
|
||||||
|
{ "type": "BinaryObject", "value": [[]] },
|
||||||
|
{ "type": "BinaryObject", "value": [[255, 0]] }
|
||||||
|
],
|
||||||
|
"tests": [
|
||||||
|
["QueryCount", 1, "BinaryObject", "binaryCol == $0", [1, 0]],
|
||||||
|
["QueryCount", 1, "BinaryObject", "$0 == binaryCol", [2, 0]],
|
||||||
|
["QueryCount", 4, "BinaryObject", "binaryCol != $0", [0, 0]],
|
||||||
|
["QueryCount", 1, "BinaryObject", "binaryCol BEGINSWITH $0", [0, 0]],
|
||||||
|
["QueryCount", 2, "BinaryObject", "binaryCol BEGINSWITH $0", [1, 0]],
|
||||||
|
["QueryCount", 2, "BinaryObject", "binaryCol ENDSWITH $0", [4, 0]],
|
||||||
|
["QueryCount", 3, "BinaryObject", "binaryCol CONTAINS $0", [2, 0]]
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue