Below is the driver interface that defines
the driver names
, the
connect_parameters
used by
adding a datasource (see Section 10.1.3.1)
and the driver methods.
struct ocrpt_input { const char **names; const ocrpt_input_connect_parameter **connect_parameters; bool (*connect)(ocrpt_datasource *ds, const ocrpt_input_connect_parameter *params); ocrpt_query *(*query_add_sql)(ocrpt_datasource *ds, const char *name, const char *sql); ocrpt_query *(*query_add_file)(ocrpt_datasource *ds, const char *name, const char *filename, const int32_t *types, int32_t types_cols); ocrpt_query *(*query_add_data)(ocrpt_datasource *ds, const char *name, const void *data, int32_t rows, int32_t cols, const int32_t *types, int32_t types_cols); ocrpt_query *(*query_add_symbolic_data)( ocrpt_datasource *ds, const char *name, const char *dataname, int32_t rows, int32_t cols, const char *types, int32_t types_cols); void (*describe)(ocrpt_query *query, ocrpt_query_result **result, int32_t *result_cols); bool (*refresh)(ocrpt_query *query); void (*rewind)(ocrpt_query *query); bool (*next)(ocrpt_query *query); bool (*populate_result)(ocrpt_query *query); bool (*isdone)(ocrpt_query *query); void (*free)(ocrpt_query *query); bool (*set_encoding)(ocrpt_datasource *ds, const char *encoding); void (*close)(const ocrpt_datasource *); }; typedef struct ocrpt_input ocrpt_input;
The driver names
is a NULL-terminated
array of name strings. This allows the driver to be picked up
using either name. For example the built-in MariaDB
driver does so:
static const char * ocrpt_mariadb_input_names[] = { "mariadb", "mysql", NULL };
The connect_parameters
data pointer
and the connect
method are either
both set as valid, or both are NULL.
The query_add*()
methods are
optional. Some datasource drivers support direct or
symbolic data, some support file formats, some are
SQL based. A datasource input driver must support at
least one of the interfaces.
The describe()
method is mandatory.
It returns an array of ocrpt_query_result
data together with the number of columns in the result
set. The result array must contain elements 3 times the
number of columns in total due to the internal
operation of OpenCReports.
#define OCRPT_EXPR_RESULTS (3)
The refresh()
method is optional.
See the PHP module source code for its potential uses.
The rewind()
,
next()
,
populate_result()
and
isdone()
methods are all mandatory
as they are required to traverse the result set.
The free()
method is optional.
It's needed if the query uses private data.
The set_encoding()
method is
optional. It's needed if the datasource input driver
can use data in encodings other than
UTF-8
.
The close()
method is optional.
It's needed if the datasource connection uses
private data.