18 #if defined(_WIN32) || defined(_WIN64) 25 #include <libxml/parser.h> 26 #include <libxml/tree.h> 27 #include <libxml/xpath.h> 29 #include <libxslt/xslt.h> 30 #include <libxslt/transform.h> 31 #include <libxslt/xsltutils.h> 37 #include <sqlite3ext.h> 38 static SQLITE_EXTENSION_INIT1
136 sqlite3_vtab **vtabp,
char **errp)
138 int rc = SQLITE_ERROR;
141 xt = sqlite3_malloc(
sizeof (
XTAB));
144 *errp = sqlite3_mprintf(
"out of memory");
147 memset(xt, 0,
sizeof (
XTAB));
153 xt->
idocs = sqlite3_malloc(xt->
sdoc * sizeof (
int));
158 rc = sqlite3_declare_vtab(db,
160 " DOCID INTEGER PRIMARY KEY," 163 " OPTIONS HIDDEN INTEGER," 164 " ENCODING HIDDEN TEXT," 165 " BASEURL HIDDEN TEXT," 166 " XMLDUMP HIDDEN TEXT" 168 if (rc != SQLITE_OK) {
169 sqlite3_free(xt->
idocs);
171 *errp = sqlite3_mprintf(
"table definition failed (error %d)", rc);
192 const char *
const *argv,
193 sqlite3_vtab **vtabp,
char **errp)
212 sqlite3_mutex_enter(xm->
mutex);
213 for (i = 0; xm->
docs && (i < xt->
ndoc); i++) {
215 if ((n >= 0) && (n < xm->
sdoc)) {
228 sqlite3_mutex_leave(xm->
mutex);
230 sqlite3_free(xt->
idocs);
268 xpath_open(sqlite3_vtab *vtab, sqlite3_vtab_cursor **cursorp)
270 XCSR *xc = sqlite3_malloc(
sizeof (
XCSR));
299 xmlXPathFreeObject(xp->
pobj);
302 xmlXPathFreeContext(xp->
pctx);
332 xmlNodePtr node, parent = 0;
337 if (xp == xc->
first) {
339 }
else if (parent != xp->parent) {
350 if (xp->pobj && (xp->pobj->type == XPATH_NODESET) &&
351 xp->pobj->nodesetval) {
352 newpos = xp->
pos + 1;
353 if (newpos < xp->pobj->nodesetval->nodeNr) {
354 node = xp->pobj->nodesetval->nodeTab[newpos];
355 if (node->parent != xp->parent) {
364 if ((pchg != 0) && (pchg != xc->
nexpr)) {
367 if (xp->pobj && (xp->pobj->type == XPATH_NODESET) &&
368 xp->pobj->nodesetval) {
369 newpos = xp->
pos + 1;
370 if (newpos < xp->pobj->nodesetval->nodeNr) {
371 node = xp->pobj->nodesetval->nodeTab[newpos];
372 if (node->parent == xp->parent) {
377 xp->pos = xp->pobj->nodesetval->nodeNr;
388 if (xp->pobj && (xp->pobj->type == XPATH_NODESET) &&
389 xp->pobj->nodesetval) {
390 newpos = xp->
pos + 1;
391 if (newpos < xp->pobj->nodesetval->nodeNr) {
395 xp->pos = xp->pobj->nodesetval->nodeNr;
427 const char *idxStr,
int argc, sqlite3_value **argv)
468 sqlite3_result_error(ctx,
"column out of bounds", -1);
473 if (xm->docs[n].doc) {
474 sqlite3_result_int(ctx, n + 1);
479 if (xm->docs[n].doc) {
483 xmlDocDumpFormatMemoryEnc(xm->docs[n].doc, &dump,
484 &dump_len,
"utf-8", 1);
486 sqlite3_result_text(ctx, (
char *) dump, dump_len,
493 sqlite3_result_null(ctx);
512 if (xm->docs[n].doc) {
513 *rowidp = (sqlite3_int64) (n + 1);
551 sqlite3_int64 *rowidp)
553 int n = -1, rc = SQLITE_ERROR;
556 xmlDocPtr
doc = 0, docToFree = 0;
562 n = sqlite3_value_int(argv[0]);
563 for (i = 0; i < xt->
ndoc; i++) {
564 if ((n - 1) == xt->
idocs[i]) {
567 (xt->
ndoc - (i + 1)) * sizeof (
int));
572 if ((k >= 0) && xm->
mutex) {
577 }
else if ((argc > 1) && (sqlite3_value_type(argv[0]) == SQLITE_NULL)) {
580 int opts = (XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NONET);
583 if (sqlite3_value_type(argv[1]) != SQLITE_NULL) {
585 sqlite3_free(vtab->zErrMsg);
587 vtab->zErrMsg = sqlite3_mprintf(
"ROWID must be NULL");
588 rc = SQLITE_CONSTRAINT;
591 if (sqlite3_value_type(argv[2]) != SQLITE_NULL) {
592 docid = sqlite3_value_int(argv[2]);
593 if ((sqlite3_value_type(argv[3]) != SQLITE_NULL) ||
594 (sqlite3_value_type(argv[4]) != SQLITE_NULL)) {
596 sqlite3_free(vtab->zErrMsg);
598 vtab->zErrMsg = sqlite3_mprintf(
"XML and PATH must be NULL");
599 rc = SQLITE_CONSTRAINT;
602 sqlite3_mutex_enter(xm->
mutex);
603 for (i = 0; xm->
docs && (i < xt->
ndoc); i++) {
604 if ((docid - 1) == xt->
idocs[i]) {
605 sqlite3_mutex_leave(xm->
mutex);
607 sqlite3_free(vtab->zErrMsg);
609 vtab->zErrMsg = sqlite3_mprintf(
"constraint violation");
610 rc = SQLITE_CONSTRAINT;
614 if ((docid > 0) && (docid <= xm->sdoc)) {
620 sqlite3_mutex_leave(xm->
mutex);
623 sqlite3_free(vtab->zErrMsg);
625 vtab->zErrMsg = sqlite3_mprintf(
"invalid DOCID");
630 if (((sqlite3_value_type(argv[3]) == SQLITE_NULL) &&
631 (sqlite3_value_type(argv[4]) == SQLITE_NULL)) ||
632 ((sqlite3_value_type(argv[3]) != SQLITE_NULL) &&
633 (sqlite3_value_type(argv[4]) != SQLITE_NULL))) {
635 sqlite3_free(vtab->zErrMsg);
637 vtab->zErrMsg = sqlite3_mprintf(
"specify one of XML or PATH");
638 rc = SQLITE_CONSTRAINT;
641 if (sqlite3_value_type(argv[5]) != SQLITE_NULL) {
642 opts = sqlite3_value_int(argv[5]);
644 if (sqlite3_value_type(argv[6]) != SQLITE_NULL) {
645 enc = (
char *) sqlite3_value_text(argv[6]);
647 if (sqlite3_value_type(argv[4]) != SQLITE_NULL) {
648 doc = xmlReadFile((
char *) sqlite3_value_text(argv[4]), enc, opts);
652 if (sqlite3_value_type(argv[7]) != SQLITE_NULL) {
653 url = (
char *) sqlite3_value_text(argv[7]);
655 doc = xmlReadMemory(sqlite3_value_blob(argv[3]),
656 sqlite3_value_bytes(argv[3]),
657 url ? url :
"", enc, opts);
661 sqlite3_free(vtab->zErrMsg);
663 vtab->zErrMsg = sqlite3_mprintf(
"read error");
669 int *idocs = sqlite3_realloc(xt->
idocs, xt->
sdoc +
681 sqlite3_mutex_enter(xm->
mutex);
684 128 * sizeof (
XDOC));
687 sqlite3_mutex_leave(xm->
mutex);
692 memset(docs, 0, 128 *
sizeof (
XDOC));
695 for (i = 0; i < xm->
sdoc; i++) {
701 *rowidp = (sqlite3_int64) (i + 1);
710 sqlite3_free(vtab->zErrMsg);
712 vtab->zErrMsg = sqlite3_mprintf(
"UPDATE not supported");
716 xmlFreeDoc(docToFree);
717 }
else if (
doc && (n >= 0)) {
718 sqlite3_mutex_enter(xm->
mutex);
726 sqlite3_mutex_leave(xm->
mutex);
731 sqlite3_free(vtab->zErrMsg);
733 vtab->zErrMsg = sqlite3_mprintf(
"out of memory");
757 sqlite3_value **argv)
759 XTAB *xt = (
XTAB *) sqlite3_user_data(ctx);
763 xmlXPathContextPtr pctx = 0;
764 xmlXPathObjectPtr pobj = 0;
768 if ((argc < 2) || !sqlite3_value_text(argv[1])) {
769 sqlite3_result_error(ctx,
"wrong arguments", -1);
773 sqlite3_result_error(ctx,
"not in virtual table context", -1);
777 sqlite3_result_error(ctx,
"cursor out of bounds", -1);
782 sqlite3_result_error(ctx,
"no docid", -1);
785 p = (
char *) sqlite3_value_text(argv[1]);
787 sqlite3_result_error(ctx,
"no or empty XPath expression", -1);
792 if (!strcmp(p, xp->
expr)) {
798 xp = sqlite3_malloc(
sizeof (
XEXP) + strlen(p));
800 sqlite3_result_error(ctx,
"out of memory", -1);
805 pctx = xmlXPathNewContext(xm->
docs[n].
doc);
808 sqlite3_result_error(ctx,
"out of memory", -1);
811 pobj = xmlXPathEvalExpression((xmlChar *) xp->
expr, pctx);
814 sqlite3_result_error(ctx,
"bad XPath expression", -1);
835 xmlXPathFreeObject(xp->
pobj);
839 xmlXPathFreeContext(xp->
pctx);
846 pctx = xmlXPathNewContext(xm->
docs[n].
doc);
848 sqlite3_result_error(ctx,
"out of memory", -1);
851 pobj = xmlXPathEvalExpression((xmlChar *) xp->
expr, pctx);
853 sqlite3_result_error(ctx,
"bad XPath expression", -1);
867 sqlite3_result_null(ctx);
870 if ((xp->
pobj->type == XPATH_NODESET) && xp->
pobj->nodesetval) {
871 if ((xp->
pos < 0) || (xp->
pos >= xp->
pobj->nodesetval->nodeNr)) {
873 sqlite3_result_null(ctx);
875 xmlNodePtr node = xp->
pobj->nodesetval->nodeTab[xp->
pos];
876 xmlBufferPtr buf = 0;
878 xp->
parent = node->parent;
882 p = (
char *) xmlXPathCastNodeToString(node);
883 n = xmlXPathCastStringToBoolean((xmlChar *) p);
884 sqlite3_result_int(ctx, n);
890 sqlite3_result_double(ctx,
891 xmlXPathCastNodeToNumber(node));
894 buf = xmlBufferCreate();
896 sqlite3_result_error(ctx,
"out of memory", -1);
899 xmlNodeDump(buf, xp->
doc, node, 0, 0);
900 sqlite3_result_text(ctx, (
char *) xmlBufferContent(buf),
901 xmlBufferLength(buf),
906 p = (
char *) xmlXPathCastNodeToString(node);
907 sqlite3_result_text(ctx, p, -1, SQLITE_TRANSIENT);
914 sqlite3_result_null(ctx);
921 sqlite3_result_int(ctx, xmlXPathCastToBoolean(xp->
pobj));
924 sqlite3_result_double(ctx, xmlXPathCastToNumber(xp->
pobj));
927 p = (
char *) xmlXPathCastToString(xp->
pobj);
928 sqlite3_result_text(ctx, p, -1, SQLITE_TRANSIENT);
937 xmlXPathFreeObject(pobj);
940 xmlXPathFreeContext(pctx);
1008 void (**pfunc)(sqlite3_context *,
int, sqlite3_value **),
1014 if (!strcmp(name,
"xpath_string")) {
1019 if (!strcmp(name,
"xpath_boolean")) {
1024 if (!strcmp(name,
"xpath_number")) {
1029 if (!strcmp(name,
"xpath_xml")) {
1037 #if (SQLITE_VERSION_NUMBER > 3004000) 1046 xpath_rename(sqlite3_vtab *vtab,
const char *newname)
1077 #if (SQLITE_VERSION_NUMBER > 3004000) 1106 int argc, sqlite3_value **argv)
1108 xmlDocPtr
doc = 0, docToFree = 0;
1109 xmlXPathContextPtr pctx = 0;
1110 xmlXPathObjectPtr pobj = 0;
1111 XMOD *xm = (
XMOD *) sqlite3_user_data(ctx);
1116 sqlite3_result_null(ctx);
1119 if (sqlite3_value_type(argv[0]) == SQLITE_INTEGER) {
1120 index = sqlite3_value_int(argv[0]);
1122 sqlite3_result_error(ctx,
"init error", -1);
1125 sqlite3_mutex_enter(xm->
mutex);
1126 if ((index <= 0) || (index > xm->
sdoc) || !xm->
docs[index - 1].
doc) {
1127 sqlite3_mutex_leave(xm->
mutex);
1128 sqlite3_result_error(ctx,
"invalid DOCID", -1);
1131 doc = xm->
docs[index - 1].
doc;
1133 sqlite3_mutex_leave(xm->
mutex);
1135 int opts = (XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NONET);
1136 char *enc = 0, *url = 0;
1138 p = (
char *) sqlite3_value_blob(argv[0]);
1140 sqlite3_result_null(ctx);
1143 if ((argc > 2) && (sqlite3_value_type(argv[2]) != SQLITE_NULL)) {
1144 opts = sqlite3_value_int(argv[2]);
1146 if ((argc > 3) && (sqlite3_value_type(argv[3]) != SQLITE_NULL)) {
1147 enc = (
char *) sqlite3_value_text(argv[3]);
1149 if ((argc > 4) && (sqlite3_value_type(argv[4]) != SQLITE_NULL)) {
1150 url = (
char *) sqlite3_value_text(argv[4]);
1152 doc = xmlReadMemory(p, sqlite3_value_bytes(argv[0]),
1153 url ? url :
"", enc, opts);
1156 sqlite3_result_error(ctx,
"read error", -1);
1160 p = (
char *) sqlite3_value_text(argv[1]);
1162 sqlite3_result_null(ctx);
1165 pctx = xmlXPathNewContext(doc);
1167 sqlite3_result_error(ctx,
"out of memory", -1);
1170 pobj = xmlXPathEvalExpression((xmlChar *) p, pctx);
1172 sqlite3_result_error(ctx,
"bad XPath expression", -1);
1177 sqlite3_result_int(ctx, xmlXPathCastToBoolean(pobj));
1180 sqlite3_result_double(ctx, xmlXPathCastToNumber(pobj));
1183 if ((pobj->type == XPATH_NODESET) && pobj->nodesetval &&
1184 (pobj->nodesetval->nodeNr)) {
1185 xmlNodePtr node = pobj->nodesetval->nodeTab[0];
1186 xmlBufferPtr buf = 0;
1188 buf = xmlBufferCreate();
1190 sqlite3_result_error(ctx,
"out of memory", -1);
1193 xmlNodeDump(buf, doc, node, 0, 0);
1194 sqlite3_result_text(ctx, (
char *) xmlBufferContent(buf),
1195 xmlBufferLength(buf), SQLITE_TRANSIENT);
1198 sqlite3_result_null(ctx);
1202 p = (
char *) xmlXPathCastToString(pobj);
1203 sqlite3_result_text(ctx, p, -1, SQLITE_TRANSIENT);
1211 xmlXPathFreeObject(pobj);
1214 xmlXPathFreeContext(pctx);
1217 xmlFreeDoc(docToFree);
1220 sqlite3_mutex_enter(xm->
mutex);
1221 if (xm->
docs && index) {
1229 sqlite3_mutex_leave(xm->
mutex);
1231 xmlFreeDoc(docToFree);
1309 XMOD *xm = (
XMOD *) sqlite3_user_data(ctx);
1310 int index = 0, dump_len = 0, fmt = 1;
1312 char *enc =
"utf-8";
1315 sqlite3_result_null(ctx);
1318 index = sqlite3_value_int(argv[0]);
1320 enc = (
char *) sqlite3_value_text(argv[1]);
1326 fmt = sqlite3_value_int(argv[2]);
1329 sqlite3_result_error(ctx,
"init error", -1);
1332 sqlite3_mutex_enter(xm->
mutex);
1333 if ((index <= 0) || (index > xm->
sdoc) || !xm->
docs[index - 1].
doc) {
1334 sqlite3_mutex_leave(xm->
mutex);
1335 sqlite3_result_error(ctx,
"invalid DOCID", -1);
1338 xmlDocDumpFormatMemoryEnc(xm->
docs[index - 1].
doc, &dump, &dump_len,
1341 sqlite3_result_text(ctx, (
char *) dump, dump_len, SQLITE_TRANSIENT);
1344 sqlite3_mutex_leave(xm->
mutex);
1372 xpath_func_transform(sqlite3_context *ctx,
int argc, sqlite3_value **argv)
1374 xmlDocPtr
doc = 0, docToFree = 0, res = 0;
1375 xsltStylesheetPtr cur = 0;
1376 XMOD *xm = (
XMOD *) sqlite3_user_data(ctx);
1377 int index = 0, nparams = 0, param0, i;
1379 const char **params = 0;
1382 sqlite3_result_null(ctx);
1385 if (sqlite3_value_type(argv[0]) == SQLITE_INTEGER) {
1386 index = sqlite3_value_int(argv[0]);
1388 sqlite3_result_error(ctx,
"init error", -1);
1391 sqlite3_mutex_enter(xm->
mutex);
1392 if ((index <= 0) || (index > xm->
sdoc) || !xm->
docs[index - 1].
doc) {
1393 sqlite3_mutex_leave(xm->
mutex);
1394 sqlite3_result_error(ctx,
"invalid DOCID", -1);
1397 doc = xm->
docs[index - 1].
doc;
1399 sqlite3_mutex_leave(xm->
mutex);
1403 int opts = (XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NONET);
1404 char *enc = 0, *url = 0;
1406 p = (
char *) sqlite3_value_blob(argv[0]);
1408 sqlite3_result_null(ctx);
1411 if ((argc > 2) && (sqlite3_value_type(argv[2]) != SQLITE_NULL)) {
1412 opts = sqlite3_value_int(argv[2]);
1414 if ((argc > 3) && (sqlite3_value_type(argv[3]) != SQLITE_NULL)) {
1415 enc = (
char *) sqlite3_value_text(argv[3]);
1417 if ((argc > 4) && (sqlite3_value_type(argv[4]) != SQLITE_NULL)) {
1418 url = (
char *) sqlite3_value_text(argv[4]);
1420 doc = xmlReadMemory(p, sqlite3_value_bytes(argv[0]),
1421 url ? url :
"", enc, opts);
1424 sqlite3_result_error(ctx,
"read error", -1);
1430 p = (
char *) sqlite3_value_text(argv[1]);
1432 sqlite3_result_null(ctx);
1435 cur = xsltParseStylesheetFile((xmlChar *) p);
1437 sqlite3_result_error(ctx,
"read error on stylesheet", -1);
1445 params = sqlite3_malloc(nparams *
sizeof (
char *));
1447 sqlite3_result_error(ctx,
"out of memory", -1);
1450 for (i = 0; i < (argc - param0); i++) {
1451 params[i] = (
const char *) sqlite3_value_text(argv[i + param0]);
1457 res = xsltApplyStylesheet(cur, doc, params);
1459 sqlite3_result_error(ctx,
"transformation failed", -1);
1465 xmlFreeDoc(docToFree);
1468 xsltSaveResultToString(&str, &i, res, cur);
1470 sqlite3_result_text(ctx, (
char *) str, i, SQLITE_TRANSIENT);
1473 sqlite3_result_null(ctx);
1478 sqlite3_free(params);
1481 xsltFreeStylesheet(cur);
1484 xmlFreeDoc(docToFree);
1487 sqlite3_mutex_enter(xm->
mutex);
1488 if (xm->
docs && index) {
1491 xmlFreeDoc(docToFree);
1494 xm->
docs[index - 1].
doc = res;
1501 sqlite3_mutex_leave(xm->
mutex);
1503 xmlFreeDoc(docToFree);
1521 int i, n, cleanup = 0;
1522 sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
1527 sqlite3_mutex_enter(mutex);
1538 sqlite3_mutex_leave(mutex);
1540 sqlite3_mutex_enter(xm->
mutex);
1547 sqlite3_mutex_leave(mutex);
1548 sqlite3_mutex_free(mutex);
1549 for (i = 0; i < n; i++) {
1551 xmlFreeDoc(docs->
doc);
1574 sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
1577 return SQLITE_NOMEM;
1579 sqlite3_mutex_enter(mutex);
1581 xm = sqlite3_malloc(
sizeof (
XMOD));
1583 sqlite3_mutex_leave(mutex);
1584 return SQLITE_NOMEM;
1587 xm->
mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
1589 sqlite3_mutex_leave(mutex);
1591 return SQLITE_NOMEM;
1597 sqlite3_mutex_leave(mutex);
1598 sqlite3_mutex_free(xm->
mutex);
1600 return SQLITE_NOMEM;
1609 sqlite3_mutex_leave(mutex);
1610 sqlite3_create_function(db,
"xpath_string", -1, SQLITE_UTF8,
1612 sqlite3_create_function(db,
"xpath_boolean", -1, SQLITE_UTF8,
1614 sqlite3_create_function(db,
"xpath_number", -1, SQLITE_UTF8,
1616 sqlite3_create_function(db,
"xpath_xml", -1, SQLITE_UTF8,
1618 sqlite3_create_function(db,
"xml_dump", -1, SQLITE_UTF8,
1621 sqlite3_create_function(db,
"xslt_transform", -1, SQLITE_UTF8,
1622 (
void *) xm, xpath_func_transform, 0, 0);
1624 rc = sqlite3_create_module_v2(db,
"xpath", &xpath_mod,
1626 if (rc != SQLITE_OK) {
1627 sqlite3_create_function(db,
"xpath_string", -1, SQLITE_UTF8,
1628 (
void *) xm, 0, 0, 0);
1629 sqlite3_create_function(db,
"xpath_boolean", -1, SQLITE_UTF8,
1630 (
void *) xm, 0, 0, 0);
1631 sqlite3_create_function(db,
"xpath_number", -1, SQLITE_UTF8,
1632 (
void *) xm, 0, 0, 0);
1633 sqlite3_create_function(db,
"xpath_xml", -1, SQLITE_UTF8,
1634 (
void *) xm, 0, 0, 0);
1635 sqlite3_create_function(db,
"xml_dump", -1, SQLITE_UTF8,
1636 (
void *) xm, 0, 0, 0);
1638 sqlite3_create_function(db,
"xslt_transform", -1, SQLITE_UTF8,
1639 (
void *) xm, 0, 0, 0);
1658 const sqlite3_api_routines *api)
1660 SQLITE_EXTENSION_INIT2(api);
xmlXPathContextPtr pctx
Current XPath context.
static SQLRETURN nomem(STMT *s)
Report S1000 (out of memory) SQL error given STMT.
struct XEXP * prev
Previous item.
int refcnt
Reference counter.
static sqlite3_module xpath_mod
SQLite module descriptor.
xmlNodePtr parent
Current parent node or NULL.
int conv
Conversion: string/boolean/number.
int sdoc
Size of idocs array.
static int xpath_init(sqlite3 *db)
Module initializer creating SQLite module and functions.
static void xpath_func_dump(sqlite3_context *ctx, int argc, sqlite3_value **argv)
Function to dump XML document.
static void xpath_func_boolean(sqlite3_context *ctx, int argc, sqlite3_value **argv)
XPath select function returning boolean value.
static void xpath_fini(void *aux)
Module finalizer.
static void xpath_vfunc_number(sqlite3_context *ctx, int argc, sqlite3_value **argv)
XPath select function returning number from virtual table.
int ndoc
Number of used entries in docs array.
static int xpath_create(sqlite3 *db, void *aux, int argc, const char *const *argv, sqlite3_vtab **vtabp, char **errp)
Create virtual table.
xmlXPathObjectPtr pobj
Current XPath objects.
static void xpath_vfunc_common(sqlite3_context *ctx, int conv, int argc, sqlite3_value **argv)
Common XPath select function for virtual table.
static int xpath_findfunc(sqlite3_vtab *vtab, int nargs, const char *name, void(**pfunc)(sqlite3_context *, int, sqlite3_value **), void **parg)
Find overloaded function on virtual table.
struct XCSR * xc
Current cursor.
xmlDocPtr doc
Current XML document.
int ndoc
Number of used entries in idocs array.
static int xpath_update(sqlite3_vtab *vtab, int argc, sqlite3_value **argv, sqlite3_int64 *rowidp)
Insert/delete row into/from virtual table.
static int xpath_column(sqlite3_vtab_cursor *cursor, sqlite3_context *ctx, int n)
Return column data of virtual table.
char expr[1]
XPath expression text.
int nexpr
Number of XPath expr.
sqlite3_mutex * mutex
DOC table mutex.
int refcnt
Reference counter.
static int xpath_rowid(sqlite3_vtab_cursor *cursor, sqlite3_int64 *rowidp)
Return current rowid of virtual table cursor.
static void xpath_func_string(sqlite3_context *ctx, int argc, sqlite3_value **argv)
XPath select function returning string value.
XEXP * first
First XPath expr.
sqlite3_vtab_cursor cursor
SQLite virtual table cursor.
Structure to cache XML document.
static void xpath_func_common(sqlite3_context *ctx, int conv, int argc, sqlite3_value **argv)
Common XPath select function.
static int xpath_filter(sqlite3_vtab_cursor *cursor, int idxNum, const char *idxStr, int argc, sqlite3_value **argv)
Filter function for virtual table.
XEXP * last
Last XPath expr.
static void xpath_func_xml(sqlite3_context *ctx, int argc, sqlite3_value **argv)
XPath select function returning XML.
static int xpath_connect(sqlite3 *db, void *aux, int argc, const char *const *argv, sqlite3_vtab **vtabp, char **errp)
Connect to virtual table.
static int xpath_next(sqlite3_vtab_cursor *cursor)
Retrieve next row from virtual table cursor.
int sqlite3_extension_init(sqlite3 *db, char **errmsg, const sqlite3_api_routines *api)
Initializer for SQLite extension load mechanism.
static int xpath_destroy(sqlite3_vtab *vtab)
Destroy virtual table.
static void xpath_func_number(sqlite3_context *ctx, int argc, sqlite3_value **argv)
XPath select function returning number.
Structure to describe virtual table cursor.
XDOC * docs
Array of modules's DOCs.
Structure to describe virtual table.
static void xpath_vfunc_string(sqlite3_context *ctx, int argc, sqlite3_value **argv)
XPath select function returning string value from virtual table.
static int xpath_open(sqlite3_vtab *vtab, sqlite3_vtab_cursor **cursorp)
Open virtual table and return cursor.
static void xpath_vfunc_xml(sqlite3_context *ctx, int argc, sqlite3_value **argv)
XPath select function returning XML from virtual table.
int * idocs
Indexes in module-wide DOC table.
sqlite3 * db
Open database.
Structure holding per module/database data.
static int xpath_bestindex(sqlite3_vtab *vtab, sqlite3_index_info *info)
Determines information for filter function according to constraints.
static void xpath_vfunc_boolean(sqlite3_context *ctx, int argc, sqlite3_value **argv)
XPath select function returning boolean value from virtual table.
int sdoc
Size of docs array.
xmlDocPtr doc
XML document.
static int xpath_disconnect(sqlite3_vtab *vtab)
Disconnect virtual table.
static int xpath_eof(sqlite3_vtab_cursor *cursor)
Return end of table state of virtual table cursor.
Structure to describe XPath expression.
int pos
Position within XPath expr.
sqlite3_vtab vtab
SQLite virtual table.
static int xpath_close(sqlite3_vtab_cursor *cursor)
Close virtual table cursor.
struct XEXP * next
Next item.