2010-09-18 02:51:12 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2012-01-08 04:59:51 +01:00
|
|
|
* Copyright (c) 2010-2012, Tomasz Sowa
|
2010-09-18 02:51:12 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef headerfile_winix_db_dbbase
|
|
|
|
#define headerfile_winix_db_dbbase
|
|
|
|
|
|
|
|
|
|
|
|
#include "dbconn.h"
|
|
|
|
#include "dbtextstream.h"
|
2010-10-19 02:31:20 +02:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include "core/error.h"
|
2012-01-12 03:24:08 +01:00
|
|
|
#include "confparser/confparser.h"
|
2010-09-18 02:51:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
class DbBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
DbBase();
|
|
|
|
|
|
|
|
void SetConn(DbConn * conn);
|
|
|
|
void SetConn(DbConn & conn);
|
|
|
|
DbConn * GetConn();
|
|
|
|
|
|
|
|
void LogQueries(bool log_q);
|
|
|
|
|
|
|
|
PGresult * AssertQuery(const char * query);
|
2010-11-21 01:19:17 +01:00
|
|
|
PGresult * AssertQuery(const std::wstring & query);
|
2010-09-18 02:51:12 +02:00
|
|
|
PGresult * AssertQuery(const DbTextStream & query);
|
|
|
|
void AssertResult(PGresult * r, ExecStatusType t);
|
|
|
|
static int AssertColumn(PGresult * r, const char * column_name);
|
|
|
|
|
2012-01-08 04:59:51 +01:00
|
|
|
// static assignments
|
2010-09-18 02:51:12 +02:00
|
|
|
static const char * AssertValue(PGresult * r, int row, int col);
|
2010-11-21 01:19:17 +01:00
|
|
|
static const std::wstring & AssertValueWide(PGresult * r, int row, int col); // warning: this method uses a static buffer
|
|
|
|
static void AssertValueWide(PGresult * r, int row, int col, std::wstring & result);
|
changed: when winix demonizes it creates a three new descriptors (0, 1 and 3)
pointing to /dev/null
added: DbBase::AssertValueBin(PGresult * r, int row, int col, std::string & result)
it reads binary (bytea) data
added: DbTextStream can handle 'bool' types now
(is puts 'true' of 'false' to the stream)
changed: now passwords can be stored either as plain text, a hash or can be encrypted
with RSA
currently we have following hashes:
md4, md5, sha1, sha224, sha256, sha384, sha512
we are using openssl to manage them
(look at config options for more info)
changed: winix version to 0.4.7
added: class Run - you can run any program from os and send a buffer to its standard input
and read what the program put on its standard output
added: class Crypt (in System) - calculating hashes, and crypting/decrypting
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@734 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-06-09 23:22:08 +02:00
|
|
|
static void AssertValueBin(PGresult * r, int row, int col, std::string & result);
|
2010-09-18 02:51:12 +02:00
|
|
|
static long AssertValueLong(PGresult * r, int row, int col);
|
|
|
|
static int AssertValueInt(PGresult * r, int row, int col);
|
2010-12-11 23:55:48 +01:00
|
|
|
static bool AssertValueBool(PGresult * r, int row, int col);
|
2010-09-18 02:51:12 +02:00
|
|
|
static unsigned long AssertValueULong(PGresult * r, int row, int col);
|
|
|
|
static unsigned int AssertValueUInt(PGresult * r, int row, int col);
|
2010-10-09 22:27:45 +02:00
|
|
|
static tm AssertValueTm(PGresult * r, int row, int col);
|
2012-01-08 04:59:51 +01:00
|
|
|
|
|
|
|
// non static assignments
|
2012-01-12 03:24:08 +01:00
|
|
|
bool AssertValueSpace(PGresult * r, int row, int col, PT::Space & space, bool split_single = true);
|
2010-09-18 02:51:12 +02:00
|
|
|
|
|
|
|
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
|
2010-11-21 01:19:17 +01:00
|
|
|
void CreateIdList(const std::vector<long> & id_tab, std::wstring & list, bool add_parentheses = true);
|
2010-10-19 02:31:20 +02:00
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
Error DoCommand(const DbTextStream & command);
|
2010-10-19 02:31:20 +02:00
|
|
|
Error DoCommand(const char * command);
|
|
|
|
Error BeginTrans();
|
|
|
|
Error RollbackTrans();
|
|
|
|
Error CommitTrans();
|
2011-01-05 22:24:11 +01:00
|
|
|
Error EndTrans(Error err);
|
2010-09-18 02:51:12 +02:00
|
|
|
|
changed: when winix demonizes it creates a three new descriptors (0, 1 and 3)
pointing to /dev/null
added: DbBase::AssertValueBin(PGresult * r, int row, int col, std::string & result)
it reads binary (bytea) data
added: DbTextStream can handle 'bool' types now
(is puts 'true' of 'false' to the stream)
changed: now passwords can be stored either as plain text, a hash or can be encrypted
with RSA
currently we have following hashes:
md4, md5, sha1, sha224, sha256, sha384, sha512
we are using openssl to manage them
(look at config options for more info)
changed: winix version to 0.4.7
added: class Run - you can run any program from os and send a buffer to its standard input
and read what the program put on its standard output
added: class Crypt (in System) - calculating hashes, and crypting/decrypting
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@734 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-06-09 23:22:08 +02:00
|
|
|
static void UnescapeBin(const char * str, size_t len, std::string & out, bool clear_out = true);
|
|
|
|
|
|
|
|
|
2010-09-18 02:51:12 +02:00
|
|
|
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;
|
|
|
|
|
changed: when winix demonizes it creates a three new descriptors (0, 1 and 3)
pointing to /dev/null
added: DbBase::AssertValueBin(PGresult * r, int row, int col, std::string & result)
it reads binary (bytea) data
added: DbTextStream can handle 'bool' types now
(is puts 'true' of 'false' to the stream)
changed: now passwords can be stored either as plain text, a hash or can be encrypted
with RSA
currently we have following hashes:
md4, md5, sha1, sha224, sha256, sha384, sha512
we are using openssl to manage them
(look at config options for more info)
changed: winix version to 0.4.7
added: class Run - you can run any program from os and send a buffer to its standard input
and read what the program put on its standard output
added: class Crypt (in System) - calculating hashes, and crypting/decrypting
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@734 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-06-09 23:22:08 +02:00
|
|
|
|
2010-09-18 02:51:12 +02:00
|
|
|
private:
|
|
|
|
|
changed: when winix demonizes it creates a three new descriptors (0, 1 and 3)
pointing to /dev/null
added: DbBase::AssertValueBin(PGresult * r, int row, int col, std::string & result)
it reads binary (bytea) data
added: DbTextStream can handle 'bool' types now
(is puts 'true' of 'false' to the stream)
changed: now passwords can be stored either as plain text, a hash or can be encrypted
with RSA
currently we have following hashes:
md4, md5, sha1, sha224, sha256, sha384, sha512
we are using openssl to manage them
(look at config options for more info)
changed: winix version to 0.4.7
added: class Run - you can run any program from os and send a buffer to its standard input
and read what the program put on its standard output
added: class Crypt (in System) - calculating hashes, and crypting/decrypting
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@734 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-06-09 23:22:08 +02:00
|
|
|
static int CharToInt(char c);
|
|
|
|
static bool IsCorrectOctalDigit(char c);
|
|
|
|
static int UnescapeBin(const char * str, size_t & i, size_t len);
|
2010-09-18 02:51:12 +02:00
|
|
|
|
changed: when winix demonizes it creates a three new descriptors (0, 1 and 3)
pointing to /dev/null
added: DbBase::AssertValueBin(PGresult * r, int row, int col, std::string & result)
it reads binary (bytea) data
added: DbTextStream can handle 'bool' types now
(is puts 'true' of 'false' to the stream)
changed: now passwords can be stored either as plain text, a hash or can be encrypted
with RSA
currently we have following hashes:
md4, md5, sha1, sha224, sha256, sha384, sha512
we are using openssl to manage them
(look at config options for more info)
changed: winix version to 0.4.7
added: class Run - you can run any program from os and send a buffer to its standard input
and read what the program put on its standard output
added: class Crypt (in System) - calculating hashes, and crypting/decrypting
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@734 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-06-09 23:22:08 +02:00
|
|
|
DbTextStream bquery;
|
2012-01-12 03:24:08 +01:00
|
|
|
PT::ConfParser conf_parser;
|
2010-11-21 01:19:17 +01:00
|
|
|
|
2010-09-18 02:51:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|