summaryrefslogtreecommitdiffstats
path: root/database/sqlite
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2008-12-13 02:10:51 +0100
committerDavid Sommerseth <dazo@users.sourceforge.net>2008-12-13 02:10:51 +0100
commit4942d5a229dca435488aa959d99638c774a0eea7 (patch)
tree810eef61686b13daacc7387c6c5e9b987d5537f9 /database/sqlite
parent45c5e846e401ec9a4102eff0dbb5c22cf0742b52 (diff)
downloadeurephia-4942d5a229dca435488aa959d99638c774a0eea7.tar.gz
eurephia-4942d5a229dca435488aa959d99638c774a0eea7.tar.xz
eurephia-4942d5a229dca435488aa959d99638c774a0eea7.zip
Added sqlite functions for populating an XML document directly
Diffstat (limited to 'database/sqlite')
-rw-r--r--database/sqlite/sqlite.c19
-rw-r--r--database/sqlite/sqlite.h8
2 files changed, 27 insertions, 0 deletions
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 <assert.h>
#include <sqlite3.h>
+#ifdef HAVE_LIBXML2
+# include <libxml/tree.h>
+#endif
+
#include <eurephia_log.h>
#include <eurephia_nullsafe.h>
#include <eurephia_directions.h>
@@ -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 <stdarg.h>
+#ifdef HAVE_LIBXML2
+# include <libxml/tree.h>
+#endif
#include <eurephiadb_mapping.h>
+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