added: TextStream a class similar to std::ostringstream
but with a Clear() method the dynamic allocated buffer can be easily reused added: DbTextStream a special version of a stream used to create a database string query everything is escaped by default added: DbBase a base class with some basic methods for communicating with the database added: DbConn a class for managing connection to the database changed: some refactoring in Db class git-svn-id: svn://ttmath.org/publicrep/winix/trunk@655 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
75
db/dbbase.h
Executable file
75
db/dbbase.h
Executable file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_db_dbbase
|
||||
#define headerfile_winix_db_dbbase
|
||||
|
||||
|
||||
#include "dbconn.h"
|
||||
#include "dbtextstream.h"
|
||||
|
||||
|
||||
class DbBase
|
||||
{
|
||||
public:
|
||||
|
||||
DbBase();
|
||||
|
||||
void SetConn(DbConn * conn);
|
||||
void SetConn(DbConn & conn);
|
||||
DbConn * GetConn();
|
||||
|
||||
void LogQueries(bool log_q);
|
||||
|
||||
PGresult * AssertQuery(const char * query);
|
||||
PGresult * AssertQuery(const std::string & query);
|
||||
PGresult * AssertQuery(const DbTextStream & query);
|
||||
void AssertResult(PGresult * r, ExecStatusType t);
|
||||
static int AssertColumn(PGresult * r, const char * column_name);
|
||||
|
||||
static const char * AssertValue(PGresult * r, int row, int col);
|
||||
static long AssertValueLong(PGresult * r, int row, int col);
|
||||
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);
|
||||
|
||||
void ClearResult(PGresult * r);
|
||||
long AssertCurrval(const char * table);
|
||||
|
||||
bool IsNull(PGresult * r, int row, int col);
|
||||
int Rows(PGresult * r);
|
||||
int Cols(PGresult * r);
|
||||
long AffectedRows(PGresult * r);
|
||||
|
||||
static tm ConvertTime(const char * str);
|
||||
static const char * ConvertTime(const tm & t); // warning: it uses its own static buffer
|
||||
|
||||
protected:
|
||||
|
||||
// a helper method for escaping strings
|
||||
template<class RawType>
|
||||
DbTextStream::RawText<RawType> R(const RawType & par)
|
||||
{
|
||||
return DbTextStream::RawText<RawType>(par);
|
||||
}
|
||||
|
||||
DbConn * db_conn;
|
||||
bool log_queries;
|
||||
|
||||
private:
|
||||
|
||||
DbTextStream bquery;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user