代码如下:
/* query record from table 'normalLog' or 'debugLog'
 *
 * Parameters in : *condition: log query condition
 *     *log_new: function point for getting memory form caller
 *     *p: the parameter for log_new
 *    *count: start record
 *     flag: indicates the log is normal or debug. 0-normal, 1-debug
 *     lines: indicates the result set involved how many records
 *     order: indicates the order: ASC(>0) or DESC(<=0)
 * Parameters out: *count: next record, -1 indicates no more records. 0 indicates no records.
 * Returns  : 0: succeed
 *                 1: failed
 */
static int
query_log(struct log_condition *condition, void *(*log_new) (void *p),
  void *p, int *count, short flag, unsigned int lines, int order)
{
unsigned long n;
char query[DB_LARGE_BUF_SIZE] = { 0 };
char query_condition[512] = { 0 };
char *header =
    "SELECT logtime,a.logtype,a.subtype,msg,a.level,username,result,sessionid,para1,"
    "para2,para3,para4,para5,para6,para7,id,b.msgid,paranum ";
char *fc = " FROM log.devicelog a,mng.logdefine b ";
int rtv, rc, rc2;
time_t logtime_from, logtime_to;
struct tm tm;
MYSQL_RES *res_set;
ST_DB_HANDLE dbhandle; memset(&dbhandle, 0, sizeof (dbhandle));
dbhandle.dbtype = LOG;
strncpy(dbhandle.caller, __FUNCTION__, 20);
if (db_pool_get_handle(&dbhandle) != OK) {
print_error(NULL, "get database connect handle failure\n");
return GET_HANDLE_DBPOOL_FAILURE;
} if (*count < 0)
return PARAMETER_DB_ERROR; /* generate the where sub clause */
n = 0;
n += sprintf(query_condition + n, "where ");
if (condition->type & 0x01)
n += sprintf(query_condition + n, "a.level=%u and ",
     condition->level);
if (condition->type & 0x02)
n += sprintf(query_condition + n, "result=%u and ",
     condition->result);
if (condition->type & 0x04)
n += sprintf(query_condition + n,
     "username LIKE \'%%%s%%\' and ",
     condition->username);
if (condition->type & 0x08){
tzset();
strptime(condition->time_from, "%Y-%m-%d %H:%M:%S", &tm);
logtime_from = mktime(&tm);
// logtime_from -= timezone;
n += sprintf(query_condition + n,
 "logtime>=%lu and ", logtime_from);
}
if (condition->type & 0x10){
tzset();
strptime(condition->time_to, "%Y-%m-%d %H:%M:%S", &tm);
logtime_to = mktime(&tm);
// logtime_to -= timezone;
n += sprintf(query_condition + n,
 "logtime<=%lu and ", logtime_to);
}
if (condition->type & 0x20)
n += sprintf(query_condition + n, "a.logtype=%u and ",
     condition->logtype);
if (condition->type & 0x40)
n += sprintf(query_condition + n, "a.subtype=%u and ",
     condition->subtype);
if (condition->type & 0x80) {
n += sprintf(query_condition + n, "username=\'");
n += snprintf(query_condition + n, MAX_NAME_LEN,
      "%s", condition->username);
n += sprintf(query_condition + n, "\' and ");
}
if (condition->type & 0x100)
n += sprintf(query_condition + n, "a.level<=%u and ",
     condition->level);
if (condition->type & 0x200)
n += sprintf(query_condition + n, "sessionid='%s' and ",
     condition->sessionid);
if (condition->type & 0x400)
n += sprintf(query_condition + n, "(para2='%s'or para3='%s') and ",
     condition->ipname, condition->ipname);
if (condition->type & 0x800)
n += sprintf(query_condition + n, "para2='%s' and ",
     condition->servername); n += sprintf(query_condition + n, "langid=%u and a.msgid=b.msgid and ",
     condition->langid); n -= 4; query_condition[n] = '\0'; /* get the record count */
sprintf(query, "select count(a.id) %s %s", fc, query_condition);
rc2 = db_get_counts(dbhandle.mysql, query); if (rc2 < 0) {
rtv = FAILED_REAL_QUERY_DB_ERROR;
goto L_EXIT;
}
if (rc2 == 0) {
rtv = NO_MORE_DATA_DB_ERROR;
goto L_EXIT;
}
memset(query, 0, sizeof (query));
/* generate the sort sub clause */
n += sprintf(query_condition + n,
     "ORDER BY id %s LIMIT %u,%u", order > 0 ? "ASC" : "DESC",
     *count, lines); gw_strcpy(query, header);
n = strlen(query);
n += sprintf(query + n, "%s", fc);
n += sprintf(query + n, "%s", query_condition); SQL_print(query); /* do the query with database server */
rtv = mysql_real_query(dbhandle.mysql, query, n);
if (rtv) {
print_error(dbhandle.mysql, "mysql_real_query() failed:\n");
rtv = FAILED_REAL_QUERY_DB_ERROR;
goto L_EXIT;
} /* process the result */
res_set = mysql_store_result(dbhandle.mysql);
if (res_set == NULL) {
print_error(dbhandle.mysql, "mysql_store_result() failed");
rtv = FAILED_STORE_RESULT_DB_ERROR;
goto L_EXIT; }
else { /* process result set, then deallocate it */
MYSQL_ROW row;
while ((row = mysql_fetch_row(res_set)) != NULL) {
struct gwlog_info *tmp = NULL; if (log_new == NULL)
break;
tmp = (struct gwlog_info *) (*log_new) (p);
if (!tmp) {
mysql_free_result(res_set);
rtv = FAILED_CALL_FUNCTION_DB_ERROR;
goto L_EXIT;
} tmp->rc = rc2;
tmp->logtime = atol(row[0]);
tmp->logtype = atoi(row[1]);
tmp->subtype = atoi(row[2]);
gw_strcpy(tmp->msg, row[3]);
tmp->level = atoi(row[4]);
strncpy(tmp->username, row[5], MAX_NAME_LEN - 1);
tmp->result = atoi(row[6]);
if (row[7])
gw_strcpy(tmp->sessionid, row[7]); /* Add "" string to all 7 params if it's NULL */
int i = 0;
for (i = 0; i < LOG_MAX_PARAM_NUM; i++) {
//memset(tmp->paralist[i], 0,
    //   2 * (MAX_NAME_LEN - 1) + 1);
if (row[i + 8] != NULL) {
gw_strncpy(tmp->paralist[i], row[i + 8],
LOG_MAX_PARAM_LEN); } else {
gw_strcpy(tmp->paralist[i], "");
}
} tmp->log_id = atoi(row[15]);
tmp->msgid = (unsigned int) atoi(row[16]);
tmp->paranum = (unsigned int) atoi(row[17]);
} /* return the next record number */
rc = (unsigned long) mysql_num_rows(res_set);
mysql_free_result(res_set);
*count += rc;
if (rc < MAX_RECORDS_PER_QUERY) {
rtv = NO_MORE_DATA_DB_ERROR;
goto L_EXIT;
}
}
rtv = OK;
      L_EXIT:
db_pool_put_handle(&dbhandle);
return rtv;
}
当我要调用这个query_log()函数的时候, 我query_log 函数里面的参数,应该怎么添加。MySQL