SQL usage in TradeDesign

Base concept

One of the base ideas of TradeDesign is, that the database and access to the database should be transparent for the application developer.

Thus standard application development should not care about the currently used database. The database connection is defined in the TradeDesign configuration files tdpara.ini and tdodbc.ini.

In addition it is needed to define the ODBC datasource as defined in tdpara.ini if Trade2 or tdodbc is used. This is not needed for installations running with tdoci.

Good praxis is to access the database ONLY with the relevant TradeDesign commands (s)DBRead, (s)DBInsert, (s)DBUpdate, DBHold, DBFetch(stream), …

DBExecutesql(var)

Only in case of complex selections e.g. if one select needs to combine access to several tables there is also the option to use the commands DBExecuteSQL and DBExecutesqlvar. Out of those two the better candidate is DBExecutesqlvar, as with this command bind is used, which makes the database access much more performant.

Please avoid other commands as SELECT in direct SQL. Especially updating database entries with direct UPDATE can easily break the application. Any update through DBUpdate respects the TradeDesign locking. Thus is a record is currently locked by another session it can not be updated. Direct updates will ignore the locking.

Even if the currently used database type can be retrieved it should be avoided to write datbase specific SQLs. E.g. this makes it dangerous for productive installations to move the application from one database to another (e.g. Oracle to PostGreSQL).

Some databases have some restrictions for SQLs. Please always use the standard which is supported by all databases.

Special restriction for MariaDB and MySQL:

Both databases can not deal with the command SELECT COUNT(*) with spaces somewhere. Correct is to write

DBExecutesql (“select count(*) FROM …”)