sqlite.h

Go to the documentation of this file.
00001 /* sqlite.h  --  Generic functions to simplify SQLite3 queries - data structures defined here
00002  *
00003  *  GPLv2 only - Copyright (C) 2008 - 2010
00004  *               David Sommerseth <dazo@users.sourceforge.net>
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; version 2
00009  *  of the License.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  *
00020  */
00021 
00031 #ifndef         SQLITE_H_
00032 # define        SQLITE_H_
00033 
00034 #include <stdarg.h>
00035 #ifdef HAVE_LIBXML2
00036 # include <libxml/tree.h>
00037 #endif
00038 #include <eurephiadb_mapping.h>
00039 
00043 typedef enum _xmlFieldType { XML_ATTR, XML_NODE } xmlFieldType;
00044 
00052 typedef struct __sqlite_header {
00053         unsigned int fieldid;   
00054         char *name;             
00055         // char *type;
00056         size_t namelength;      
00057         size_t maxvaluelength;  
00058         struct __sqlite_header *next; 
00059         struct __sqlite_header *prev; 
00060 } _sqlite_header;
00061 
00062 
00070 typedef struct __sqlite_tuples {
00071         unsigned int tupleid;   
00072         unsigned int fieldid;   
00073         char *value;            
00074         size_t length;          
00075         _sqlite_header *header; 
00076         struct __sqlite_tuples *nextfield; 
00077         struct __sqlite_tuples *prevfield; 
00078         struct __sqlite_tuples *nexttuple; 
00079         struct __sqlite_tuples *prevtuple; 
00080 } _sqlite_tuples;
00081 
00082 
00093 typedef struct __sqlite_dbresult {
00094         // Query results
00095         _sqlite_tuples *tuples;       
00096         _sqlite_header *headerrec;    
00097         size_t num_tuples;            
00098         size_t num_fields;            
00099         sqlite_int64 last_insert_id;  
00100         int affected_rows;            
00102         // "Search" pointers
00103         _sqlite_tuples *srch_tuples;    
00104         _sqlite_header *srch_headerrec; 
00105 } dbresult;
00106 
00107 
00111 typedef enum _SQLqueryType { SQL_SELECT, SQL_INSERT, SQL_UPDATE, SQL_DELETE } SQLqueryType;
00112 
00119 #define sqlite_free_results(r) { _sqlite_free_results(r); r = NULL; }
00120 void _sqlite_free_results(dbresult *);
00121 dbresult *sqlite_query(eurephiaCTX *ctx, const char *, ...);
00122 dbresult *sqlite_query_mapped(eurephiaCTX *ctx, SQLqueryType type, const char *sqlstub,
00123                               eDBfieldMap *valMap, eDBfieldMap *whereMap, const char *sortkeys);
00124 char *sqlite_get_value(dbresult *res, int, int);
00125 #ifdef HAVE_LIBXML2
00126 xmlNodePtr sqlite_xml_value(xmlNodePtr node, xmlFieldType xmltyp, char *name, dbresult *res, int row, int col);
00127 #endif
00128 void sqlite_dump_result(FILE *, dbresult *);
00129 
00130 
00138 #define sqlite_get_numtuples(dbres) (dbres != NULL ? dbres->num_tuples : 0)
00139 
00140 
00149 #define sqlite_get_affected_rows(dbres) (dbres != NULL ? dbres->affected_rows : 0)
00150 
00151 #endif      /* !SQLITE_H_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines