| 68 | } |
| 69 | |
| 70 | bool db_store::db_update(const http_thread& http) |
| 71 | { |
| 72 | // ��ȡ���ݿ����� |
| 73 | acl::db_handle* db = var_dbpool->peek(); |
| 74 | if (db == NULL) |
| 75 | { |
| 76 | logger_error("peek db connect failed!"); |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | // ���ȴ����ݿ� |
| 81 | if (db->open(var_cfg_dbcharset) == false) |
| 82 | { |
| 83 | logger_error("open db error, charset: %s", |
| 84 | var_cfg_dbcharset); |
| 85 | var_dbpool->put(db); |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | // ���������ٶ� |
| 90 | double speed = (http.length_ * 1000) / http.spent_http_; |
| 91 | |
| 92 | acl::string sql; |
| 93 | sql.format("insert into http_tbl(addr, url, total_spent," |
| 94 | " dns_spent, connect_spent, http_spent, length, speed," |
| 95 | " success, currtime) values('%s', '%s', %.2f, %.2f, %.2f," |
| 96 | " %.2f, %d, %.2f, '%s', CURRENT_TIMESTAMP)", |
| 97 | http.addr_, http.url_.c_str(), http.spent_total_, |
| 98 | http.spent_dns_, http.spent_connect_, http.spent_http_, |
| 99 | http.length_, speed, http.success_ ? "ok" : "error"); |
| 100 | |
| 101 | // �������ݿ���ֶ� |
| 102 | if (db->sql_update(sql.c_str()) == false) |
| 103 | logger_error("sql(%s) error", sql.c_str()); |
| 104 | else |
| 105 | logger("sql: %s ok", sql.c_str()); |
| 106 | |
| 107 | // �黹���ݿ����� |
| 108 | var_dbpool->put(db); |
| 109 | return true; |
| 110 | } |
no test coverage detected