60 printf((
const char *) mysql_error(&
mysql));
68 sprintf(
buf,
"%d",val);
81 sprintf(vbuf,
"%d,",val[i]);
82 if(strlen(
buf)+strlen(vbuf) >=
sizeof(
buf)-1)
return -1;
91 sprintf(
buf,
"%f",val);
104 sprintf(vbuf,
"%f,",val[i]);
105 if(strlen(
buf)+strlen(vbuf) >=
sizeof(
buf)-1)
return -1;
114 sprintf(
typebuf,
"S%d",strlen(val));
125 ret = snprintf(sqlbuf,
sizeof(sqlbuf)-1,
"UPDATE %s SET datatype='%s', datavalue='%s' WHERE name='%s'",
tableName,
typebuf,
buf,item);
128 printf(
"sqlbuf too small in writeDatabaseString\n");
132 if(ret > 0)
return 0;
135 ret = snprintf(sqlbuf,
sizeof(sqlbuf)-1,
"INSERT INTO %s VALUES ('%s','%s','%s')",
tableName,item,
typebuf,
buf);
138 printf(
"sqlbuf too small in writeDatabaseString\n");
142 if(ret >= 0)
return 0;
152 state = mysql_query((MYSQL *)
connection, query);
158 num_rows = mysql_affected_rows((MYSQL *)
connection);
159 result = mysql_store_result((MYSQL *)
connection);
160 mysql_free_result(result);
172 *type = *value =
'\0';
173 sprintf(query,
"select * from bus where name = '%s'",item);
175 state = mysql_query((MYSQL *)
connection, query);
181 num_rows = mysql_affected_rows((MYSQL *)
connection);
182 result = mysql_store_result((MYSQL *)
connection);
185 row = mysql_fetch_row(result);
188 if(row[1] != NULL) strcpy(type ,row[1]);
189 if(row[2] != NULL) strcpy(value,row[2]);
191 mysql_free_result(result);
virtual ~rlBussignalDatabase()
int readDatabase(const char *item, char *type, char *value)
char buf[rl_PRINTF_LENGTH]
int writeDatabaseIntArray(const char *item, int *val, int len)
int writeDatabaseFloatArray(const char *item, float *val, int len)
int writeDatabaseString(const char *item, char *val)
static int mysql_is_initialized
int myquery(const char *query)
int openDatabase(const char *database, const char *table)
int writeDatabaseFloat(const char *item, float val)
char * rlstrncpy(char *dest, const char *source, int n)
int writeDatabaseInt(const char *item, int val)