/[PAMELA software]/calo/ground/COMMON/src/readmy.c
ViewVC logotype

Annotation of /calo/ground/COMMON/src/readmy.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Tue Dec 6 10:18:54 2005 UTC (19 years ago) by mocchiut
Branch point for: MAIN, COMMON
File MIME type: text/plain
Initial revision

1 mocchiut 1.1 #include <stdio.h>
2     #include <stdlib.h>
3     #include <string.h>
4     #include <mysql.h>
5     #include "calomysqlstruct.h"
6    
7    
8     short int readmy(char *db, const char *myquery, struct Mystruct *mystruct){
9     //
10     int debug = 0;
11     if ( debug ) printf("Connecting to database... \n");
12     MYSQL *pConnection;
13     MYSQL_RES *pResult;
14     MYSQL_ROW Row;
15     short int retval = 0;
16     int t;
17     int r;
18     pConnection = mysql_init(NULL);
19     if( !pConnection ) return(1);
20     //
21     int connect = (int)mysql_real_connect(pConnection,"srv-g2-01.ts.infn.it","pamela","CaloMyC@l1brati0n",db,0,NULL,0);
22     //
23     if( !connect ) return(2);
24     if ( debug ) printf("...connected! \n\n");
25     if ( debug ) printf("The query is:\n \"%s\" \n",myquery);
26     int errqu = mysql_query(pConnection,myquery);
27     if ( !errqu ) {
28     pResult = mysql_store_result(pConnection);
29     mystruct->obtjump = 0;
30     mystruct->fromtime = -1;
31     mystruct->totime = -1;
32     mystruct->calibtime = -1;
33     mystruct->calcalibfile = "";
34     for( r=0; r < mysql_field_count(pConnection); r++){
35     Row = mysql_fetch_row(pResult);
36     if( Row == NULL ) break;
37     int section = 0;
38     for( t = 0; t < mysql_num_fields(pResult); t++){
39     if ( t == 1 ) section = atoi(Row[t]);
40     if ( t == 2 ) mystruct->obtjump = atoi(Row[t]);
41     if ( t == 3 ) mystruct->fromtime = atoi(Row[t]);
42     if ( t == 4 ) mystruct->totime = atoi(Row[t]);
43     if ( t == 5 ) mystruct->calibtime = atoi(Row[t]);
44     if ( t == 6 ) mystruct->calcalibfile = Row[t];
45     };
46     if ( debug ) printf(" section %i from time %i to time %i use calibration at time %i from file %s ",section,mystruct->fromtime,mystruct->totime,mystruct->calibtime,mystruct->calcalibfile);
47     if ( debug ) printf("\n");
48     };
49     mysql_free_result(pResult);
50     retval = 0;
51     } else {
52     if ( debug ) printf(" errqu = %i \n",errqu);
53     retval = 3;
54     };
55     if ( debug ) printf("\nClose the connection... \n");
56     mysql_close(pConnection);
57     if ( debug ) printf("...connection terminated!\n");
58     return(retval);
59     }

  ViewVC Help
Powered by ViewVC 1.1.23