func requestType(stmt string, prepared *plan.Prepared) string { var tokens []string // FIXME - this is a proper hack! should be using algebra.Statement // or something similar to determine the statement type! if prepared != nil && prepared.Text() != "" { // Second or fourth token determines type of statement tokens = strings.Split(strings.TrimSpace(prepared.Text()), " ")[1:] } else { if stmt != "" { // First token determines type of statement tokens = strings.Split(strings.TrimSpace(stmt), " ")[0:1] } } for _, token := range tokens { switch strings.ToLower(token) { case "select": return SELECTS case "update": return UPDATES case "insert": return INSERTS case "delete": return DELETES } } return UNKNOWN }
func LogRequest(acctstore AccountingStore, request_time time.Duration, service_time time.Duration, result_count int, result_size int, error_count int, warn_count int, stmt string, sort_count uint64, plan *plan.Prepared, id string) { if requestLog.threshold >= 0 && request_time < time.Millisecond*requestLog.threshold { return } rv := &RequestLogEntry{ RequestId: id, ElapsedTime: request_time, ServiceTime: service_time, ResultCount: result_count, ResultSize: result_size, ErrorCount: error_count, SortCount: sort_count, Time: time.Now(), } if stmt != "" { rv.Statement = stmt } if plan != nil { rv.PreparedName = plan.Name() rv.PreparedText = plan.Text() } requestLog.add(rv) }