DeviceSQL Interfaces
DeviceSQL provides three different application programming interfaces for data management functions and services:
- Developer-Defined API
- Dynamic C API
- Interpreted SQL API
With these APIs, you can easily match interfaces with your application requirements. For example, if speed is the most important issue for part of the application, then the Developer-Defined API is best. If it is more important to support ad hoc SQL statements, then the Interpreted SQL API should be used. Regardless, all three interfaces can be used separately or together, even in the same application.
Developer-Defined API
The Developer-Defined API lets you define the names for functions written in the DeviceSQL language so they can be called from your C application. In the below example, you can see how the DeviceSQL function “FindContact” is exposed using the “EXPORT NAME” clause so that it can be called from the C application as “dm_FindContact.”
| |
DeviceSQL Function |
|
| |
..
CREATE FUNCTION FindContact(
pPhone PHONECHAR,
pName OUT VARCHAR)
RETURN INT32
AS
EXPORT NAME “dm_FindContact”;
BEGIN
SELECT Name INTO pName
FROM Contacts
WHERE Phone = pPhone;
EXCEPTION
WHEN NO_ROWS_FOUND THEN
..
|
|
| |
C Interface Function to Call |
|
| |
int32 dm_FindContact(
char * pPhone,
char * pName);
|
|
The Developer-Defined API provides the fastest performance, best determinism and smallest memory footprint of the three DeviceSQL APIs. This is because the DeviceSQL Compiler can analyze your schema and functions at build time to generate the fastest, most memory-efficient code and data accesses possible. Optimal determinism is achieved by using direct C function calls that bypass the need for runtime parsing and interpretation.
Another advantage of the Developer-Defined API is that it makes it easier to upgrade existing applications. If you are trying to upgrade/replace an in-house database, tables or other functions, you can give the DeviceSQL-enabled versions the exact same interface as the existing versions to simplify integration.
Dynamic C API
DeviceSQL’s Dynamic C API provides a low-level C interface for access to data and services. You can use the Dynamic C API to perform basic data manipulation and control routines, such as inserting data, deleting data, backing up data, searching, and obtaining search results. It also provides increased flexibility for changing data, such as changing schemas, creating new tables and fields, etc., at runtime. Although not as fast as pre-compiled operation with the Developer-Defined API, the Dynamic C API still provides excellent performance.
| |
C Interfaces for the Dynamic C API |
|
| |
edb_dyn_Insert(…) edb_dyn_Delete(…) edb_dyn_Select(…) edb_dyn_GetNextRow() edb_CreateIndex(…) |
|
Interpreted SQL API
The Interpreted SQL API enables ad hoc SQL statements to be processed and executed. Internally, this interface is built on DeviceSQL’s Dynamic C API and contains all its capabilities.
SQL statements using this interface require parsing before execution so this interface is the slowest of the three DeviceSQL interfaces. However, it still provides much faster performance than SQL statements in pre-packaged embedded database technologies.
| |
C Interfaces for the Interpreted SQL API |
|
| |
edb_sql_Exec(“INSERT into MyTab edb_sql_Exec(“DELETE from MyTab edb_sql_Exec(“SELECT * from MyT edb_sql_QueryResults(…) |
|
Want to know more about DeviceSQL APIs? You can:
- Visit the Downloads page and download a copy of the DeviceSQL Language Reference Manual
- Visit DevZone and download a copy of the DeviceSQL Quick Start Suite
- Ask the experts at Encirq, info@encirq.com or 1-650-292-3535