changed: the way of building the cmslu
main Makefile is in an application directory in cmslu/ there are only libraries: core.a content.a confparser.a templates.a added: macros APPTEMPLATES APPFUNCTIONS defined in the application's Makefile added: PatternCacher added: cmslu function 'run' files which have exec permissions can be run (run is a default function) after read from the database the content is parsed into Ezc::Pattern object, this object is then cached in PatternCacher added: FunctionCodeParser - will be used to parse the code from standard functions (ls/cat/...) git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@475 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
60
core/db.cpp
60
core/db.cpp
@@ -10,18 +10,25 @@
|
||||
#include "db.h"
|
||||
|
||||
|
||||
Db::Db()
|
||||
Db::Db(bool close_at_end_)
|
||||
{
|
||||
pg_conn = 0;
|
||||
pg_conn = 0;
|
||||
close_at_end = close_at_end_;
|
||||
}
|
||||
|
||||
|
||||
Db::~Db()
|
||||
{
|
||||
Close();
|
||||
if( close_at_end )
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
PGconn * Db::GetPGconn()
|
||||
{
|
||||
return pg_conn;
|
||||
}
|
||||
|
||||
|
||||
void Db::Init(const std::string & d, const std::string & u, const std::string & p)
|
||||
{
|
||||
@@ -43,10 +50,15 @@ void Db::Connect()
|
||||
pg_conn = PQconnectdb(buf.str().c_str());
|
||||
|
||||
if( !pg_conn )
|
||||
{
|
||||
log << log1 << "Db: Fatal error during connecting" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
if( PQsetClientEncoding(pg_conn, "LATIN2") == -1 )
|
||||
log << log1 << "Db: Can't set the proper client encoding" << logend;
|
||||
|
||||
log << log3 << "Db: Socket: " << PQsocket(pg_conn) << logend;
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +104,8 @@ void Db::AssertConnection()
|
||||
|
||||
if( PQsetClientEncoding(pg_conn, "LATIN2") == -1 )
|
||||
log << log1 << "Db: Can't set the proper client encoding" << logend;
|
||||
|
||||
log << log3 << "Db: Socket: " << PQsocket(pg_conn) << logend;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,7 +152,9 @@ PGresult * Db::AssertQuery(const std::string & q)
|
||||
|
||||
if( !r )
|
||||
{
|
||||
log << log1 << "Db: Problem with query: " << PQerrorMessage(pg_conn) << logend;
|
||||
log << log1 << "Db: Problem with query: \"" << q << '\"' << logend;
|
||||
log << log1 << "Db: " << PQerrorMessage(pg_conn) << logend;
|
||||
|
||||
throw Error(Error::db_incorrect_query);
|
||||
}
|
||||
|
||||
@@ -1247,6 +1263,42 @@ void Db::GetGroups(UGContainer<Group> & group_table)
|
||||
|
||||
|
||||
|
||||
tm Db::ConvertTime(const char * str)
|
||||
{
|
||||
tm t;
|
||||
|
||||
memset(&t, 0, sizeof(t));
|
||||
|
||||
if( !str )
|
||||
return t;
|
||||
|
||||
size_t len = strlen(str);
|
||||
|
||||
if( len != 19 )
|
||||
{
|
||||
// unknown format
|
||||
// the format must be like this: 2008-12-31 22:30:00
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
t.tm_year = atoi(str + 0) - 1900; /* year - 1900 */
|
||||
t.tm_mon = atoi(str + 5) - 1; /* month of year (0 - 11) */
|
||||
t.tm_mday = atoi(str + 8); /* day of month (1 - 31) */
|
||||
t.tm_hour = atoi(str + 11); /* hours (0 - 23) */
|
||||
t.tm_min = atoi(str + 14); /* minutes (0 - 59) */
|
||||
t.tm_sec = atoi(str + 17); /* seconds (0 - 60) */
|
||||
|
||||
|
||||
// t.tm_wday = 0; /* day of week (Sunday = 0) */
|
||||
// t.tm_yday = 0; /* day of year (0 - 365) */
|
||||
// t.tm_isdst = 0; /* is summer time in effect? */
|
||||
// t.tm_zone = 0; // const_cast<char*>(""); /* abbreviation of timezone name */
|
||||
|
||||
|
||||
//return mktime(&t);
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user