Skip to content

Commit

Permalink
Fix: query to not return #id when JSONPath does not match
Browse files Browse the repository at this point in the history
  • Loading branch information
rzander committed Feb 7, 2018
1 parent ffc8df4 commit 3ad33dc
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions source/jaindb/jaindb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,13 +1133,24 @@ public static JArray query(string paths, string select)
JObject oRes = new JObject();
foreach (string sAttrib in select.Split(','))
{
oRes.Add(sAttrib.Trim(), jObj[sAttrib]);
//var jVal = jObj[sAttrib];
var jVal = jObj.SelectToken(sAttrib);

if (jVal != null)
oRes.Add(sAttrib.Trim(), jVal);
}
foreach (string path in paths.Split(','))
foreach (string path in paths.Split(';'))
{
try
{
var oToks = jObj.SelectTokens(path.Trim(), false);

if (oToks.Count() == 0)
{
oRes = new JObject(); //remove selected attributes as we do not have any vresults from jsonpath
continue;
}

foreach (JToken oTok in oToks)
{
try
Expand All @@ -1165,15 +1176,18 @@ public static JArray query(string paths, string select)
}
catch(Exception ex)
{
ex.Message.ToString();
Debug.WriteLine("Error Query_5: " + ex.Message.ToString());
}

}

/*if (oToks.Count() == 0)
oRes = null; */
oRes = new JObject(); */
}
catch(Exception ex)
{
Debug.WriteLine("Error Query_5: " + ex.Message.ToString());
}
catch { }
}
if (oRes.HasValues)
{
Expand All @@ -1182,7 +1196,10 @@ public static JArray query(string paths, string select)
//i++;
}
}
catch { }
catch (Exception ex)
{
Debug.WriteLine("Error Query_5: " + ex.Message.ToString());
}
}

return aRes;
Expand Down

0 comments on commit 3ad33dc

Please # to comment.