Drizzled Public API Documentation

file.cc
1 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright 2011 Daniel Nichter
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <config.h>
21 #include "file.h"
22 
23 using namespace std;
24 
25 QueryLoggerFile::QueryLoggerFile()
26 {
27  _fh.setf(ios::fixed, ios::floatfield);
28  _fh.precision(6);
29 }
30 
31 QueryLoggerFile::~QueryLoggerFile()
32 {
33  closeLogFile();
34 }
35 
37 {
38  if (_fh.is_open())
39  {
40  _fh << "# start_ts=" << event->ts
41  << "\n"
42  << "# session_id=" << event->session_id
43  << " query_id=" << event->query_id
44  << " rows_examined=" << event->rows_examined
45  << " rows_sent=" << event->rows_sent
46  << " tmp_tables=" << event->tmp_tables
47  << " warnings=" << event->warnings
48  << "\n"
49  << "# execution_time=" << event->execution_time
50  << " lock_time=" << event->lock_time
51  << " session_time=" << event->session_time
52  << "\n"
53  << "# error=" << event->error << "\n"
54  << "# schema=\"" << event->schema << "\"\n"
55  << event->query << ";\n#"
56  << endl;
57  }
58  return false; // success
59 }
60 
61 bool QueryLoggerFile::openLogFile(const char *file)
62 {
63  closeLogFile();
64 
65  _fh.open(file, ios::app);
66  if (_fh.fail())
67  return true; // error
68 
69  return false; // success
70 }
71 
73 {
74  if (_fh.is_open())
75  {
76  _fh.close();
77  if (_fh.fail())
78  return true; // error
79  }
80 
81  return false; // success
82 }