libdballe 4.0.18
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_ltype1;
00187     DBALLE_SQL_C_SINT_TYPE  sel_l1;
00188     DBALLE_SQL_C_SINT_TYPE  sel_ltype2;
00189     DBALLE_SQL_C_SINT_TYPE  sel_l2;
00190     DBALLE_SQL_C_SINT_TYPE  sel_pind;
00191     DBALLE_SQL_C_SINT_TYPE  sel_p1;
00192     DBALLE_SQL_C_SINT_TYPE  sel_p2;
00193     DBALLE_SQL_C_SINT_TYPE  sel_b;
00194     DBALLE_SQL_C_SINT_TYPE  sel_rep_cod;
00195     DBALLE_SQL_C_SINT_TYPE  sel_ana_id;
00196     DBALLE_SQL_C_SINT_TYPE  sel_context_id;
00202     DBALLE_SQL_C_SINT_TYPE  out_lat;
00203     DBALLE_SQL_C_SINT_TYPE  out_lon;
00204     char    out_ident[64];      SQLLEN out_ident_ind;
00205     DBALLE_SQL_C_SINT_TYPE  out_ltype1;
00206     DBALLE_SQL_C_SINT_TYPE  out_l1;
00207     DBALLE_SQL_C_SINT_TYPE  out_ltype2;
00208     DBALLE_SQL_C_SINT_TYPE  out_l2;
00209     DBALLE_SQL_C_SINT_TYPE  out_pind;
00210     DBALLE_SQL_C_SINT_TYPE  out_p1;
00211     DBALLE_SQL_C_SINT_TYPE  out_p2;
00212     DBALLE_SQL_C_SINT_TYPE  out_idvar;
00213     SQL_TIMESTAMP_STRUCT    out_datetime;
00214     char    out_value[255];
00215     DBALLE_SQL_C_SINT_TYPE  out_rep_cod;
00216     DBALLE_SQL_C_SINT_TYPE  out_ana_id;
00217     DBALLE_SQL_C_SINT_TYPE  out_context_id;
00218     DBALLE_SQL_C_SINT_TYPE  out_priority;
00222     int count;
00223 };
00224 
00225 struct _dba_db_seq
00226 {
00227     SQLHSTMT stm;
00228     DBALLE_SQL_C_SINT_TYPE out;
00229 };
00230 
00231 typedef struct _dba_db_seq* dba_db_seq;
00232 
00236 dba_err dba_db_error_odbc(SQLSMALLINT handleType, SQLHANDLE handle, const char* fmt, ...);
00237 
00245 dba_err dba_db_error_odbc_except(const char* error_to_ignore, SQLSMALLINT handleType, SQLHANDLE handle, const char* fmt, ...);
00246 
00250 dba_err dba_db_statement_create(dba_db db, SQLHSTMT* stm);
00251         
00255 dba_err dba_db_last_insert_id(dba_db db, int* id);
00256 
00260 dba_err dba_db_seq_create(dba_db db, const char* name, dba_db_seq* seq);
00261 
00265 dba_err dba_db_seq_read(dba_db_seq seq);
00266 
00270 void dba_db_seq_delete(dba_db_seq seq);
00271 
00275 dba_err dba_db_drop_table_if_exists(dba_db db, const char* name);
00276 
00280 dba_err dba_db_run_sql(dba_db db, const char* query);
00281 
00285 dba_err dba_db_begin(dba_db db);
00286 
00290 dba_err dba_db_commit(dba_db db);
00291 
00295 void dba_db_rollback(dba_db db);
00296 
00300 dba_err dba_db_need_repinfo(dba_db db);
00301 
00305 dba_err dba_db_need_pseudoana(dba_db db);
00306 
00310 dba_err dba_db_need_context(dba_db db);
00311 
00315 dba_err dba_db_need_data(dba_db db);
00316 
00320 dba_err dba_db_need_attr(dba_db db);
00321 
00322 #ifdef  __cplusplus
00323 }
00324 #endif
00325 
00326 /* vim:set ts=4 sw=4: */
00327 #endif