added: a new class Clearer with clear_value() methods moved from DbConnector
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1122 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
38b85722b8
commit
fdc44c56eb
|
@ -11,11 +11,21 @@ baseexpression.o: ../../pikotools/convert/text.h
|
|||
baseexpression.o: ../../pikotools/convert/misc.h
|
||||
baseexpression.o: ../../pikotools/membuffer/membuffer.h
|
||||
baseexpression.o: ../../pikotools/textstream/types.h morm_types.h model.h
|
||||
baseexpression.o: modelconnector.h dbconnector.h dbexpression.h
|
||||
baseexpression.o: ../../pikotools/logger/logger.h flatexpression.h
|
||||
baseexpression.o: flatconnector.h ../../pikotools/utf8/utf8.h
|
||||
dbconnector.o: dbconnector.h dbexpression.h baseexpression.h
|
||||
dbconnector.o: ../../pikotools/textstream/textstream.h
|
||||
baseexpression.o: modelconnector.h clearer.h dbconnector.h
|
||||
baseexpression.o: ../../pikotools/logger/logger.h flatconnector.h
|
||||
baseexpression.o: dbexpression.h flatexpression.h ../../pikotools/utf8/utf8.h
|
||||
clearer.o: clearer.h ../../pikotools/date/date.h
|
||||
clearer.o: ../../pikotools/convert/convert.h
|
||||
clearer.o: ../../pikotools/convert/inttostr.h
|
||||
clearer.o: ../../pikotools/convert/strtoint.h ../../pikotools/convert/text.h
|
||||
clearer.o: ../../pikotools/convert/misc.h model.h
|
||||
clearer.o: ../../pikotools/textstream/textstream.h
|
||||
clearer.o: ../../pikotools/space/space.h ../../pikotools/textstream/types.h
|
||||
clearer.o: ../../pikotools/membuffer/membuffer.h
|
||||
clearer.o: ../../pikotools/textstream/types.h modelconnector.h dbconnector.h
|
||||
clearer.o: ../../pikotools/logger/logger.h flatconnector.h dbexpression.h
|
||||
clearer.o: baseexpression.h morm_types.h flatexpression.h
|
||||
dbconnector.o: dbconnector.h ../../pikotools/textstream/textstream.h
|
||||
dbconnector.o: ../../pikotools/space/space.h
|
||||
dbconnector.o: ../../pikotools/textstream/types.h ../../pikotools/date/date.h
|
||||
dbconnector.o: ../../pikotools/convert/convert.h
|
||||
|
@ -23,9 +33,11 @@ dbconnector.o: ../../pikotools/convert/inttostr.h
|
|||
dbconnector.o: ../../pikotools/convert/strtoint.h
|
||||
dbconnector.o: ../../pikotools/convert/text.h ../../pikotools/convert/misc.h
|
||||
dbconnector.o: ../../pikotools/membuffer/membuffer.h
|
||||
dbconnector.o: ../../pikotools/textstream/types.h morm_types.h
|
||||
dbconnector.o: ../../pikotools/logger/logger.h model.h modelconnector.h
|
||||
dbconnector.o: flatexpression.h flatconnector.h ../../pikotools/utf8/utf8.h
|
||||
dbconnector.o: ../../pikotools/textstream/types.h
|
||||
dbconnector.o: ../../pikotools/logger/logger.h dbexpression.h
|
||||
dbconnector.o: baseexpression.h morm_types.h model.h modelconnector.h
|
||||
dbconnector.o: clearer.h flatconnector.h flatexpression.h
|
||||
dbconnector.o: ../../pikotools/utf8/utf8.h
|
||||
dbexpression.o: dbexpression.h baseexpression.h
|
||||
dbexpression.o: ../../pikotools/textstream/textstream.h
|
||||
dbexpression.o: ../../pikotools/space/space.h
|
||||
|
@ -36,8 +48,7 @@ dbexpression.o: ../../pikotools/convert/strtoint.h
|
|||
dbexpression.o: ../../pikotools/convert/text.h ../../pikotools/convert/misc.h
|
||||
dbexpression.o: ../../pikotools/membuffer/membuffer.h
|
||||
dbexpression.o: ../../pikotools/textstream/types.h morm_types.h
|
||||
flatconnector.o: flatconnector.h flatexpression.h baseexpression.h
|
||||
flatconnector.o: ../../pikotools/textstream/textstream.h
|
||||
flatconnector.o: flatconnector.h ../../pikotools/textstream/textstream.h
|
||||
flatconnector.o: ../../pikotools/space/space.h
|
||||
flatconnector.o: ../../pikotools/textstream/types.h
|
||||
flatconnector.o: ../../pikotools/date/date.h
|
||||
|
@ -47,9 +58,10 @@ flatconnector.o: ../../pikotools/convert/strtoint.h
|
|||
flatconnector.o: ../../pikotools/convert/text.h
|
||||
flatconnector.o: ../../pikotools/convert/misc.h
|
||||
flatconnector.o: ../../pikotools/membuffer/membuffer.h
|
||||
flatconnector.o: ../../pikotools/textstream/types.h morm_types.h model.h
|
||||
flatconnector.o: modelconnector.h dbconnector.h dbexpression.h
|
||||
flatconnector.o: ../../pikotools/logger/logger.h
|
||||
flatconnector.o: ../../pikotools/textstream/types.h flatexpression.h
|
||||
flatconnector.o: baseexpression.h morm_types.h model.h modelconnector.h
|
||||
flatconnector.o: clearer.h dbconnector.h ../../pikotools/logger/logger.h
|
||||
flatconnector.o: dbexpression.h
|
||||
flatexpression.o: flatexpression.h baseexpression.h
|
||||
flatexpression.o: ../../pikotools/textstream/textstream.h
|
||||
flatexpression.o: ../../pikotools/space/space.h
|
||||
|
@ -62,8 +74,8 @@ flatexpression.o: ../../pikotools/convert/text.h
|
|||
flatexpression.o: ../../pikotools/convert/misc.h
|
||||
flatexpression.o: ../../pikotools/membuffer/membuffer.h
|
||||
flatexpression.o: ../../pikotools/textstream/types.h morm_types.h
|
||||
jsonconnector.o: jsonconnector.h flatconnector.h flatexpression.h
|
||||
jsonconnector.o: baseexpression.h ../../pikotools/textstream/textstream.h
|
||||
jsonconnector.o: jsonconnector.h flatconnector.h
|
||||
jsonconnector.o: ../../pikotools/textstream/textstream.h
|
||||
jsonconnector.o: ../../pikotools/space/space.h
|
||||
jsonconnector.o: ../../pikotools/textstream/types.h
|
||||
jsonconnector.o: ../../pikotools/date/date.h
|
||||
|
@ -73,8 +85,8 @@ jsonconnector.o: ../../pikotools/convert/strtoint.h
|
|||
jsonconnector.o: ../../pikotools/convert/text.h
|
||||
jsonconnector.o: ../../pikotools/convert/misc.h
|
||||
jsonconnector.o: ../../pikotools/membuffer/membuffer.h
|
||||
jsonconnector.o: ../../pikotools/textstream/types.h morm_types.h
|
||||
jsonconnector.o: jsonexpression.h
|
||||
jsonconnector.o: ../../pikotools/textstream/types.h jsonexpression.h
|
||||
jsonconnector.o: flatexpression.h baseexpression.h morm_types.h
|
||||
jsonexpression.o: jsonexpression.h flatexpression.h baseexpression.h
|
||||
jsonexpression.o: ../../pikotools/textstream/textstream.h
|
||||
jsonexpression.o: ../../pikotools/space/space.h
|
||||
|
@ -93,26 +105,22 @@ model.o: ../../pikotools/date/date.h ../../pikotools/convert/convert.h
|
|||
model.o: ../../pikotools/convert/inttostr.h
|
||||
model.o: ../../pikotools/convert/strtoint.h ../../pikotools/convert/text.h
|
||||
model.o: ../../pikotools/convert/misc.h ../../pikotools/membuffer/membuffer.h
|
||||
model.o: ../../pikotools/textstream/types.h modelconnector.h baseexpression.h
|
||||
model.o: morm_types.h dbconnector.h dbexpression.h
|
||||
model.o: ../../pikotools/logger/logger.h flatexpression.h flatconnector.h
|
||||
modelconnector.o: modelconnector.h baseexpression.h
|
||||
modelconnector.o: ../../pikotools/textstream/textstream.h
|
||||
modelconnector.o: ../../pikotools/space/space.h
|
||||
modelconnector.o: ../../pikotools/textstream/types.h
|
||||
modelconnector.o: ../../pikotools/date/date.h
|
||||
model.o: ../../pikotools/textstream/types.h modelconnector.h clearer.h
|
||||
model.o: dbconnector.h ../../pikotools/logger/logger.h flatconnector.h
|
||||
model.o: dbexpression.h baseexpression.h morm_types.h flatexpression.h
|
||||
modelconnector.o: modelconnector.h clearer.h ../../pikotools/date/date.h
|
||||
modelconnector.o: ../../pikotools/convert/convert.h
|
||||
modelconnector.o: ../../pikotools/convert/inttostr.h
|
||||
modelconnector.o: ../../pikotools/convert/strtoint.h
|
||||
modelconnector.o: ../../pikotools/convert/text.h
|
||||
modelconnector.o: ../../pikotools/convert/misc.h
|
||||
modelconnector.o: ../../pikotools/convert/misc.h dbconnector.h
|
||||
modelconnector.o: ../../pikotools/textstream/textstream.h
|
||||
modelconnector.o: ../../pikotools/space/space.h
|
||||
modelconnector.o: ../../pikotools/textstream/types.h
|
||||
modelconnector.o: ../../pikotools/membuffer/membuffer.h
|
||||
modelconnector.o: ../../pikotools/textstream/types.h morm_types.h
|
||||
modelconnector.o: dbconnector.h dbexpression.h
|
||||
modelconnector.o: ../../pikotools/logger/logger.h flatexpression.h
|
||||
modelconnector.o: flatconnector.h model.h
|
||||
postgresqlconnector.o: postgresqlconnector.h dbconnector.h dbexpression.h
|
||||
postgresqlconnector.o: baseexpression.h
|
||||
modelconnector.o: ../../pikotools/textstream/types.h
|
||||
modelconnector.o: ../../pikotools/logger/logger.h flatconnector.h
|
||||
postgresqlconnector.o: postgresqlconnector.h dbconnector.h
|
||||
postgresqlconnector.o: ../../pikotools/textstream/textstream.h
|
||||
postgresqlconnector.o: ../../pikotools/space/space.h
|
||||
postgresqlconnector.o: ../../pikotools/textstream/types.h
|
||||
|
@ -123,9 +131,10 @@ postgresqlconnector.o: ../../pikotools/convert/strtoint.h
|
|||
postgresqlconnector.o: ../../pikotools/convert/text.h
|
||||
postgresqlconnector.o: ../../pikotools/convert/misc.h
|
||||
postgresqlconnector.o: ../../pikotools/membuffer/membuffer.h
|
||||
postgresqlconnector.o: ../../pikotools/textstream/types.h morm_types.h
|
||||
postgresqlconnector.o: ../../pikotools/textstream/types.h
|
||||
postgresqlconnector.o: ../../pikotools/logger/logger.h
|
||||
postgresqlconnector.o: ../../pikotools/utf8/utf8.h postgresqlexpression.h
|
||||
postgresqlconnector.o: dbexpression.h baseexpression.h morm_types.h
|
||||
postgresqlconnector.o: ../../pikotools/convert/strtoint.h
|
||||
postgresqlexpression.o: postgresqlexpression.h dbexpression.h
|
||||
postgresqlexpression.o: baseexpression.h
|
||||
|
|
|
@ -1 +1 @@
|
|||
o = baseexpression.o dbconnector.o dbexpression.o flatconnector.o flatexpression.o jsonconnector.o jsonexpression.o model.o modelconnector.o postgresqlconnector.o postgresqlexpression.o
|
||||
o = baseexpression.o clearer.o dbconnector.o dbexpression.o flatconnector.o flatexpression.o jsonconnector.o jsonexpression.o model.o modelconnector.o postgresqlconnector.o postgresqlexpression.o
|
|
@ -142,17 +142,16 @@ public:
|
|||
{
|
||||
field_before();
|
||||
|
||||
// IMPLEMENTME
|
||||
// if( work_mode == MORM_WORK_MODE_MODEL_FIELDS )
|
||||
// {
|
||||
// put_field_name(field_name);
|
||||
// }
|
||||
// else
|
||||
// if( work_mode == MORM_WORK_MODE_MODEL_VALUES )
|
||||
// {
|
||||
// put_field_value(field_value);
|
||||
// }
|
||||
// else
|
||||
if( work_mode == MORM_WORK_MODE_MODEL_FIELDS )
|
||||
{
|
||||
put_field_name(field_name);
|
||||
}
|
||||
else
|
||||
if( work_mode == MORM_WORK_MODE_MODEL_VALUES )
|
||||
{
|
||||
generate_from_model(field_model); // is it ok as a value?
|
||||
}
|
||||
else
|
||||
if( work_mode == MORM_WORK_MODE_MODEL_FIELDS_VALUES )
|
||||
{
|
||||
put_field_name(field_name);
|
||||
|
@ -217,16 +216,6 @@ protected:
|
|||
|
||||
std::wstring column_prefix;
|
||||
|
||||
// virtual void map_fields(Model * model)
|
||||
// {
|
||||
// work_mode = model->work_mode;
|
||||
// out_stream = model->out_stream;
|
||||
// is_insert = model->is_insert;
|
||||
// is_update = model->is_update;
|
||||
//
|
||||
// generate_from_model();
|
||||
// }
|
||||
|
||||
virtual void generate_from_model(Model & model);
|
||||
|
||||
virtual void before_generate_from_model();
|
||||
|
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* This file is a part of morm
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "clearer.h"
|
||||
#include "model.h"
|
||||
|
||||
|
||||
namespace morm
|
||||
{
|
||||
|
||||
|
||||
Clearer::Clearer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Clearer::~Clearer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Clearer::clear_value(char & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
|
||||
void Clearer::clear_value(unsigned char & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
|
||||
void Clearer::clear_value(std::wstring & field_value)
|
||||
{
|
||||
field_value.clear();
|
||||
}
|
||||
|
||||
|
||||
void Clearer::clear_value(std::string & field_value)
|
||||
{
|
||||
field_value.clear();
|
||||
}
|
||||
|
||||
|
||||
void Clearer::clear_value(bool & field_value)
|
||||
{
|
||||
field_value = false;
|
||||
}
|
||||
|
||||
void Clearer::clear_value(short & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void Clearer::clear_value(unsigned short & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void Clearer::clear_value(int & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void Clearer::clear_value(unsigned int & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void Clearer::clear_value(long & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void Clearer::clear_value(unsigned long & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void Clearer::clear_value(long long & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void Clearer::clear_value(unsigned long long & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void Clearer::clear_value(float & field_value)
|
||||
{
|
||||
field_value = 0.0f;
|
||||
}
|
||||
|
||||
void Clearer::clear_value(double & field_value)
|
||||
{
|
||||
field_value = 0.0;
|
||||
}
|
||||
|
||||
void Clearer::clear_value(long double & field_value)
|
||||
{
|
||||
field_value = 0.0;
|
||||
}
|
||||
|
||||
void Clearer::clear_value(PT::Date & field_value)
|
||||
{
|
||||
field_value.Clear();
|
||||
}
|
||||
|
||||
void Clearer::clear_model(Model & field_value)
|
||||
{
|
||||
field_value.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* This file is a part of morm
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_morm_clearer
|
||||
#define headerfile_morm_clearer
|
||||
|
||||
#include <string>
|
||||
#include "date/date.h"
|
||||
|
||||
|
||||
namespace morm
|
||||
{
|
||||
class Model;
|
||||
|
||||
|
||||
class Clearer
|
||||
{
|
||||
public:
|
||||
|
||||
Clearer();
|
||||
virtual ~Clearer();
|
||||
|
||||
virtual void clear_value(char & field_value);
|
||||
virtual void clear_value(unsigned char & field_value);
|
||||
virtual void clear_value(std::wstring & field_value);
|
||||
virtual void clear_value(std::string & field_value);
|
||||
virtual void clear_value(bool & field_value);
|
||||
virtual void clear_value(short & field_value);
|
||||
virtual void clear_value(unsigned short & field_value);
|
||||
virtual void clear_value(int & field_value);
|
||||
virtual void clear_value(unsigned int & field_value);
|
||||
virtual void clear_value(long & field_value);
|
||||
virtual void clear_value(unsigned long & field_value);
|
||||
virtual void clear_value(long long & field_value);
|
||||
virtual void clear_value(unsigned long long & field_value);
|
||||
virtual void clear_value(float & field_value);
|
||||
virtual void clear_value(double & field_value);
|
||||
virtual void clear_value(long double & field_value);
|
||||
virtual void clear_value(PT::Date & field_value);
|
||||
|
||||
virtual void clear_model(Model & field_value);
|
||||
|
||||
template<typename ModelContainer>
|
||||
void clear_container(ModelContainer & container)
|
||||
{
|
||||
container.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// give here containers?
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -300,97 +300,6 @@ const char * DbConnector::get_field_string_value(const wchar_t * field_name)
|
|||
|
||||
|
||||
|
||||
void DbConnector::clear_value(char & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(unsigned char & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(std::wstring & field_value)
|
||||
{
|
||||
field_value.clear();
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::clear_value(std::string & field_value)
|
||||
{
|
||||
field_value.clear();
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::clear_value(bool & field_value)
|
||||
{
|
||||
field_value = false;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(short & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(unsigned short & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(int & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(unsigned int & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(long & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(unsigned long & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(long long & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(unsigned long long & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(float & field_value)
|
||||
{
|
||||
field_value = 0.0f;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(double & field_value)
|
||||
{
|
||||
field_value = 0.0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(long double & field_value)
|
||||
{
|
||||
field_value = 0.0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(PT::Date & field_value)
|
||||
{
|
||||
field_value.Clear();
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(Model & field_value)
|
||||
{
|
||||
field_value.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -93,34 +93,6 @@ public:
|
|||
|
||||
//virtual void map_values_from_query(Model & model);
|
||||
|
||||
// these methods should be somewhere else
|
||||
// flat_parsers (json parser) can use them as well
|
||||
virtual void clear_value(char & field_value);
|
||||
virtual void clear_value(unsigned char & field_value);
|
||||
virtual void clear_value(std::wstring & field_value);
|
||||
virtual void clear_value(std::string & field_value);
|
||||
virtual void clear_value(bool & field_value);
|
||||
virtual void clear_value(short & field_value);
|
||||
virtual void clear_value(unsigned short & field_value);
|
||||
virtual void clear_value(int & field_value);
|
||||
virtual void clear_value(unsigned int & field_value);
|
||||
virtual void clear_value(long & field_value);
|
||||
virtual void clear_value(unsigned long & field_value);
|
||||
virtual void clear_value(long long & field_value);
|
||||
virtual void clear_value(unsigned long long & field_value);
|
||||
virtual void clear_value(float & field_value);
|
||||
virtual void clear_value(double & field_value);
|
||||
virtual void clear_value(long double & field_value);
|
||||
virtual void clear_value(PT::Date & field_value);
|
||||
|
||||
virtual void clear_value(Model & field_value);
|
||||
|
||||
// template<typename ModelClass>
|
||||
// void clear_value(std::list<ModelClass> & list)
|
||||
// {
|
||||
// list.clear();
|
||||
// }
|
||||
|
||||
virtual void get_value(const char * value_str, char & field_value);
|
||||
virtual void get_value(const char * value_str, unsigned char & field_value);
|
||||
virtual void get_value(const char * value_str, std::wstring & field_value);
|
||||
|
|
96
src/model.h
96
src/model.h
|
@ -58,6 +58,17 @@ public:
|
|||
|
||||
ModelData() {}
|
||||
virtual ~ModelData() {}
|
||||
|
||||
/*
|
||||
* may to add:
|
||||
* std::set<std::wstring> skip_columns;
|
||||
* and Finder can use this
|
||||
* also update and insert from Model
|
||||
* (but what about the same name of columns through the whole objects-tree?
|
||||
* may we can save the name of the table too?)
|
||||
*
|
||||
*
|
||||
*/
|
||||
};
|
||||
|
||||
enum SaveMode
|
||||
|
@ -446,52 +457,17 @@ protected:
|
|||
|
||||
if( model_connector_mode == MORM_MODEL_CONNECTOR_MODE_CLEARING_VALUE )
|
||||
{
|
||||
DbConnector * db_connector = model_connector->get_db_connector();
|
||||
Clearer * clearer = model_connector->get_clearer();
|
||||
|
||||
if( db_connector )
|
||||
if( clearer )
|
||||
{
|
||||
// IMPROVE ME those clearing should be moved to a better place
|
||||
db_connector->clear_value(field_value);
|
||||
clearer->clear_value(field_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// template<typename ModelClass>
|
||||
// void field_list(const wchar_t * db_field_name, const wchar_t * flat_field_name, std::list<ModelClass> & field_list, bool insertable, bool updatable, bool is_primary_key)
|
||||
template<typename ModelContainer>
|
||||
void field_list(const wchar_t * db_field_name, const wchar_t * flat_field_name, ModelContainer & field_container, bool insertable, bool updatable, bool is_primary_key)
|
||||
{
|
||||
// IMPLEMENTME what about db?
|
||||
if( model_connector )
|
||||
{
|
||||
if( model_connector_mode == MORM_MODEL_CONNECTOR_MODE_GENERATING_FLAT_STRING )
|
||||
{
|
||||
FlatConnector * flat_connector = model_connector->get_flat_connector();
|
||||
|
||||
if( flat_connector )
|
||||
{
|
||||
FlatExpression * flat_expression = flat_connector->get_expression();
|
||||
|
||||
if( flat_expression && !is_empty_field(flat_field_name) )
|
||||
{
|
||||
// IMPROVE ME
|
||||
// what about model_data and save_mode?
|
||||
// may it should be placed inside some structure?
|
||||
flat_expression->field_list(flat_field_name, field_container, insertable, updatable, is_primary_key, model_connector, model_connector_mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( model_connector_mode == MORM_MODEL_CONNECTOR_MODE_CLEARING_VALUE )
|
||||
{
|
||||
field_container.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void field_model(const wchar_t * db_field_name, const wchar_t * flat_field_name, Model & field_model, bool insertable, bool updatable, bool is_primary_key)
|
||||
{
|
||||
if( model_connector )
|
||||
|
@ -518,7 +494,49 @@ protected:
|
|||
|
||||
if( model_connector_mode == MORM_MODEL_CONNECTOR_MODE_CLEARING_VALUE )
|
||||
{
|
||||
field_model.clear();
|
||||
Clearer * clearer = model_connector->get_clearer();
|
||||
|
||||
if( clearer )
|
||||
{
|
||||
clearer->clear_model(field_model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename ModelContainer>
|
||||
void field_list(const wchar_t * db_field_name, const wchar_t * flat_field_name, ModelContainer & field_container, bool insertable, bool updatable, bool is_primary_key)
|
||||
{
|
||||
// IMPLEMENTME what about db?
|
||||
if( model_connector )
|
||||
{
|
||||
if( model_connector_mode == MORM_MODEL_CONNECTOR_MODE_GENERATING_FLAT_STRING )
|
||||
{
|
||||
FlatConnector * flat_connector = model_connector->get_flat_connector();
|
||||
|
||||
if( flat_connector )
|
||||
{
|
||||
FlatExpression * flat_expression = flat_connector->get_expression();
|
||||
|
||||
if( flat_expression && !is_empty_field(flat_field_name) )
|
||||
{
|
||||
// IMPROVE ME
|
||||
// what about model_data and save_mode?
|
||||
// may it should be placed inside some structure?
|
||||
flat_expression->field_list(flat_field_name, field_container, insertable, updatable, is_primary_key, model_connector, model_connector_mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( model_connector_mode == MORM_MODEL_CONNECTOR_MODE_CLEARING_VALUE )
|
||||
{
|
||||
Clearer * clearer = model_connector->get_clearer();
|
||||
|
||||
if( clearer )
|
||||
{
|
||||
clearer->clear_container(field_container);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,11 +47,16 @@ ModelConnector::ModelConnector()
|
|||
|
||||
out_stream = nullptr;
|
||||
out_stream_allocated = false;
|
||||
|
||||
clearer = nullptr;
|
||||
clearer_allocated = false;
|
||||
}
|
||||
|
||||
|
||||
ModelConnector::~ModelConnector()
|
||||
{
|
||||
deallocate_stream();
|
||||
deallocate_clearer();
|
||||
}
|
||||
|
||||
|
||||
|
@ -95,6 +100,33 @@ void ModelConnector::allocate_default_stream_if_needed()
|
|||
}
|
||||
|
||||
|
||||
void ModelConnector::deallocate_clearer()
|
||||
{
|
||||
if( clearer_allocated )
|
||||
{
|
||||
delete clearer;
|
||||
clearer = nullptr;
|
||||
clearer_allocated = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ModelConnector::allocate_default_clearer()
|
||||
{
|
||||
deallocate_clearer();
|
||||
clearer = new Clearer();
|
||||
clearer_allocated = true;
|
||||
}
|
||||
|
||||
|
||||
void ModelConnector::allocate_default_clearer_if_needed()
|
||||
{
|
||||
if( !clearer )
|
||||
{
|
||||
allocate_default_clearer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ModelConnector::set_stream(PT::TextStream & stream)
|
||||
{
|
||||
|
@ -136,6 +168,21 @@ DbConnector * ModelConnector::get_db_connector()
|
|||
}
|
||||
|
||||
|
||||
void ModelConnector::set_clearer(Clearer & clearer)
|
||||
{
|
||||
deallocate_clearer();
|
||||
this->clearer = &clearer;
|
||||
}
|
||||
|
||||
|
||||
Clearer * ModelConnector::get_clearer()
|
||||
{
|
||||
allocate_default_clearer_if_needed();
|
||||
return this->clearer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ModelConnector::was_db_error()
|
||||
{
|
||||
if( db_connector )
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#ifndef headerfile_morm_modelconnector
|
||||
#define headerfile_morm_modelconnector
|
||||
|
||||
#include "clearer.h"
|
||||
#include "dbconnector.h"
|
||||
#include "flatconnector.h"
|
||||
#include "logger/logger.h"
|
||||
|
@ -76,6 +77,8 @@ public:
|
|||
virtual void set_db_connector(DbConnector & db_connector);
|
||||
virtual DbConnector * get_db_connector();
|
||||
|
||||
virtual void set_clearer(Clearer & clearer);
|
||||
virtual Clearer * get_clearer();
|
||||
|
||||
|
||||
protected:
|
||||
|
@ -88,9 +91,16 @@ protected:
|
|||
PT::TextStream * out_stream; // IMPROVE ME give here an interface to the base stream (implement him)
|
||||
bool out_stream_allocated;
|
||||
|
||||
Clearer * clearer;
|
||||
bool clearer_allocated;
|
||||
|
||||
void deallocate_stream();
|
||||
void allocate_default_stream();
|
||||
void allocate_default_stream_if_needed();
|
||||
void deallocate_stream();
|
||||
|
||||
void deallocate_clearer();
|
||||
void allocate_default_clearer();
|
||||
void allocate_default_clearer_if_needed();
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue