CitectSCADA DataBase
To change the Database Management System, for this article I have selected PostgreSQL, as we have seen SQL Server, MySQL, Oracle where there is a server running and we will access it remotely.
The first step is to install the corresponding Open Database Connectivity (ODBC) Driver to be able to access it.
We can now configure the new Data Source
In the following image, the configuration of two Data Sources appears, one for the PostgreSQL database and one for MySQL. Further explanation follows.
Consulting the documentation of CitectSCADA 2018, these are the methods we can use:
And very importantly, you should know that CitectSCADA has its own Cicode language for scripting and also includes CicodeVBA Visual Basic for Applications.
Cicode, being a proprietary language, has functions that we can use, and for databases, these are some of its functions.
We move on to creating a new function, and with the help of the documentation, this is how it would look. PostgreSQL has a peculiarity; in the definition of SQL statements, fields and table names are enclosed in quotes, and this is a problem in Cicode.
This is the error message when trying to execute the code we have seen.
I have tried several options, but for now, I have no solution.
If we enable the debugger, when we execute the SQLGetRecordset function, we get the following error; this is due to the query we are passing.
This was the reason for later testing with MySQL.
And this was my surprise when I switched to MySQL and enabled the debugger; we can observe:
SQLConnect := Ok!
SQLGetRecordset:= Ok!
SQLRowCount := Ok!
SQLGetField := NoK! (Returns the string with no value)
I don't know if it will be a bug or if I am doing something incorrectly; if you have the solution, please share it for an update.
As we have already mentioned that we have CicodeVBA, now we will create the functions to connect to the Database, but with this language.
These would be the functions, and the result has been perfect; it works perfectly.
We have associated the functions we have seen or procedures to several buttons to check their operation; if you are going to call CicodeVBA code, you must first use the CiVBA function.
However, with Cicode code, the function is called directly.
CONCLUSION: If you are going to work with Databases, it is better to use the CicodeVBA language.
04-06-2019