From 4942d5a229dca435488aa959d99638c774a0eea7 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Sat, 13 Dec 2008 02:10:51 +0100 Subject: Added sqlite functions for populating an XML document directly --- database/sqlite/sqlite.c | 19 +++++++++++++++++++ database/sqlite/sqlite.h | 8 ++++++++ 2 files changed, 27 insertions(+) (limited to 'database/sqlite') diff --git a/database/sqlite/sqlite.c b/database/sqlite/sqlite.c index f74b4d7..c0df997 100644 --- a/database/sqlite/sqlite.c +++ b/database/sqlite/sqlite.c @@ -25,6 +25,10 @@ #include #include +#ifdef HAVE_LIBXML2 +# include +#endif + #include #include #include @@ -469,6 +473,21 @@ char *sqlite_get_value(dbresult *res, int row, int col) { return NULL; } + +#ifdef HAVE_LIBXML2 +xmlNodePtr sqlite_xml_value(xmlNodePtr node, xmlFieldType xmltyp, char *name, dbresult *res, int row, int col) { + switch( xmltyp ) { + case XML_ATTR: + xmlNewProp(node, (xmlChar *)name, (xmlChar *) sqlite_get_value(res, row, col)); + return node; + + case XML_NODE: + return xmlNewChild(node, NULL, (xmlChar *) name, (xmlChar *)sqlite_get_value(res, row, col)); + } + return NULL; +} +#endif + // Retrieve number of tuples in current dbresult structure int sqlite_get_numtuples(dbresult *res) { return (res != NULL ? res->num_tuples : 0); diff --git a/database/sqlite/sqlite.h b/database/sqlite/sqlite.h index 3dfe058..4ffbfd5 100644 --- a/database/sqlite/sqlite.h +++ b/database/sqlite/sqlite.h @@ -22,8 +22,13 @@ # define SQLITE_H_ #include +#ifdef HAVE_LIBXML2 +# include +#endif #include +typedef enum _xmlFieldType { XML_ATTR, XML_NODE } xmlFieldType; + typedef struct __sqlite_header { unsigned int fieldid; char *name; @@ -69,6 +74,9 @@ dbresult *sqlite_query(eurephiaCTX *ctx, const char *, ...); dbresult *sqlite_query_mapped(eurephiaCTX *ctx, SQLqueryType type, const char *sqlstub, eDBfieldMap *valMap, eDBfieldMap *whereMap); char *sqlite_get_value(dbresult *res, int, int); +#ifdef HAVE_LIBXML2 +xmlNodePtr sqlite_xml_value(xmlNodePtr node, xmlFieldType xmltyp, char *name, dbresult *res, int row, int col); +#endif void sqlite_dump_result(FILE *, dbresult *); int sqlite_get_numtuples(dbresult *); #endif -- cgit