DataBase access from the client

From both client and designer java applications how to get the JDBC driver from the default database ?

It is possible to get the database name from clientContext.getDefaultDatasourceName();

But how to perform an SQL query to that base ?

You send a message to the gateway instructing it to run the query there.

Something like:

GatewayConnection gatewayConnection = GatewayConnectionManager.getInstance();
GatewayInterface gatewayInterface = gatewayConnection.getGatewayInterface();
Dataset dataset = gatewayInterface.runQuery(...);

Do you mean that there is no other way to do than making a RPC call to to gateway, to have it calling de database ?
This seems heavy !
Isn’t another way to access the Ignition history ?

This design means that:

  1. a client doesn’t need to be on the same network or have access to databases directly.
  2. you don’t end up with N-connectiosn-per-client, completely overloading your database.

Access to history, DB, etc… is all done by querying the gateway if you’re programming in the client.

Thanks Kevin !

I though an API could have been available in the client to access the history so it could be easy to have an historic plotting.

Right now I have a gateway driver that create an OPC tree.
From the OPC I created TAGs (manually) in the designer interface so that they have historic.

I succeed in creating the TAGs from the gateway module, but I have been unable to get them historic.

How can I retrieve the historic values of a Tag from the gateway?
Is there a difference on how they were created (gateway/designer)?

If it seems difficult I will directly access the SQLserver base which seems a lot easier than using the APIs because I have no ideas on how they work.

If you could give me an example of a module that creates a TAG with an historic, retrieves values from the historic, it would be wonderful!
And if the example shows how to add missing values in the historic it would be perfect!

Hi,

Let me try to make sure I understand the question, and then there are probably a few different suggestions that can be made. This thread seems to talk about two subjects that seem related, but are actually quite different: Querying the database, and retrieving tag history. Even though tag history is stored in a database, the query mechanism is different.

You have tags, and you’ve configured them to store history with the tag history feature. You now want to query these in the client… in java, with the API, correct?

In both cases, I think the best way would be to use the GatewayInterface, which you can get with:

GatewayConnectionManager.getInstance().getGatewayInterface()

For tag history, you would use [tt]runTagHistoryQuery()[/tt], for the db, you would use one of the other [tt]runQuery()[/tt] type functions.

Regards,

That’s really interesting, I thought I had to create RPC calls to get to the gateway !
I’ll test it quickly !

This answers to my main question that is to get Tag history from the client.

I used the function, but all the fields in my Dataset are null…

I did not used any aggregate, so I put null. it seems to work as far as I get a Dataset with rows…
But it contains nothing…