fixed: DbBase::ConvertTime(tm) should not have been used in this way as it was
(it uses a static buffer) now DbTextStream can get tm struct so you don't have to use ConvertTime git-svn-id: svn://ttmath.org/publicrep/winix/trunk@662 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
69c634d53f
commit
07511a2eb0
|
@ -505,6 +505,7 @@ return status;
|
|||
|
||||
|
||||
|
||||
|
||||
Error System::EditFile(Item & item, bool with_url)
|
||||
{
|
||||
if( item.type == Item::dir )
|
||||
|
|
12
db/db.cpp
12
db/db.cpp
|
@ -245,8 +245,8 @@ Error Db::AddItemIntoItem(Item & item)
|
|||
<< item.modification_user_id
|
||||
<< item.group_id
|
||||
<< item.privileges
|
||||
<< ConvertTime(item.date_creation)
|
||||
<< ConvertTime(item.date_modification)
|
||||
<< item.date_creation
|
||||
<< item.date_modification
|
||||
<< static_cast<int>(item.type)
|
||||
<< item.parent_id
|
||||
<< item.content_id
|
||||
|
@ -356,8 +356,8 @@ Error Db::EditItemInItem(Item & item, bool with_url)
|
|||
<< item.modification_user_id
|
||||
<< item.group_id
|
||||
<< item.privileges
|
||||
<< ConvertTime(item.date_creation)
|
||||
<< ConvertTime(item.date_modification)
|
||||
<< item.date_creation
|
||||
<< item.date_modification
|
||||
<< static_cast<int>(item.type)
|
||||
<< item.default_item
|
||||
<< item.parent_id
|
||||
|
@ -1447,7 +1447,7 @@ Error Db::GetThreadByDirId(long dir_id, Thread & thread)
|
|||
thread.closed = AssertValueLong(r, 0, cclosed) == 0 ? false : true;
|
||||
thread.items = AssertValueLong(r, 0, citems);
|
||||
thread.last_item.id = AssertValueLong(r, 0, clast_item);
|
||||
thread.last_item.date_modification = ConvertTime( AssertValue(r, 0, cdate_modification) );
|
||||
thread.last_item.date_modification = AssertValueTm(r, 0, cdate_modification);
|
||||
thread.last_item.user_id = AssertValueLong(r, 0, cuser_id);
|
||||
}
|
||||
catch(const Error & e)
|
||||
|
@ -1500,7 +1500,7 @@ Error Db::GetThreads(long parent_id, std::vector<Thread> & thread_tab)
|
|||
thread.closed = AssertValueLong(r, i, cclosed) == 0 ? false : true;
|
||||
thread.items = AssertValueLong(r, i, citems);
|
||||
thread.last_item.id = AssertValueLong(r, i, clast_item);
|
||||
thread.last_item.date_modification = ConvertTime( AssertValue(r, i, cdate_modification) );
|
||||
thread.last_item.date_modification = AssertValueTm(r, i, cdate_modification);
|
||||
thread.last_item.user_id = AssertValueLong(r, i, cuser_id);
|
||||
thread.last_item.guest_name = AssertValue(r, i, cguest_name);
|
||||
|
||||
|
|
|
@ -165,6 +165,12 @@ unsigned int DbBase::AssertValueUInt(PGresult * r, int row, int col)
|
|||
}
|
||||
|
||||
|
||||
tm DbBase::AssertValueTm(PGresult * r, int row, int col)
|
||||
{
|
||||
return ConvertTime(AssertValue(r, row, col));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DbBase::ClearResult(PGresult * r)
|
||||
{
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
static int AssertValueInt(PGresult * r, int row, int col);
|
||||
static unsigned long AssertValueULong(PGresult * r, int row, int col);
|
||||
static unsigned int AssertValueUInt(PGresult * r, int row, int col);
|
||||
static tm AssertValueTm(PGresult * r, int row, int col);
|
||||
|
||||
void ClearResult(PGresult * r);
|
||||
long AssertCurrval(const char * table);
|
||||
|
|
|
@ -44,8 +44,8 @@ void DbItemColumns::SetItem(PGresult * r, long row, Item & item)
|
|||
if( user_id != -1 ) item.user_id = DbBase::AssertValueLong(r, row, user_id);
|
||||
if( group_id != -1 ) item.group_id = DbBase::AssertValueLong(r, row, group_id);
|
||||
if( privileges != -1 ) item.privileges = DbBase::AssertValueInt(r, row, privileges);
|
||||
if( date_creation != -1 ) item.date_creation = DbBase::ConvertTime( DbBase::AssertValue(r, row, date_creation) );
|
||||
if( date_modification != -1 ) item.date_modification = DbBase::ConvertTime( DbBase::AssertValue(r, row, date_modification) );
|
||||
if( date_creation != -1 ) item.date_creation = DbBase::AssertValueTm(r, row, date_creation);
|
||||
if( date_modification != -1 ) item.date_modification = DbBase::AssertValueTm(r, row, date_modification);
|
||||
if( url != -1 ) item.url = DbBase::AssertValue(r, row, url);
|
||||
if( type != -1 ) item.type = static_cast<Item::Type>( DbBase::AssertValueInt(r, row, type) );
|
||||
if( parent_id != -1 ) item.parent_id = DbBase::AssertValueLong(r, row, parent_id);
|
||||
|
|
|
@ -54,7 +54,7 @@ DbTextStream & DbTextStream::PutText(const std::string & str)
|
|||
|
||||
|
||||
|
||||
DbTextStream & DbTextStream::operator<<(const DbTextStream::RawText<const char*> & raw)
|
||||
DbTextStream & DbTextStream::operator<<(const RawText<const char*> & raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ DbTextStream & DbTextStream::operator<<(const DbTextStream::RawText<const char*>
|
|||
|
||||
|
||||
|
||||
DbTextStream & DbTextStream::operator<<(DbTextStream::RawText<std::string> raw)
|
||||
DbTextStream & DbTextStream::operator<<(RawText<std::string> raw)
|
||||
{
|
||||
return PutText(raw.par.c_str());
|
||||
}
|
||||
|
@ -131,6 +131,15 @@ return *this;
|
|||
}
|
||||
|
||||
|
||||
DbTextStream & DbTextStream::operator<<(const RawText<tm> & t)
|
||||
{
|
||||
buffer += ConvertTime(t.par);
|
||||
was_param = false;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -357,7 +366,36 @@ return *this;
|
|||
|
||||
|
||||
|
||||
|
||||
DbTextStream & DbTextStream::operator<<(const tm & t)
|
||||
{
|
||||
if( was_param )
|
||||
buffer += ", ";
|
||||
|
||||
buffer += '\'';
|
||||
buffer += ConvertTime(t);
|
||||
buffer += '\'';
|
||||
was_param = true;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char * DbTextStream::ConvertTime(const tm & t)
|
||||
{
|
||||
// not thread safe
|
||||
static char buffer[100];
|
||||
|
||||
sprintf(buffer, "%04d-%02d-%02d %02d:%02d:%02d",
|
||||
t.tm_year + 1900,
|
||||
t.tm_mon + 1,
|
||||
t.tm_mday,
|
||||
t.tm_hour,
|
||||
t.tm_min,
|
||||
t.tm_sec);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#ifndef headerfile_winix_db_dbtextstream
|
||||
#define headerfile_winix_db_dbtextstream
|
||||
|
||||
#include <ctime>
|
||||
#include "core/textstream.h"
|
||||
|
||||
|
||||
|
@ -100,7 +101,7 @@ public:
|
|||
DbTextStream & operator<<(RawText<unsigned long> raw);
|
||||
DbTextStream & operator<<(RawText<double> raw);
|
||||
DbTextStream & operator<<(RawText<void*> raw);
|
||||
|
||||
DbTextStream & operator<<(const RawText<tm> & t);
|
||||
|
||||
|
||||
/*
|
||||
|
@ -128,8 +129,11 @@ public:
|
|||
DbTextStream & operator<<(unsigned long);
|
||||
DbTextStream & operator<<(double);
|
||||
DbTextStream & operator<<(const void *);
|
||||
DbTextStream & operator<<(const tm & t);
|
||||
|
||||
|
||||
static const char * ConvertTime(const tm & t);
|
||||
|
||||
private:
|
||||
|
||||
bool was_param;
|
||||
|
|
Loading…
Reference in New Issue