102 char* mysql_host =
"localhost";
104 char* mysql_user = NULL;
105 char* mysql_password = NULL;
106 char* mysql_db = NULL;
108 char* dataname = NULL;
110 int option_index = 0;
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'},
134 while ((c = getopt_long (argc, argv,
"H:u:p:P:d:n:r:Vh",long_options,&option_index)) != -1)
138 mysql_host =
malloc(strlen(optarg)+1);
139 strcpy(mysql_host,optarg);
142 mysql_user =
malloc(strlen(optarg)+1);
143 strcpy(mysql_user,optarg);
146 mysql_password =
malloc(strlen(optarg)+1);
147 strcpy(mysql_password,optarg);
150 mysql_db =
malloc(strlen(optarg)+1);
151 strcpy(mysql_db,optarg);
154 dataname =
malloc(strlen(optarg)+1);
155 strcpy(dataname,optarg);
158 printf(
"ac_mysqlread (1.4)\n");
165 mysql_port = atoi(optarg);
168 runid = atoi(optarg);
172 fprintf (stderr,
"Option -%c requires an argument.\n", optopt);
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);}
184 open_connection(mysql_host, mysql_user, mysql_password, mysql_db,mysql_port);
188 datasql = (
char*)
malloc((255)*
sizeof(char));
189 sprintf(datasql,
"select data,description from rundata where runid=%d and name='%s'",runid,dataname);
193 while((row = mysql_fetch_row(result)) != NULL){
195 printf(
"%s\n",row[0]);
213 printf(
"No data found with name %s or run %d not found\n",dataname,runid);
217 printf(
"No data found with name %s or run %d not found\n",dataname,runid);
219 mysql_free_result(result);
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