Forums  +  C++ and Sockets  +  C++ and SQL: MySQL, sqlite, ODBC  +  Miscellaneous Projects
Logo
~Database~
~ C++ ~
~Contact~

StderrLog.cpp

Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 2004  Anders Hedstrom
00009 
00010 This program is made available under the terms of the GNU GPL.
00011 
00012 If you would like to use this program in a closed-source application,
00013 a separate license agreement is available. For information about 
00014 the closed-source license agreement for this program, please
00015 visit http://www.alhem.net/sqlwrapped/license.html and/or
00016 email license@alhem.net.
00017 
00018 This program is free software; you can redistribute it and/or
00019 modify it under the terms of the GNU General Public License
00020 as published by the Free Software Foundation; either version 2
00021 of the License, or (at your option) any later version.
00022 
00023 This program is distributed in the hope that it will be useful,
00024 but WITHOUT ANY WARRANTY; without even the implied warranty of
00025 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00026 GNU General Public License for more details.
00027 
00028 You should have received a copy of the GNU General Public License
00029 along with this program; if not, write to the Free Software
00030 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00031 */
00032 #include <stdio.h>
00033 #ifdef _WIN32
00034 #pragma warning(disable:4786)
00035 #endif
00036 
00037 #include <string>
00038 #include <map>
00039 #ifdef WIN32
00040 #include <config-win.h>
00041 #include <mysql.h>
00042 #include <time.h>
00043 #else
00044 #include <mysql/mysql.h>
00045 #endif
00046 
00047 #include "Database.h"
00048 #include "Query.h"
00049 #include "IError.h"
00050 #include "StderrLog.h"
00051 
00052 
00053 #ifdef MYSQLW_NAMESPACE
00054 namespace MYSQLW_NAMESPACE {
00055 #endif
00056 
00057 
00058 void StderrLog::error(Database& db,const std::string& str)
00059 {
00060         time_t t = time(NULL);
00061         struct tm *tp = localtime(&t);
00062         fprintf(stderr,"%d-%02d-%02d %02d:%02d:%02d :: Database: %s\n",
00063                 tp -> tm_year + 1900,tp -> tm_mon + 1,tp -> tm_mday,
00064                 tp -> tm_hour,tp -> tm_min, tp -> tm_sec,
00065                 str.c_str());
00066 }
00067 
00068 
00069 void StderrLog::error(Database& db,Query& q,const std::string& str)
00070 {
00071         time_t t = time(NULL);
00072         struct tm *tp = localtime(&t);
00073         fprintf(stderr,"%d-%02d-%02d %02d:%02d:%02d :: Query: %s: %s(%d)\n",
00074                 tp -> tm_year + 1900,tp -> tm_mon + 1,tp -> tm_mday,
00075                 tp -> tm_hour,tp -> tm_min, tp -> tm_sec,
00076                 str.c_str(),q.GetError().c_str(),q.GetErrno());
00077         fprintf(stderr," (QUERY: \"%s\")\n",q.GetLastQuery().c_str());
00078 }
00079 
00080 
00081 #ifdef MYSQLW_NAMESPACE
00082 } // namespace MYSQLW_NAMESPACE {
00083 #endif
00084 
Page, code, and content Copyright (C) 2006 by Anders Hedström