2010-09-18 02:51:12 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
2014-10-04 20:04:03 +02:00
|
|
|
* and is distributed under the 2-Clause BSD licence.
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2018-01-06 19:12:53 +01:00
|
|
|
* Copyright (c) 2010-2018, Tomasz Sowa
|
2010-09-18 02:51:12 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2014-10-04 20:04:03 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2010-09-18 02:51:12 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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-05-01 00:53:54 +02:00
|
|
|
#include "space/spaceparser.h"
|
2012-05-27 01:04:49 +02:00
|
|
|
#include "date/date.h"
|
2018-11-21 12:03:53 +01:00
|
|
|
#include "core/winixbase.h"
|
|
|
|
|
2012-05-27 01:04:49 +02:00
|
|
|
|
2010-09-18 02:51:12 +02:00
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2010-09-18 02:51:12 +02:00
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
class DbBase : public WinixBase
|
2010-09-18 02:51:12 +02:00
|
|
|
{
|
|
|
|
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 DbTextStream & query);
|
2012-02-12 15:52:52 +01:00
|
|
|
PGresult * AssertQuery(const char * q, ExecStatusType t);
|
|
|
|
PGresult * AssertQuery(const DbTextStream & query, ExecStatusType t);
|
2010-09-18 02:51:12 +02:00
|
|
|
void AssertResult(PGresult * r, ExecStatusType t);
|
2018-11-21 12:03:53 +01:00
|
|
|
int AssertColumn(PGresult * r, const char * column_name);
|
|
|
|
|
|
|
|
const char * AssertValue(PGresult * r, int row, int col);
|
|
|
|
const std::wstring & AssertValueWide(PGresult * r, int row, int col); // warning: this method uses a static buffer
|
|
|
|
void AssertValueWide(PGresult * r, int row, int col, std::wstring & result);
|
|
|
|
void AssertValueBin(PGresult * r, int row, int col, std::string & result);
|
|
|
|
long AssertValueLong(PGresult * r, int row, int col);
|
|
|
|
int AssertValueInt(PGresult * r, int row, int col);
|
|
|
|
bool AssertValueBool(PGresult * r, int row, int col);
|
|
|
|
unsigned long AssertValueULong(PGresult * r, int row, int col);
|
|
|
|
unsigned int AssertValueUInt(PGresult * r, int row, int col);
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::Date AssertValueDate(PGresult * r, int row, int col);
|
2018-11-21 12:03:53 +01:00
|
|
|
|
2021-05-20 20:59:12 +02:00
|
|
|
bool AssertValueSpace(PGresult * r, int row, int col, pt::Space & space);
|
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);
|
|
|
|
|
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
|
|
|
|
2012-08-15 21:33:20 +02:00
|
|
|
// new API (returns only bool)
|
|
|
|
bool EndTrans(bool everything_ok);
|
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
void UnescapeBin(const char * str, size_t len, std::string & out, bool clear_out = true);
|
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
|
|
|
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:
|
|
|
|
|
2012-09-11 07:19:45 +02:00
|
|
|
// static int CharToInt(char c);
|
|
|
|
// static bool IsCorrectOctalDigit(char c);
|
|
|
|
// static int UnescapeBin(const char * str, size_t & i, size_t len);
|
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
char UnescapeBinHexToDigit(char hex);
|
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;
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::SpaceParser conf_parser;
|
2010-11-21 01:19:17 +01:00
|
|
|
|
2010-09-18 02:51:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
} // namespace Winix
|
|
|
|
|
|
|
|
|
2010-09-18 02:51:12 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|