internals.h

Go to the documentation of this file.
00001 /*
00002  * DB-ALLe - Archive for punctual meteorological data
00003  *
00004  * Copyright (C) 2005,2006  ARPA-SIM <urpsim@smr.arpa.emr.it>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00018  *
00019  * Author: Enrico Zini <enrico@enricozini.com>
00020  */
00021 
00022 #ifndef DBALLE_DB_INTERNALS_H
00023 #define DBALLE_DB_INTERNALS_H
00024 
00025 #ifdef  __cplusplus
00026 extern "C" {
00027 #endif
00028 
00036 #include <dballe/db/querybuf.h>
00037 #include <dballe/db/odbcworkarounds.h>
00038 
00039 #include <sqltypes.h>
00040 
00045 /* #define TRACE_DB */
00046 
00047 #ifdef TRACE_DB
00048 #define TRACE(...) fprintf(stderr, __VA_ARGS__)
00049 #define IFTRACE if (1)
00050 #else
00051 
00052 #define TRACE(...) do { } while (0)
00053 
00054 #define IFTRACE if (0)
00055 #endif
00056 
00060 struct _dba_db_repinfo;
00061 struct _dba_db_pseudoana;
00062 struct _dba_db_context;
00063 struct _dba_db_data;
00064 struct _dba_db_attr;
00065 struct _dba_db_seq;
00066 
00070 enum dba_db_server_type
00071 {
00072     MYSQL,
00073     SQLITE,
00074     ORACLE,
00075     POSTGRES,
00076 };
00077 
00081 struct _dba_db
00082 {
00084     SQLHDBC od_conn;
00086     int connected;
00088     enum dba_db_server_type server_type;
00089 
00098     struct _dba_db_repinfo* repinfo;
00100     struct _dba_db_pseudoana* pseudoana;
00102     struct _dba_db_context* context;
00104     struct _dba_db_data* data;
00106     struct _dba_db_attr* attr;
00116     struct _dba_db_seq* seq_pseudoana;
00118     struct _dba_db_seq* seq_context;
00122     SQLHSTMT stm_begin;
00124     SQLHSTMT stm_commit;
00126     SQLHSTMT stm_rollback;
00128     SQLHSTMT stm_last_insert_id;
00130     DBALLE_SQL_C_SINT_TYPE last_insert_id;
00131 };
00132 #ifndef DBA_DB_DEFINED
00133 #define DBA_DB_DEFINED
00134 
00135 typedef struct _dba_db* dba_db;
00136 #endif
00137 
00142 struct _dba_db_cursor
00143 {
00145     dba_db db;
00147     SQLHSTMT stm;
00148 
00150     dba_querybuf query;
00151 
00153     dba_querybuf where;
00154 
00156     unsigned int wanted;
00157 
00159     unsigned int modifiers;
00160 
00162     unsigned int select_wanted;
00163 
00165     unsigned int from_wanted;
00166 
00168     unsigned int input_seq;
00169 
00171     unsigned int output_seq;
00172 
00174     int accept_from_ana_context;
00175 
00179     SQL_TIMESTAMP_STRUCT    sel_dtmin;
00180     SQL_TIMESTAMP_STRUCT    sel_dtmax;
00181     DBALLE_SQL_C_SINT_TYPE  sel_latmin;
00182     DBALLE_SQL_C_SINT_TYPE  sel_latmax;
00183     DBALLE_SQL_C_SINT_TYPE  sel_lonmin;
00184     DBALLE_SQL_C_SINT_TYPE  sel_lonmax;
00185     char    sel_ident[64];
00186     DBALLE_SQL_C_SINT_TYPE  sel_ltype;
00187     DBALLE_SQL_C_SINT_TYPE  sel_l1;
00188     DBALLE_SQL_C_SINT_TYPE  sel_l2;
00189     DBALLE_SQL_C_SINT_TYPE  sel_pind;
00190     DBALLE_SQL_C_SINT_TYPE  sel_p1;
00191     DBALLE_SQL_C_SINT_TYPE  sel_p2;
00192     DBALLE_SQL_C_SINT_TYPE  sel_b;
00193     DBALLE_SQL_C_SINT_TYPE  sel_rep_cod;
00194     DBALLE_SQL_C_SINT_TYPE  sel_priority;
00195     DBALLE_SQL_C_SINT_TYPE  sel_priomin;
00196     DBALLE_SQL_C_SINT_TYPE  sel_priomax;
00197     DBALLE_SQL_C_SINT_TYPE  sel_ana_id;
00198     DBALLE_SQL_C_SINT_TYPE  sel_context_id;
00204     DBALLE_SQL_C_SINT_TYPE  out_lat;
00205     DBALLE_SQL_C_SINT_TYPE  out_lon;
00206     char    out_ident[64];      SQLLEN out_ident_ind;
00207     DBALLE_SQL_C_SINT_TYPE  out_ltype;
00208     DBALLE_SQL_C_SINT_TYPE  out_l1;
00209     DBALLE_SQL_C_SINT_TYPE  out_l2;
00210     DBALLE_SQL_C_SINT_TYPE  out_pind;
00211     DBALLE_SQL_C_SINT_TYPE  out_p1;
00212     DBALLE_SQL_C_SINT_TYPE  out_p2;
00213     DBALLE_SQL_C_SINT_TYPE  out_idvar;
00214     SQL_TIMESTAMP_STRUCT    out_datetime;
00215     char    out_value[255];
00216     DBALLE_SQL_C_SINT_TYPE  out_rep_cod;
00217     DBALLE_SQL_C_SINT_TYPE  out_ana_id;
00218     DBALLE_SQL_C_SINT_TYPE  out_context_id;
00219     DBALLE_SQL_C_SINT_TYPE  out_priority;
00223     int count;
00224 };
00225 
00226 struct _dba_db_seq
00227 {
00228     SQLHSTMT stm;
00229     DBALLE_SQL_C_SINT_TYPE out;
00230 };
00231 
00232 typedef struct _dba_db_seq* dba_db_seq;
00233 
00237 dba_err dba_db_error_odbc(SQLSMALLINT handleType, SQLHANDLE handle, const char* fmt, ...);
00238 
00246 dba_err dba_db_error_odbc_except(const char* error_to_ignore, SQLSMALLINT handleType, SQLHANDLE handle, const char* fmt, ...);
00247 
00251 dba_err dba_db_statement_create(dba_db db, SQLHSTMT* stm);
00252         
00256 dba_err dba_db_last_insert_id(dba_db db, int* id);
00257 
00261 dba_err dba_db_seq_create(dba_db db, const char* name, dba_db_seq* seq);
00262 
00266 dba_err dba_db_seq_read(dba_db_seq seq);
00267 
00271 void dba_db_seq_delete(dba_db_seq seq);
00272 
00276 dba_err dba_db_drop_table_if_exists(dba_db db, const char* name);
00277 
00281 dba_err dba_db_begin(dba_db db);
00282 
00286 dba_err dba_db_commit(dba_db db);
00287 
00291 void dba_db_rollback(dba_db db);
00292 
00296 dba_err dba_db_need_repinfo(dba_db db);
00297 
00301 dba_err dba_db_need_pseudoana(dba_db db);
00302 
00306 dba_err dba_db_need_context(dba_db db);
00307 
00311 dba_err dba_db_need_data(dba_db db);
00312 
00316 dba_err dba_db_need_attr(dba_db db);
00317 
00318 #ifdef  __cplusplus
00319 }
00320 #endif
00321 
00322 /* vim:set ts=4 sw=4: */
00323 #endif

Generated on Thu Aug 30 14:59:08 2007 for libdballe-db by  doxygen 1.5.3