Using Firedac For MongoDB's Time Range Query - c++

I has one question about time range query.
Here is my code:
TMongoPipeline* MGPipeline = new TMongoPipeline(FEnv);
MGPipeline->Match()->Doc->AsJSON="{DayTime:{$gt:ISODate(\"2000-11-02T17:04:11.102Z\")}}"; ^^^^^^^^^
where DayTime field's Data type is Date
Compile is ok, but it always throw an exception as like this:
project TestC.cpp raised exception class EJSONReaderException with message 'Cannot read Infinity value' Path 'DayTime', line 1, position 9'.
I also tried another code:
TMongoPipeline* MGPipeline = new TMongoPipeline(FEnv);
MGPipeline->Match()->Doc->AsJSON="{DayTime:{$gt:new Date(2001,1,1)}}";
^^^^^^^^^
But it throw exception,too.
TestC.cpp raised exception class $C0000094 with message 'integer divide by zero at 0x50096'
My MongoDB version is 3.0.
Now I can't do any time range query.
Can tell me anyway to do that by using FireDac and Rad Studio XE10?

You should use Extended JSON:
MGPipeline->Match()->Doc->AsJSON="{DayTime:{$gt:{\"$date\":\"2000-11-02T17:04:11.102Z\"}}}";

Related

Netowrkx len() command giving a 'str' object error

To start, I created a Network using 2014 flight data as explained here:https://ipython-books.github.io/142-drawing-flight-routes-with-networkx/
I'm trying to create smaller graphs using airline specific flight paths to test connectivity within each business, starting with American Airlines, I did the following:
AASys = routes[
routes['source'].isin(airports_us.index) &
routes['dest'].isin(airports_us.index) &
routes['airline'].str.contains('AA')]
AASys
AAedges = AASys[['source', 'dest']].values
AAedges
AAg = nx.from_edgelist(AAedges)
len(AAg.nodes()), len(AAg.edges())
This mirrors the tutorial input almost exactly, with the only change being the additional str.contains('AA'). But when I try to test the len() of my new database, I get -- TypeError: 'str' object is not callable.
Can anyone explain why my edgelist is reading as a string? How to I fix the TypeError?

OCaml: define composite exception type with line number information

I am working on some OCaml code and I would like to define a composite exception type; as follows:
type exceptbase = string * string
exception UndefinedTyp of exceptbase
I would like the first element of such exception to be the line number information.
However, when I use some exception handling code below, it cannot be compiled.
raise UndefinedTyp (__LOC__, "some exception messages")
So here are my questions:
How to correctly define such composite exception type?
Note that since the first element is always the __LOC__, is there any way I can save the effort and use __LOC__ to pre-occupy the first element?
On the second point, within the vanilla OCaml, I am afraid it is impossible to omit __LOC__ argument.
But you can write a perprocessor to rewrite Undefined "some exception message" to Undefined (__LOC__, "some exception message"). Today we use PPX framework to write such a preprocessor.
BTW, OCaml's exception backtrace contains the location of raised exceptions. Setting environment variable OCAMLRUNPARAM=b, OCaml runtime prints it with source code locations when an uncaught exception terminates the program. Programatically Printexc module provides some APIs to obtain it.
You just need some parentheses:
# type exceptbase = string * string
exception UndefinedTyp of exceptbase;;
type exceptbase = string * string
exception UndefinedTyp of exceptbase
# raise (UndefinedTyp (__LOC__, "some exception message"));;
Exception:
UndefinedTyp
("File \"//toplevel//\", line 2, characters -13--6",
"some exception message").

Missing descriptor exception while using Eclipselink Expressionbuilder

I have an entity Person with fields String name and String designation. When I tried to query using Eclipselink ExpressionBuilder, as:
Project project=new Project();
Login login=new DatabaseLogin();
login.setUserName("root");
login.setPassword("root");
project.setLogin(login);
DatabaseSession session=project.createDatabaseSession();
ExpressionBuilder expBuilder=new ExpressionBuilder();
Expression expression=expBuilder.get("name").equalsIgnoreCase("SomeName");
Vector readAllObjects = session.readAllObjects(Person.class, expression);
On executing last statement the following exception is thrown :
Exception [EclipseLink-6007] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.QueryException
Exception Description: Missing descriptor for [class com.mycompany.entity.Person].
Query: ReadAllQuery(referenceClass=Person)
What might be the reason? Thanks in advance...
At last I got it. Instead of DatabaseSession, org.eclipse.persistence.sessions.server.ClientSession had to be used.
JpaEntityManager jpaEntityManager=em.unwrap(JpaEntityManager.class);
ClientSession session=jpaEntityManager.getServerSession().acquireClientSession();
ExpressionBuilder expBuilder=new ExpressionBuilder();
Expression expression=expBuilder.get("name").equalsIgnoreCase("SomeName");
Vector readAllObjects = session.readAllObjects(Person.class, expression);
em is the EntityManager.
This solved the issue.
You did not add a descriptor for Person. You need to map it to be able to query it.
Also consider using JPA.

Sitecore Fast Query Gives Parse Exception

Why am I getting this error with the code below ParseException: End of string expected at position 4.
Here's the code: The error is on the 3rd line.
var db = Sitecore.Configuration.Factory.GetDatabase("web");
string query = #"fast:/sitecore/content/foodservice/home/Products/3492-5326/3518-7";
Item item = db.SelectSingleItem(query);
return item;
Can we use a fast query with SelectSingleItem()? I was trying to avoid the get folder contents and loop through each item until I find the target solution. Suggestions?
When using Sitecore Query, you need to escape item names with dashes. From SDN:
Items with dashes in names (“-”) should be included in “#” symbols. Please use such syntax: /sitecore/content/Home/#About-us#. Otherwise you may get the following error: Invalid lookup source "/sitecore/content/TestSiteB/Home/About-us": End of string expected at position 38. Also, an item name should be included in “#” symbols if it contains “and” or “or” word and is used before “//” symbols. For example: "/sitecore/content/Home/#news and events#//".
UPDATE:
I have confirmed that this applies to Fast Query as well.
End of string expected at position 27.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Sitecore.Data.Query.ParseException: End of string expected at position 27.
Source Error:
Line 21: protected void Page_Load(object sender, EventArgs e)
Line 22: {
Line 23: Sitecore.Context.Database.SelectSingleItem("fast:/sitecore/Content/Home/Test-Item");
Line 24:
Line 25: Model = Sitecore.Context.Item;
The same code runs fine with #escapes#:
Sitecore.Context.Database.SelectSingleItem("fast:/sitecore/Content/Home/#Test-Item#");
This is a bug when using Fast Query and SelectSingleItem(). The issue is fixed in the Sitecore CMS 6.3.0 rev.100716 release. See Release Notes. Since we are using 6.2, I had to rewrite my method to use a Sitecore Query instead of the Fast Query.

Null Reference Excepion when saving data on subsonic 3

I am testing subsonic 3, i can query my database but when i am inserting a record i have an exception. Here is my code:
Client lClient = new Client();
lClient.Name = "Peter";
lClient.FullName = "Richards";
lCliente.Save();
And i have a null reference exception on this generated code:
var newKey=_repo.Add(this,provider);
Any help is appreciated.
I am using ActiveRecords
I had a similar problem, with code not unlike the following:
var pending = myTable.SingleOrDefault(x => x.Id == 1);
if (pending == null)
pending = new myTable();
pending.Id = 1;
pending.MyDate = DateTime.Now;
pending.MyString = someString;
pending.Save();
This worked the first time I ran it, on an empty table, but not the second time when updating. I got a nullreference exception somewhere inside the subsonic repository. The solution was to add a primary key, as Rob suggested.
Just thought I'd mention it (thanks Rob).
Where does the null reference exception actually happen? Is _repo null?
Try and double check that you don’t have any columns in the “Client” table which are not nullable and you don’t set any value.
Also make sure you PK is handled correctly (check you have the [Property.IsForeignKey=true;] attribute)
Do you have NullReferenceException Checked in (file menu) Debug -> Exceptions (press Find and type NullReferenceException, press OK)?
I downloaded the SubSonic code and used it as reference for my project, the exception is thrown in SubSonic.Core\Repository\SubSonicRepository.cs:209 because prop is not checked for null at line 208, and any exceptions are swallowed as evidenced by line 213.
What happens is visual studio breaks on all the exceptions checked in the mentioned dialog. So in one way, this is the expected behaviour from the code.
What actually causes prop to become null, in my case, the table field name is lower-case, but the property is actually cased properly.
From Immediate:
tbl.PrimaryKey.Name
"playerinformationid"
item.GetType().GetProperties()
{System.Reflection.PropertyInfo[11]}
[0]: {System.Collections.Generic.IList`1[SubSonic.Schema.IColumn] Columns}
// *snip*
[5]: {Int32 PlayerInformationid}
// *snip*
item.GetType().GetProperty("PlayerInformationid")
{Int32 PlayerInformationid} // Works!
item.GetType().GetProperty(tbl.PrimaryKey.Name)
null
I hacked this together to "just make it work" (Warning: newbie at 3.5 stuff)
-var prop = item.GetType().GetProperty(tbl.PrimaryKey.Name);
+var lowerCasedPrimaryKeyName = tbl.PrimaryKey.Name.ToLowerInvariant();
+var prop = item.GetType().GetProperties().First<System.Reflection.PropertyInfo>(x => x.Name.ToLowerInvariant() == lowerCasedPrimaryKeyName);
Does your table have a PrimaryKey? It doesn't sound like it does. If not - this is your problem.