AcouSTO  version 2.0

◆ main()

int main ( int  argc,
char **  argv 
)
100  {
101 
102  char* mysql_host = "localhost";
103  int mysql_port = 0;
104  char* mysql_user = NULL;
105  char* mysql_password = NULL;
106  char* mysql_db = NULL;
107 
108  char* dataname = NULL;
109  int runid = 0;
110  int option_index = 0;
111  int c;
112  char* datasql;
113 
114 
115  MYSQL_RES *result;
116  MYSQL_ROW row;
117 
118 
119 
120  /* Defining long options struct */
121  static struct option long_options[] ={
122  {"mysql-host",required_argument,0,'H'},
123  {"mysql-port",required_argument,0,'P'},
124  {"mysql-user",required_argument,0,'u'},
125  {"mysql-password",required_argument,0,'p'},
126  {"mysql-dbname",required_argument,0,'d'},
127  {"data-name",required_argument,0,'n'},
128  {"run-id",required_argument,0,'r'},
129  {"version" ,no_argument ,0,'V'},
130  {"help" ,no_argument ,0,'h'},
131  };
132 
133  /* Options Parsing loop */
134  while ((c = getopt_long (argc, argv, "H:u:p:P:d:n:r:Vh",long_options,&option_index)) != -1)
135  switch (c)
136  {
137  case 'H': // hostname
138  mysql_host = malloc(strlen(optarg)+1);
139  strcpy(mysql_host,optarg);
140  break;
141  case 'u': // username
142  mysql_user = malloc(strlen(optarg)+1);
143  strcpy(mysql_user,optarg);
144  break;
145  case 'p': // password
146  mysql_password = malloc(strlen(optarg)+1);
147  strcpy(mysql_password,optarg);
148  break;
149  case 'd': // database name
150  mysql_db = malloc(strlen(optarg)+1);
151  strcpy(mysql_db,optarg);
152  break;
153  case 'n': // data name
154  dataname = malloc(strlen(optarg)+1);
155  strcpy(dataname,optarg);
156  break;
157  case 'V': // version
158  printf("ac_mysqlread (1.4)\n");
159  break;
160  case 'h': // help
161  printhelp();
162  exit(0);
163  break;
164  case 'P': // mysql port
165  mysql_port = atoi(optarg);
166  break;
167  case 'r': // runid
168  runid = atoi(optarg);
169  break;
170  case '?':
171  if (optopt == 'f')
172  fprintf (stderr, "Option -%c requires an argument.\n", optopt);
173  default:
174  printf(" ");
175  }
176 
177 
178  // checking mandatory options
179  if(NULL == mysql_user) {perror("Mysql User must be provided\n"); exit(1);}
180  if(NULL == mysql_db) {perror("Mysql DB Name must be provided\n"); exit(1);}
181  if(0 == runid) {perror("Run id must be provided\n"); exit(1);}
182  if(NULL == dataname) {perror("Data name must be provided\n"); exit(1);}
183 
184  open_connection(mysql_host, mysql_user, mysql_password, mysql_db,mysql_port); // init mysql
185 
186 
187  // doing query
188  datasql = (char*) malloc((255)*sizeof(char));
189  sprintf(datasql,"select data,description from rundata where runid=%d and name='%s'",runid,dataname);
190  mysql_query(connection,datasql);
191  result=mysql_store_result(connection);
192  if(NULL != result){
193  while((row = mysql_fetch_row(result)) != NULL){
194  if(NULL != row){ // if we get some result...
195  printf("%s\n",row[0]);
196  /*
197  if(0 == strcmp(dataname,"ACOUSTO_CONFIG")){ // configuration is dumped as is
198  printf("%s\n",row[0]);
199  }else{ // complex array data is casted to the right array and dumped on stdout
200  l = mysql_fetch_lengths(result);
201  cval = (COMPLEX*) (row[0]);
202  nitems = l[0] / sizeof(COMPLEX);
203  printf(" # frequency %s\n",row[1]);
204  for(i=0;i<nitems;i++){
205  printf("%d %f %f\n",i,creal(*cval),cimag(*cval));
206  cval++;
207  }
208 
209 
210  }
211  */
212  }else{
213  printf("No data found with name %s or run %d not found\n",dataname,runid);
214  }
215  }
216  }else{
217  printf("No data found with name %s or run %d not found\n",dataname,runid);
218  }
219  mysql_free_result(result); // freeing everything
220 
221 
223 
224 
225  return 0;
226 }
MYSQL * connection
Definition: ac_mysqlread.c:40
void printhelp()
Definition: ac_mysqlread.c:56
int open_connection(char *mysql_hostname, char *mysql_user, char *mysql_password, char *mysql_db, int mysql_port)
Definition: ac_mysqlread.c:75
void close_connection()
Definition: ac_mysqlread.c:46
#define malloc(size)
Definition: allocation.h:38