Browse Source

Merge pull request 'winix_fullmorm' (#4) from winix_fullmorm into master

Reviewed-on: https://gitea.ttmath.org/tomasz.sowa/morm/pulls/4
master
Tomasz Sowa 4 weeks ago
parent
commit
284cbc5c66
  1. 3
      .gitignore
  2. 9
      samples/Makefile
  3. 22
      samples/Makefile.dep
  4. 31
      samples/attachment.h
  5. 119
      samples/attachment2.h
  6. 12
      samples/language.h
  7. 16
      samples/main.cpp
  8. 40
      samples/person.h
  9. 77
      samples/sample01.h
  10. 12
      samples/type.h
  11. 191
      src/Makefile.dep
  12. 707
      src/baseexpression.cpp
  13. 347
      src/baseexpression.h
  14. 13
      src/clearer.cpp
  15. 7
      src/clearer.h
  16. 4
      src/cursor.h
  17. 416
      src/dbconnector.cpp
  18. 105
      src/dbconnector.h
  19. 119
      src/dbexpression.cpp
  20. 48
      src/dbexpression.h
  21. 346
      src/finder.h
  22. 10
      src/finderhelper.h
  23. 2
      src/flatconnector.cpp
  24. 2
      src/flatconnector.h
  25. 4
      src/flatexpression.cpp
  26. 4
      src/flatexpression.h
  27. 167
      src/ft.h
  28. 111
      src/jsonexpression.cpp
  29. 23
      src/jsonexpression.h
  30. 886
      src/model.cpp
  31. 949
      src/model.h
  32. 12
      src/modelconnector.cpp
  33. 14
      src/modelconnector.h
  34. 56
      src/modelenv.h
  35. 215
      src/postgresqlconnector.cpp
  36. 21
      src/postgresqlconnector.h
  37. 124
      src/postgresqlexpression.cpp
  38. 29
      src/postgresqlexpression.h
  39. 14
      src/postgresqlqueryresult.cpp
  40. 2
      src/postgresqlqueryresult.h
  41. 6
      src/queryresult.cpp
  42. 2
      src/queryresult.h

3
.gitignore

@ -3,3 +3,6 @@
.settings/
*.o
*.a
log.txt
samples/log.txt
samples/mormsample

9
samples/Makefile

@ -7,13 +7,13 @@ GLOBAL_WORKING_DIR := $(shell pwd)/../..
endif
CXX = g++7
CXX = g++10
#CXX = clang++
# -fsanitize=address
# -Wl,-rpath=/usr/local/lib/gcc5 or just compile with -static-libstdc++
CXXFLAGS = -Wl,-rpath=/usr/local/lib/gcc7 -Wfatal-errors -fPIC -Wall -pedantic -O0 -g3 -gdwarf-2 -pthread -std=c++17 -I/usr/local/include -I$(GLOBAL_WORKING_DIR)/pikotools -I$(GLOBAL_WORKING_DIR)/morm/src
CXXFLAGS = -Wl,-rpath=/usr/local/lib/gcc10 -Wfatal-errors -fPIC -Wall -pedantic -O0 -g3 -gdwarf-2 -pthread -std=c++20 -I/usr/local/include -I$(GLOBAL_WORKING_DIR)/pikotools -I$(GLOBAL_WORKING_DIR)/morm/src
LDFLAGS = -L/usr/local/lib
@ -27,11 +27,12 @@ current_path := $(shell pwd)
global_relative_working_dir := $(shell relative_path $(current_path) $(GLOBAL_WORKING_DIR))
# IMPROVE ME
# add dependency to pikotools
all: morm $(name)
$(name): $(o)
$(name): morm $(o)
$(CXX) -o $(name) $(CXXFLAGS) $(LDFLAGS) $(o) $(GLOBAL_WORKING_DIR)/morm/src/morm.a $(GLOBAL_WORKING_DIR)/pikotools/log/log.a $(GLOBAL_WORKING_DIR)/pikotools/space/space.a $(GLOBAL_WORKING_DIR)/pikotools/mainspaceparser/mainspaceparser.a $(GLOBAL_WORKING_DIR)/pikotools/date/date.a $(GLOBAL_WORKING_DIR)/pikotools/convert/convert.a $(GLOBAL_WORKING_DIR)/pikotools/utf8/utf8.a $(LDFLAGS) -lpq -lpthread

22
samples/Makefile.dep

@ -2,11 +2,10 @@
main.o: ../../pikotools/mainspaceparser/mainspaceparser.h
main.o: ../../pikotools/space/space.h ../../pikotools/textstream/types.h
main.o: sample01.h basesample.h ../../morm/src/morm.h
main.o: ../../morm/src/morm_types.h ../../morm/src/model.h
main.o: ../../pikotools/textstream/textstream.h ../../pikotools/date/date.h
main.o: ../../pikotools/convert/inttostr.h
main.o: ../../pikotools/membuffer/membuffer.h
main.o: ../../pikotools/convert/inttostr.h sample01.h basesample.h
main.o: ../../morm/src/morm.h ../../morm/src/morm_types.h
main.o: ../../morm/src/model.h ../../pikotools/textstream/textstream.h
main.o: ../../pikotools/date/date.h ../../pikotools/membuffer/membuffer.h
main.o: ../../pikotools/textstream/types.h ../../morm/src/modelconnector.h
main.o: ../../morm/src/clearer.h ../../morm/src/dbconnector.h
main.o: ../../pikotools/log/log.h ../../pikotools/log/filelog.h
@ -14,10 +13,11 @@ main.o: ../../morm/src/queryresult.h ../../morm/src/flatconnector.h
main.o: ../../morm/src/dbexpression.h ../../morm/src/baseexpression.h
main.o: ../../morm/src/modelenv.h ../../morm/src/modeldata.h
main.o: ../../morm/src/cursorhelper.h ../../morm/src/finderhelper.h
main.o: ../../morm/src/fieldvaluehelper.h ../../morm/src/flatexpression.h
main.o: ../../morm/src/finder.h ../../pikotools/utf8/utf8.h
main.o: ../../morm/src/cursor.h ../../morm/src/jsonexpression.h
main.o: ../../morm/src/postgresqlexpression.h ../../morm/src/jsonconnector.h
main.o: ../../morm/src/postgresqlconnector.h
main.o: ../../morm/src/fieldvaluehelper.h ../../morm/src/ft.h
main.o: ../../morm/src/flatexpression.h ../../morm/src/finder.h
main.o: ../../pikotools/utf8/utf8.h ../../pikotools/utf8/utf8_templates.h
main.o: ../../pikotools/utf8/utf8_private.h ../../morm/src/cursor.h
main.o: ../../morm/src/jsonexpression.h ../../morm/src/postgresqlexpression.h
main.o: ../../morm/src/jsonconnector.h ../../morm/src/postgresqlconnector.h
main.o: ../../morm/src/postgresqlqueryresult.h person.h language.h
main.o: attachment.h type.h
main.o: attachment.h type.h attachment2.h

31
samples/attachment.h

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2019, Tomasz Sowa
* Copyright (c) 2019-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -38,7 +38,7 @@
#include <string>
#include "morm.h"
#include "type.h"
#include "language.h"
namespace morm
@ -54,7 +54,7 @@ CREATE TABLE public.attachment (
content text,
some_flags bool,
created_date timestamp with time zone,
bigint language_id,
language_id bigint,
primary key(id)
);
@ -71,32 +71,39 @@ public:
std::string content;
std::vector<Type> types;
bool some_flags;
PT::Date created_date;
pt::Date created_date;
Language language;
void map_fields()
{
field(L"id", id, false, false, true);
field(L"id", id, FT::no_insertable | FT::no_updatable | FT::primary_key);
field(L"person_id", person_id);
field(L"name", name);
field(L"content", content);
field(L"attachment_id", L"types", types);
//field(L"types", types);
field(L"attachment_id", L"types", types, FT::foreign_key_in_child);
field(L"some_flags", some_flags);
field(L"created_date", created_date);
field(L"language_id", L"language", language);
field(L"language_id", L"language", language, FT::foreign_key);
}
void prepare_table()
{
table(L"public", L"attachment");
}
void table_name(PT::TextStream & stream)
void after_select()
{
// schema.table_name or just table_name
stream << "public.attachment";
if( has_primary_key_set )
{
morm::Finder<Type> finder(model_connector);
types = finder.select().where().eq(L"attachment_id", id).get_vector();
}
}
void after_insert()
{
get_last_sequence(L"public.attachment_id_seq", id);
get_last_sequence_for_primary_key(L"public.attachment_id_seq", id);
}

119
samples/attachment2.h

@ -0,0 +1,119 @@
/*
* 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) 2021, 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_samples_attachment2
#define headerfile_morm_samples_attachment2
#include <string>
#include "morm.h"
#include "type.h"
#include "language.h"
namespace morm
{
namespace samples
{
/*
CREATE TABLE public.attachment2 (
id bigserial,
person_id bigint,
name varchar(64),
content text,
some_flags bool,
created_date timestamp with time zone,
language_id bigint,
primary key(id)
);
*/
// copied from Attachment and changed the table name
class Attachment2 : public morm::Model
{
public:
long id;
long person_id;
std::wstring name;
std::string content;
std::vector<Type> types;
bool some_flags;
pt::Date created_date;
Language language;
void map_fields()
{
field(L"id", id, FT::no_insertable | FT::no_updatable | FT::primary_key);
field(L"person_id", person_id);
field(L"name", name);
field(L"content", content);
field(L"attachment_id", L"types", types, FT::foreign_key_in_child);
field(L"some_flags", some_flags);
field(L"created_date", created_date);
field(L"language_id", L"language", language, FT::foreign_key);
}
void prepare_table()
{
table(L"public", L"attachment2");
}
void after_select()
{
if( has_primary_key_set )
{
morm::Finder<Type> finder(model_connector);
types = finder.select().where().eq(L"attachment_id", id).get_vector();
}
}
void after_insert()
{
get_last_sequence_for_primary_key(L"public.attachment2_id_seq", id);
}
};
}
}
#endif

12
samples/language.h

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2019, Tomasz Sowa
* Copyright (c) 2019-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -70,23 +70,21 @@ public:
void map_fields()
{
field(L"id", id, false, false, true);
field(L"id", id, FT::no_insertable | FT::no_updatable | FT::primary_key);
field(L"english_name", english_name);
field(L"local_name", local_name);
field(L"code_str", code_str);
field(L"code_int", code_int);
}
void table_name(PT::TextStream & stream)
void prepare_table()
{
// schema.table_name or just table_name
stream << "public.language";
table(L"public", L"language");
}
void after_insert()
{
get_last_sequence(L"public.language_id_seq", id);
get_last_sequence_for_primary_key(L"public.language_id_seq", id);
}

16
samples/main.cpp

@ -61,17 +61,17 @@ void print_syntax()
int main(int argc, const char ** argv)
{
PT::Space args;
PT::Space & args_options = args.FindAddSpace(L"options");
pt::Space args;
pt::Space & args_options = args.FindAddSpace(L"options");
args_options.Add(L"c", 1); // one argument - config file
args_options.Add(L"config", 1);
PT::MainSpaceParser main_parser;
pt::MainSpaceParser main_parser;
main_parser.UTF8(true);
main_parser.SetSpace(args);
PT::MainSpaceParser::Status args_status = main_parser.Parse(argc, argv);
pt::MainSpaceParser::Status args_status = main_parser.Parse(argc, argv);
if( args_status != PT::MainSpaceParser::status_ok )
if( args_status != pt::MainSpaceParser::status_ok )
{
std::cout << "Syntax error in arguments" << std::endl;
return 1;
@ -101,9 +101,9 @@ args_options.Add(L"config", 1);
* create database morm_test owner morm_test;
*
*/
PT::Log log;
PT::FileLog file_log;
PT::WTextStream log_buffer;
pt::Log log;
pt::FileLog file_log;
pt::WTextStream log_buffer;
file_log.init(L"log.txt", true, 4, true);
log.SetLogBuffer(&log_buffer);

40
samples/person.h

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2019, Tomasz Sowa
* Copyright (c) 2019-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -39,6 +39,7 @@
#include "morm.h"
#include "language.h"
#include "attachment.h"
#include "attachment2.h"
@ -64,48 +65,49 @@ class Person : public morm::Model
public:
long id;
std::wstring first_name;
std::wstring last_name;
std::wstring email;
Language language;
std::list<Attachment> attachments;
Attachment attachment;
Attachment2 attachment2;
void map_fields()
{
field(L"id", id, false, false, true);
//field(L"id", id, f::no_insertable | f::no_updatable | f::primary_key);
field(L"id", id, FT::no_insertable | FT::no_updatable | FT::primary_key);
field(L"language_id", L"language", language, FT::foreign_key);
field(L"first_name", first_name);
field(L"last_name", last_name);
field(L"email", email);
field(L"language_id", L"language", language);
field(L"person_id", L"attachments", attachments);
field(L"person_id", L"attachment", attachment, true, true, false);
//field(L"person_id", attachment, f::insertable | f::updatable | f::foreign_key);
//field(L"person_id", attachment, f::insertable, f::updatable, f::foreign_key);
field(L"person_id", L"attachments", attachments, FT::foreign_key_in_child);
field(L"person_id", L"attachment2", attachment2, FT::foreign_key_in_child | FT::no_insertable | FT::no_updatable);
}
void table_name(PT::TextStream & stream)
void prepare_table()
{
// schema.table_name or just table_name
stream << "public.person";
table(L"public", L"person");
}
void after_select()
{
morm::Finder<Attachment> finder(model_connector);
attachments = finder.select().where().eq(L"person_id", id).get_list();
if( has_primary_key_set )
{
morm::Finder<Attachment> finder(model_connector);
attachments = finder.select().where().eq(L"person_id", id).get_list();
morm::Finder<Attachment2> finder2(model_connector);
attachment2 = finder2.select().where().eq(L"person_id", id).get();
}
}
void after_insert()
{
get_last_sequence(L"public.person_id_seq", id);
get_last_sequence_for_primary_key(L"public.person_id_seq", id);
}

77
samples/sample01.h

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2019, Tomasz Sowa
* Copyright (c) 2019-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -32,6 +32,9 @@
*
*/
#ifndef headerfile_morm_samples_sample01
#define headerfile_morm_samples_sample01
#include <ctime>
#include "basesample.h"
#include "person.h"
@ -51,23 +54,37 @@ public:
void make()
{
// delete all datas
// delete from attachment; delete from attachment2; delete from language; delete from person; delete from types;
// select * from person; select * from attachment; select * from attachment2 ; select * from types; select * from language;
std::string str;
person.set_connector(model_connector);
load_defaults(person);
std::wstring sss = L"cosik wstawiony dynamicznie";
person.set_field_value_generic(L"email", L"email", sss);
//std::wstring sss = L"some text put dynamically";
//person.set_field_value_generic(L"email", L"email", sss);
//person.insert();
//person.update();
person.save();
//person.save();
//person.remove();
//person.to_text(str, true, true);
morm::Finder<Person> finder(model_connector);
Person p = finder.select().where().eq(L"id", 210).get();
p.to_text(str, true, true);
//std::list<Person> plist = finder.use_table_prefix(false).select().where().eq(L"id", 120).get_list();
//Person p = finder.use_table_prefix(false).select().where().eq(L"id", 120).get();
// Person p = finder.prepare_to_select().use_table_prefix(true).raw("select person.id as \"person.id\", person.first_name as \"person.first_name\", person.last_name as \"person.last_name\", person.email as \"person.email\", "
// "language.id as \"language.id\", language.english_name as \"language.english_name\", language.local_name as \"language.local_name\", language.code_str as \"language.code_str\", language.code_int as \"language.code_int\", "
@ -79,14 +96,13 @@ void make()
// "LEFT JOIN public.language AS language2 ON attachment.language_id = language2.id "
// "where person.id=120").get();
std::cout << "--------------------------------" << std::endl;
//std::cout << "--------------------------------" << std::endl;
//p.remove();
//std::cout << "--------------------------------" << std::endl;
std::string str;
//str += "--------\n";
person.to_text(str, true, true);
// for(Person & person : plist)
// {
@ -112,6 +128,7 @@ private:
person.first_name = L"MyFirstName";
person.last_name = L"MyLastName";
person.email = L"myemail@mydomain.ltd";
//person.set_save_mode(Model::DO_NOTHING_ON_SAVE);
person.set_save_mode(Model::DO_INSERT_ON_SAVE);
//person.set_save_mode(Model::DO_UPDATE_ON_SAVE);
@ -120,29 +137,38 @@ private:
person.language.local_name = L"polish";
person.language.code_str = L"en";
person.language.code_int = 200;
//person.language.set_save_mode(Model::DO_NOTHING_ON_SAVE);
person.language.set_save_mode(Model::DO_INSERT_ON_SAVE);
//person.language.set_save_mode(Model::DO_UPDATE_ON_SAVE);
std::time_t t = std::time(0);
// person.attachment.id = 40;
person.attachment.person_id = person.id;
person.attachment.created_date.FromTime(t);
person.attachment.name = L"attachment name";
person.attachment.content = "long binary content";
person.attachment.some_flags = true;
person.attachment.set_save_mode(Model::DO_INSERT_ON_SAVE);
// //person.attachment.set_save_mode(Model::DO_UPDATE_ON_SAVE);
//
person.attachment.language.id = 86;
person.attachment.language.english_name = L"attachment language";
person.attachment.language.local_name = L"attachment local name";
person.attachment.language.code_str = L"loen";
person.attachment.language.code_int = 300;
// person.attachment.language.set_save_mode(Model::DO_UPDATE_ON_SAVE);
Type type;
type.id = 0;
type.set_save_mode(Model::DO_INSERT_ON_SAVE);
person.attachment2.id = 40;
person.attachment2.person_id = person.id;
person.attachment2.created_date.FromTime(t);
person.attachment2.name = L"attachment name";
person.attachment2.content = "long binary content";
person.attachment2.some_flags = true;
person.attachment2.set_save_mode(Model::DO_INSERT_ON_SAVE);
// //person.attachment.set_save_mode(Model::DO_UPDATE_ON_SAVE);
person.attachment2.language.id = 86;
person.attachment2.language.english_name = L"attachment language";
person.attachment2.language.local_name = L"attachment local name";
person.attachment2.language.code_str = L"loen";
person.attachment2.language.code_int = 300;
person.attachment2.language.set_save_mode(Model::DO_INSERT_ON_SAVE);
person.attachment2.language.set_has_primary_key_set(true);
type.name = L"abcde - fghi";
person.attachment2.types.push_back(type);
type.name = L"second type";
person.attachment2.types.push_back(type);
Attachment attachment;
attachment.id = 0;
@ -186,7 +212,6 @@ private:
type.name = L"Typ dla attachment 3 - 3";
person.attachments.back().types.push_back(type);
//type.name = L"Typik";
//person.attachment.types.push_back(type);
@ -201,3 +226,5 @@ private:
}
}
#endif

12
samples/type.h

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2019, Tomasz Sowa
* Copyright (c) 2019-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -65,21 +65,19 @@ public:
void map_fields()
{
field(L"id", id, false, false, true);
field(L"id", id, FT::no_insertable | FT::no_updatable | FT::primary_key);
field(L"attachment_id", attachment_id);
field(L"name", name);
}
void table_name(PT::TextStream & stream)
void prepare_table()
{
// schema.table_name or just table_name
stream << "public.types";
table(L"public", L"types");
}
void after_insert()
{
get_last_sequence(L"public.types_id_seq", id);
get_last_sequence_for_primary_key(L"public.types_id_seq", id);
}

191
src/Makefile.dep

@ -1,162 +1,49 @@
# DO NOT DELETE
baseexpression.o: baseexpression.h ../../pikotools/textstream/textstream.h
baseexpression.o: ../../pikotools/space/space.h
baseexpression.o: ../../pikotools/textstream/types.h
baseexpression.o: ../../pikotools/date/date.h
baseexpression.o: ../../pikotools/convert/inttostr.h
baseexpression.o: ../../pikotools/membuffer/membuffer.h
baseexpression.o: ../../pikotools/textstream/types.h morm_types.h modelenv.h
baseexpression.o: modeldata.h cursorhelper.h queryresult.h
baseexpression.o: ../../pikotools/log/log.h ../../pikotools/log/filelog.h
baseexpression.o: finderhelper.h fieldvaluehelper.h model.h modelconnector.h
baseexpression.o: clearer.h dbconnector.h flatconnector.h dbexpression.h
baseexpression.o: flatexpression.h ../../pikotools/utf8/utf8.h
clearer.o: clearer.h ../../pikotools/date/date.h
clearer.o: ../../pikotools/convert/inttostr.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/log/log.h ../../pikotools/log/filelog.h
clearer.o: queryresult.h flatconnector.h dbexpression.h baseexpression.h
clearer.o: morm_types.h modelenv.h modeldata.h cursorhelper.h finderhelper.h
baseexpression.o: baseexpression.h morm_types.h modelenv.h modeldata.h
baseexpression.o: cursorhelper.h queryresult.h finderhelper.h
baseexpression.o: fieldvaluehelper.h ft.h model.h modelconnector.h clearer.h
baseexpression.o: dbconnector.h flatconnector.h dbexpression.h
baseexpression.o: flatexpression.h
clearer.o: clearer.h model.h modelconnector.h dbconnector.h queryresult.h
clearer.o: ft.h flatconnector.h dbexpression.h baseexpression.h morm_types.h
clearer.o: modelenv.h modeldata.h cursorhelper.h finderhelper.h
clearer.o: fieldvaluehelper.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/inttostr.h
dbconnector.o: ../../pikotools/membuffer/membuffer.h
dbconnector.o: ../../pikotools/textstream/types.h ../../pikotools/log/log.h
dbconnector.o: ../../pikotools/log/filelog.h queryresult.h dbexpression.h
dbconnector.o: dbconnector.h queryresult.h ft.h dbexpression.h
dbconnector.o: baseexpression.h morm_types.h modelenv.h modeldata.h
dbconnector.o: cursorhelper.h finderhelper.h fieldvaluehelper.h model.h
dbconnector.o: modelconnector.h clearer.h flatconnector.h flatexpression.h
dbconnector.o: ../../pikotools/utf8/utf8.h ../../pikotools/convert/convert.h
dbconnector.o: ../../pikotools/convert/inttostr.h
dbconnector.o: ../../pikotools/convert/patternreplacer.h
dbconnector.o: ../../pikotools/convert/strtoint.h
dbconnector.o: ../../pikotools/convert/text.h ../../pikotools/convert/misc.h
dbexpression.o: dbexpression.h baseexpression.h
dbexpression.o: ../../pikotools/textstream/textstream.h
dbexpression.o: ../../pikotools/space/space.h
dbexpression.o: ../../pikotools/textstream/types.h
dbexpression.o: ../../pikotools/date/date.h
dbexpression.o: ../../pikotools/convert/inttostr.h
dbexpression.o: ../../pikotools/membuffer/membuffer.h
dbexpression.o: ../../pikotools/textstream/types.h morm_types.h modelenv.h
dbexpression.o: modeldata.h cursorhelper.h queryresult.h
dbexpression.o: ../../pikotools/log/log.h ../../pikotools/log/filelog.h
dbexpression.o: finderhelper.h fieldvaluehelper.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
flatconnector.o: ../../pikotools/convert/inttostr.h
flatconnector.o: ../../pikotools/membuffer/membuffer.h
flatconnector.o: ../../pikotools/textstream/types.h flatexpression.h
flatconnector.o: baseexpression.h morm_types.h modelenv.h modeldata.h
flatconnector.o: cursorhelper.h queryresult.h ../../pikotools/log/log.h
flatconnector.o: ../../pikotools/log/filelog.h finderhelper.h
flatconnector.o: fieldvaluehelper.h model.h modelconnector.h clearer.h
flatconnector.o: dbconnector.h dbexpression.h
flatexpression.o: flatexpression.h baseexpression.h
flatexpression.o: ../../pikotools/textstream/textstream.h
flatexpression.o: ../../pikotools/space/space.h
flatexpression.o: ../../pikotools/textstream/types.h
flatexpression.o: ../../pikotools/date/date.h
flatexpression.o: ../../pikotools/convert/inttostr.h
flatexpression.o: ../../pikotools/membuffer/membuffer.h
flatexpression.o: ../../pikotools/textstream/types.h morm_types.h modelenv.h
flatexpression.o: modeldata.h cursorhelper.h queryresult.h
flatexpression.o: ../../pikotools/log/log.h ../../pikotools/log/filelog.h
flatexpression.o: finderhelper.h fieldvaluehelper.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
jsonconnector.o: ../../pikotools/convert/inttostr.h
jsonconnector.o: ../../pikotools/membuffer/membuffer.h
jsonconnector.o: ../../pikotools/textstream/types.h jsonexpression.h
dbexpression.o: dbexpression.h baseexpression.h morm_types.h modelenv.h
dbexpression.o: modeldata.h cursorhelper.h queryresult.h finderhelper.h
dbexpression.o: fieldvaluehelper.h ft.h
flatconnector.o: flatconnector.h flatexpression.h baseexpression.h
flatconnector.o: morm_types.h modelenv.h modeldata.h cursorhelper.h
flatconnector.o: queryresult.h finderhelper.h fieldvaluehelper.h ft.h model.h
flatconnector.o: modelconnector.h clearer.h dbconnector.h dbexpression.h
flatexpression.o: flatexpression.h baseexpression.h morm_types.h modelenv.h
flatexpression.o: modeldata.h cursorhelper.h queryresult.h finderhelper.h
flatexpression.o: fieldvaluehelper.h ft.h
jsonconnector.o: jsonconnector.h flatconnector.h jsonexpression.h
jsonconnector.o: flatexpression.h baseexpression.h morm_types.h modelenv.h
jsonconnector.o: modeldata.h cursorhelper.h queryresult.h
jsonconnector.o: ../../pikotools/log/log.h ../../pikotools/log/filelog.h
jsonconnector.o: finderhelper.h fieldvaluehelper.h
jsonconnector.o: modeldata.h cursorhelper.h queryresult.h finderhelper.h
jsonconnector.o: fieldvaluehelper.h ft.h
jsonexpression.o: jsonexpression.h flatexpression.h baseexpression.h
jsonexpression.o: ../../pikotools/textstream/textstream.h
jsonexpression.o: ../../pikotools/space/space.h
jsonexpression.o: ../../pikotools/textstream/types.h
jsonexpression.o: ../../pikotools/date/date.h
jsonexpression.o: ../../pikotools/convert/inttostr.h
jsonexpression.o: ../../pikotools/membuffer/membuffer.h
jsonexpression.o: ../../pikotools/textstream/types.h morm_types.h modelenv.h
jsonexpression.o: modeldata.h cursorhelper.h queryresult.h
jsonexpression.o: ../../pikotools/log/log.h ../../pikotools/log/filelog.h
jsonexpression.o: finderhelper.h fieldvaluehelper.h
model.o: model.h ../../pikotools/textstream/textstream.h
model.o: ../../pikotools/space/space.h ../../pikotools/textstream/types.h
model.o: ../../pikotools/date/date.h ../../pikotools/convert/inttostr.h
model.o: ../../pikotools/membuffer/membuffer.h
model.o: ../../pikotools/textstream/types.h modelconnector.h clearer.h
model.o: dbconnector.h ../../pikotools/log/log.h
model.o: ../../pikotools/log/filelog.h queryresult.h flatconnector.h
model.o: dbexpression.h baseexpression.h morm_types.h modelenv.h modeldata.h
model.o: cursorhelper.h finderhelper.h fieldvaluehelper.h flatexpression.h
modelconnector.o: modelconnector.h clearer.h ../../pikotools/date/date.h
modelconnector.o: ../../pikotools/convert/inttostr.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
modelconnector.o: ../../pikotools/log/log.h ../../pikotools/log/filelog.h
modelconnector.o: queryresult.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
postgresqlconnector.o: ../../pikotools/date/date.h
postgresqlconnector.o: ../../pikotools/convert/inttostr.h
postgresqlconnector.o: ../../pikotools/membuffer/membuffer.h
postgresqlconnector.o: ../../pikotools/textstream/types.h
postgresqlconnector.o: ../../pikotools/log/log.h
postgresqlconnector.o: ../../pikotools/log/filelog.h queryresult.h
postgresqlconnector.o: postgresqlqueryresult.h ../../pikotools/utf8/utf8.h
postgresqlconnector.o: postgresqlexpression.h dbexpression.h baseexpression.h
postgresqlconnector.o: morm_types.h modelenv.h modeldata.h cursorhelper.h
postgresqlconnector.o: finderhelper.h fieldvaluehelper.h
postgresqlconnector.o: ../../pikotools/convert/strtoint.h
postgresqlconnector.o: ../../pikotools/convert/text.h
postgresqlconnector.o: ../../pikotools/convert/misc.h
jsonexpression.o: morm_types.h modelenv.h modeldata.h cursorhelper.h
jsonexpression.o: queryresult.h finderhelper.h fieldvaluehelper.h ft.h
model.o: model.h modelconnector.h clearer.h dbconnector.h queryresult.h ft.h
model.o: flatconnector.h dbexpression.h baseexpression.h morm_types.h
model.o: modelenv.h modeldata.h cursorhelper.h finderhelper.h
model.o: fieldvaluehelper.h flatexpression.h
modelconnector.o: modelconnector.h clearer.h dbconnector.h queryresult.h ft.h
modelconnector.o: flatconnector.h
postgresqlconnector.o: postgresqlconnector.h dbconnector.h queryresult.h ft.h
postgresqlconnector.o: postgresqlqueryresult.h postgresqlexpression.h
postgresqlconnector.o: dbexpression.h baseexpression.h morm_types.h
postgresqlconnector.o: modelenv.h modeldata.h cursorhelper.h finderhelper.h
postgresqlconnector.o: fieldvaluehelper.h
postgresqlexpression.o: postgresqlexpression.h dbexpression.h
postgresqlexpression.o: baseexpression.h
postgresqlexpression.o: ../../pikotools/textstream/textstream.h
postgresqlexpression.o: ../../pikotools/space/space.h
postgresqlexpression.o: ../../pikotools/textstream/types.h
postgresqlexpression.o: ../../pikotools/date/date.h
postgresqlexpression.o: ../../pikotools/convert/inttostr.h
postgresqlexpression.o: ../../pikotools/membuffer/membuffer.h
postgresqlexpression.o: ../../pikotools/textstream/types.h morm_types.h
postgresqlexpression.o: modelenv.h modeldata.h cursorhelper.h queryresult.h
postgresqlexpression.o: ../../pikotools/log/log.h
postgresqlexpression.o: ../../pikotools/log/filelog.h finderhelper.h
postgresqlexpression.o: fieldvaluehelper.h
postgresqlexpression.o: baseexpression.h morm_types.h modelenv.h modeldata.h
postgresqlexpression.o: cursorhelper.h queryresult.h finderhelper.h
postgresqlexpression.o: fieldvaluehelper.h ft.h
postgresqlqueryresult.o: postgresqlqueryresult.h queryresult.h
postgresqlqueryresult.o: ../../pikotools/log/log.h
postgresqlqueryresult.o: ../../pikotools/textstream/textstream.h
postgresqlqueryresult.o: ../../pikotools/space/space.h
postgresqlqueryresult.o: ../../pikotools/textstream/types.h
postgresqlqueryresult.o: ../../pikotools/date/date.h
postgresqlqueryresult.o: ../../pikotools/convert/inttostr.h
postgresqlqueryresult.o: ../../pikotools/membuffer/membuffer.h
postgresqlqueryresult.o: ../../pikotools/textstream/types.h
postgresqlqueryresult.o: ../../pikotools/log/filelog.h
queryresult.o: queryresult.h ../../pikotools/log/log.h
queryresult.o: ../../pikotools/textstream/textstream.h
queryresult.o: ../../pikotools/space/space.h
queryresult.o: ../../pikotools/textstream/types.h ../../pikotools/date/date.h
queryresult.o: ../../pikotools/convert/inttostr.h
queryresult.o: ../../pikotools/membuffer/membuffer.h
queryresult.o: ../../pikotools/textstream/types.h
queryresult.o: ../../pikotools/log/filelog.h ../../pikotools/utf8/utf8.h
queryresult.o: queryresult.h

707
src/baseexpression.cpp
File diff suppressed because it is too large
View File

347
src/baseexpression.h

@ -41,7 +41,7 @@
#include "date/date.h"
#include "morm_types.h"
#include "modelenv.h"
#include "ft.h"
namespace morm
@ -60,11 +60,14 @@ public:
virtual void set_work_mode(int work_mode);
virtual int get_work_mode();
virtual pt::TextStream * get_text_stream();
virtual void set_text_stream(pt::TextStream * out_stream);
virtual void clear();
virtual void generate_from_model(PT::TextStream & stream, Model & model);
virtual void generate_from_model(pt::TextStream & stream, Model & model);
virtual PT::TextStream * get_current_stream();
virtual pt::TextStream * get_current_stream();
// rename me
virtual void allow_to_use_prefix(bool use_prefix);
@ -73,25 +76,25 @@ public:
template<typename FieldValue>
void field(const wchar_t * field_name, const FieldValue & field_value, bool insertable, bool updatable, bool is_primary_key, ModelEnv * model_env)
void field(const wchar_t * field_name, const FieldValue & field_value, const FT & field_type, ModelEnv * model_env)
{
if( out_stream && can_field_be_generated(insertable, updatable, is_primary_key) )
if( out_stream && can_field_be_generated(field_type) )
{
field_before();
if( work_mode == MORM_WORK_MODE_MODEL_FIELDS )
{
put_field_name(field_name, model_env);
put_field_name_and_table_if_needed(field_name, field_type, model_env);
}
else
if( work_mode == MORM_WORK_MODE_MODEL_SAVE_FIELDS )
{
save_foreign_key(field_name, model_env);
save_foreign_key(field_name, field_type, model_env);
}
else
if( work_mode == MORM_WORK_MODE_MODEL_VALUES )
{
put_field_value(field_value);
put_field_value_or_null(field_value, field_type, model_env);
}
else
if( work_mode == MORM_WORK_MODE_MODEL_FIELDS_VALUES )
@ -100,18 +103,18 @@ public:
{
if( (size_t)model_env->field_index < model_env->set_field_name_helper->size() )
{
put_field_name((*model_env->set_field_name_helper)[model_env->field_index], model_env);
put_field_name_and_table_if_needed((*model_env->set_field_name_helper)[model_env->field_index], field_type, model_env);
put_name_value_separator();
put_field_value(field_value);
put_field_value_or_null(field_value, field_type, model_env);
}
model_env->field_index += 1;
}
else
{
put_field_name(field_name, model_env);
put_field_name_and_table_if_needed(field_name, field_type, model_env);
put_name_value_separator();
put_field_value(field_value);
put_field_value_or_null(field_value, field_type, model_env);
}
}
@ -121,43 +124,60 @@ public:
}
template<typename FieldValue>
void put_field_value_or_null(const FieldValue & field_value, const FT & field_type, ModelEnv * model_env)
{
if( field_type.is_primary_key() )
{
if( model_env && model_env->has_primary_key_set )
put_field_value(field_value, field_type);
else
put_null_value();
}
else
{
put_field_value(field_value, field_type);
}
}
template<typename FieldValue>
void field_in(PT::TextStream & stream, const wchar_t * field_name, const std::set<FieldValue> & container, ModelEnv * model_env)
void field_in(pt::TextStream & stream, const wchar_t * field_name, const std::set<FieldValue> & container, ModelEnv * model_env)
{
field_in_generic<FieldValue, std::set<FieldValue>>(stream, field_name, container, model_env);
}
template<typename FieldValue>
void field_in(PT::TextStream & stream, const wchar_t * field_name, const std::list<FieldValue> & container, ModelEnv * model_env)
void field_in(pt::TextStream & stream, const wchar_t * field_name, const std::list<FieldValue> & container, ModelEnv * model_env)
{
field_in_generic<FieldValue, std::list<FieldValue>>(stream, field_name, container, model_env);
}
template<typename FieldValue>
void field_in(PT::TextStream & stream, const wchar_t * field_name, const std::vector<FieldValue> & container, ModelEnv * model_env)
void field_in(pt::TextStream & stream, const wchar_t * field_name, const std::vector<FieldValue> & container, ModelEnv * model_env)
{
field_in_generic<FieldValue, std::vector<FieldValue>>(stream, field_name, container, model_env);
}
template<typename ModelContainer>
void field_list(const wchar_t * field_name, ModelContainer & field_value, bool insertable, bool updatable, bool is_primary_key,
ModelConnector * model_connector, ModelEnv * model_env)
void field_list(const wchar_t * field_name, ModelContainer & field_value, const FT & field_type, ModelConnector * model_connector, ModelEnv * model_env)
{
if( out_stream && can_field_be_generated(insertable, updatable, is_primary_key) )
if( out_stream && can_field_be_generated(field_type) )
{
field_before();
// if( work_mode == MORM_WORK_MODE_MODEL_FIELDS )
// {
// put_field_name(field_name);
// put_field_name_and_table_if_needed(field_name);
// }
// else
if( work_mode == MORM_WORK_MODE_MODEL_FIELDS_VALUES )
{
put_field_name(field_name, model_env);
put_field_name_and_table_if_needed(field_name, field_type, model_env);
put_name_value_separator();
put_field_value_list(field_value, model_connector, model_env);
}
@ -167,15 +187,15 @@ public:
}
template<typename ModelClass>
void field_model(const wchar_t * field_name, ModelClass & field_model, bool insertable, bool updatable, bool is_primary_key, ModelEnv * model_env)
void field_model(const wchar_t * field_name, ModelClass & field_model, const FT & field_type, ModelEnv * model_env)
{
if( out_stream && can_field_be_generated(insertable, updatable, is_primary_key) )
if( out_stream && can_field_be_generated(field_type) )
{
field_before();
if( work_mode == MORM_WORK_MODE_MODEL_FIELDS )
{
put_field_name(field_name, model_env);
put_field_name_and_table_if_needed(field_name, field_type, model_env);
}
else
if( work_mode == MORM_WORK_MODE_MODEL_VALUES )
@ -185,7 +205,7 @@ public:
else
if( work_mode == MORM_WORK_MODE_MODEL_FIELDS_VALUES )
{
put_field_name(field_name, model_env);
put_field_name_and_table_if_needed(field_name, field_type, model_env);
put_name_value_separator();
generate_from_model(field_model);
}
@ -195,53 +215,71 @@ public:
}
template<typename FieldValue>
void field_to_stream(PT::TextStream & stream, const wchar_t * field_name, const FieldValue & field_value, bool insertable, bool updatable, bool is_primary_key,
ModelEnv * model_env)
void field_to_stream(pt::TextStream & stream, const wchar_t * field_name, const FieldValue & field_value, const FT & field_type, ModelEnv * model_env)
{
this->out_stream = &stream;
field(field_name, field_value, insertable, updatable, is_primary_key, model_env);
field(field_name, field_value, field_type, model_env);
this->out_stream = nullptr;
}
virtual void put_schema_table(const wchar_t * schema_name, const wchar_t * table_name);
virtual void put_schema_table(const pt::WTextStream & schema_name, const pt::WTextStream & table_name);
virtual void put_table(const wchar_t * table_name);
virtual void put_table(const pt::WTextStream & table_name);
virtual void put_table_with_index(const wchar_t * table_name, int index);
virtual void put_table_with_index(const pt::WTextStream & table_name, int index);
virtual void put_table_with_index_and_field(const wchar_t * table_name, int index, const wchar_t * field_name, const FT & field_type);
virtual void put_table_with_index_and_field(const pt::WTextStream & table_name, int index, const wchar_t * field_name, const FT & field_type);
virtual void put_table_and_field(const wchar_t * table_name, const wchar_t * field_name, const FT & field_type);
virtual void put_table_and_field(const pt::WTextStream & table_name, const wchar_t * field_name, const FT & field_type);
virtual void schema_table_to_stream(pt::TextStream & stream, const wchar_t * schema_name, const wchar_t * table_name);
virtual void schema_table_to_stream(pt::TextStream & stream, const pt::WTextStream & schema_name, const pt::WTextStream & table_name);
virtual void table_to_stream(pt::TextStream & stream, const wchar_t * table_name);
virtual void table_to_stream(pt::TextStream & stream, const pt::WTextStream & table_name);
virtual void table_with_index_to_stream(pt::TextStream & stream, const wchar_t * table_name, int index);
virtual void table_with_index_to_stream(pt::TextStream & stream, const pt::WTextStream & table_name, int index);
virtual void table_with_index_and_field_to_stream(pt::TextStream & stream, const wchar_t * table_name, int index, const wchar_t * field_name, const FT & field_type);
virtual void table_with_index_and_field_to_stream(pt::TextStream & stream, const pt::WTextStream & table_name, int index, const wchar_t * field_name, const FT & field_type);
virtual void table_and_field_to_stream(pt::TextStream & stream, const wchar_t * table_name, const wchar_t * field_name, const FT & field_type);
virtual void table_and_field_to_stream(pt::TextStream & stream, const pt::WTextStream & table_name, const wchar_t * field_name, const FT & field_type);
/*
* IMPLEMENT ME
* esc for: signed char, wchar_t, char16_t, char32_t
*
*/
virtual void esc(char val, PT::TextStream & stream);
virtual void esc(unsigned char val, PT::TextStream & stream);
virtual void esc(wchar_t val, PT::TextStream & stream);
virtual void esc(const std::wstring & val, PT::TextStream & stream);
virtual void esc(const wchar_t * val, PT::TextStream & stream);
virtual void esc(char val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(unsigned char val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(const std::string & val, PT::TextStream & stream);
virtual void esc(const char * val, PT::TextStream & stream);
virtual void esc(wchar_t val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(bool val, PT::TextStream & stream);
virtual void esc(short val, PT::TextStream & stream);
virtual void esc(unsigned short val, PT::TextStream & stream);
virtual void esc(int val, PT::TextStream & stream);
virtual void esc(unsigned int val, PT::TextStream & stream);
virtual void esc(long val, PT::TextStream & stream);
virtual void esc(unsigned long val, PT::TextStream & stream);
virtual void esc(long long val, PT::TextStream & stream);
virtual void esc(unsigned long long val, PT::TextStream & stream);
virtual void esc(float val, PT::TextStream & stream);
virtual void esc(double val, PT::TextStream & stream);
virtual void esc(long double val, PT::TextStream & stream);
//virtual void esc(void* val, PT::TextStream & stream);
virtual void esc(const std::wstring & val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(const wchar_t * val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(const PT::Date & date, PT::TextStream & stream);
virtual void esc(const PT::TextStream & val,PT::TextStream & stream);
virtual void esc(const std::string & val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(const char * val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual bool is_long_field_name(const wchar_t * field_name);
virtual bool is_long_field_name(const PT::TextStream & table_name);
virtual void esc(bool val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(short val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(unsigned short val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(int val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(unsigned int val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(long val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(unsigned long val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(long long val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(unsigned long long val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(float val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(double val, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(long double val, pt::TextStream & stream, const FT & field_type = FT::default_type);
//virtual void esc(void* val, pt::TextStream & stream);
virtual bool is_long_table_name(const wchar_t * field_name);
virtual bool is_long_table_name(const PT::TextStream & table_name);
virtual void esc(const pt::Date & date, pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(const pt::TextStream & val,pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(const pt::WTextStream & val,pt::TextStream & stream, const FT & field_type = FT::default_type);
virtual void esc(const pt::Space & space, pt::TextStream & stream, const FT & field_type = FT::default_type);
@ -250,7 +288,7 @@ protected:
int work_mode; /* what to do: generating fields list, values list or fields-values list */
bool is_first_field;
PT::TextStream * out_stream;
pt::TextStream * out_stream;
bool use_prefix;
@ -258,30 +296,34 @@ protected:
virtual void before_generate_from_model();
virtual void after_generate_from_model();
virtual bool can_field_be_generated(bool insertable, bool updatable, bool is_primary_key);
virtual bool can_field_be_generated(const FT &);
virtual void field_before();
virtual void field_after();
//void field(const wchar_t * field_name, Model & field, bool insertable = true, bool updatable = true);
virtual void put_field_name(const wchar_t * field_name, ModelEnv * model_env);
virtual void save_foreign_key(const wchar_t * field_name, ModelEnv * model_env);
virtual void put_field_name_and_table_if_needed(const wchar_t * field_name, const FT & field_type, ModelEnv * model_env);
virtual void put_field_name(const wchar_t * field_name, const FT & field_type, ModelEnv * model_env);
virtual void save_foreign_key(const wchar_t * field_name, const FT & field_type, ModelEnv * model_env);
virtual void dump_additional_info(Model & model);
template<typename FieldValue>
void put_field_value(const FieldValue & field_value)
void put_field_value(const FieldValue & field_value, const FT & field_type)
{
if( out_stream )
{
before_field_value(field_value);
esc(field_value, *out_stream);
after_field_value(field_value);
before_field_value(field_value, field_type);
esc(field_value, *out_stream, field_type);
after_field_value(field_value, field_type);
}
}
virtual void put_null_value()
{
(*out_stream) << "null";
}
virtual void before_field_value_list()
{
}
@ -323,16 +365,7 @@ protected:
field_value_list_separator();
}
//ModelEnv model_env_local(*model_env);
//m.model_env = &model_env_local;
//before_field_value(field_value);
//m.set_connector(model_connector);
put_field_value(m);
//generate_from_model(m);
//m.model_env = nullptr;
//after_field_value(field_value);
put_field_value(m, FT::default_type);
is_first = false;
}
@ -358,11 +391,12 @@ protected:
ModelEnv model_env_local(*model_env);
m.model_env = &model_env_local;
//before_field_value(field_value);
m.model_env->has_primary_key_set = m.get_has_primary_key_set();
m.set_connector(model_connector);
generate_from_model(m);
m.model_env = nullptr;
//after_field_value(field_value);
is_first = false;
}
@ -451,7 +485,7 @@ protected:
put_field_value_list_non_model(field_value, model_connector);
}
void put_field_value_list(std::vector<PT::Date> & field_value, ModelConnector * model_connector, ModelEnv *)
void put_field_value_list(std::vector<pt::Date> & field_value, ModelConnector * model_connector, ModelEnv *)
{
put_field_value_list_non_model(field_value, model_connector);
}
@ -540,7 +574,7 @@ protected:
put_field_value_list_non_model(field_value, model_connector);
}
void put_field_value_list(std::list<PT::Date> & field_value, ModelConnector * model_connector, ModelEnv *)
void put_field_value_list(std::list<pt::Date> & field_value, ModelConnector * model_connector, ModelEnv *)
{
put_field_value_list_non_model(field_value, model_connector);
}
@ -549,7 +583,7 @@ protected:
// used in 'in()' statements, may should be renamed?
template<typename FieldValue, typename Container>
void field_in_generic(PT::TextStream & stream, const wchar_t * field_name, const Container & container, ModelEnv * model_env)
void field_in_generic(pt::TextStream & stream, const wchar_t * field_name, const Container & container, ModelEnv * model_env)
{
// IMPROVE ME
// what about if container is empty?
@ -557,7 +591,7 @@ protected:
this->out_stream = &stream;
field_before();
put_field_name(field_name, model_env);
put_field_name_and_table_if_needed(field_name, FT::default_type, model_env);
put_name_value_separator();
bool is_first = true;
@ -570,7 +604,7 @@ protected:
field_value_list_separator();
}
put_field_value(v);
put_field_value(v, FT::default_type);
is_first = false;
}
@ -580,50 +614,50 @@ protected:
}
/*
* escaping column names in a case when using short form - just only column_name
* [before_short_field_name]column_name[after_short_field_name]
*/
virtual void before_short_field_name();
virtual void after_short_field_name();
virtual void schema_table_separator();
virtual void table_field_separator();
virtual void before_schema_name();
virtual void after_schema_name();
virtual void before_table_name();
virtual void after_table_name();
virtual void before_field_name();
virtual void after_field_name();
/*
* escaping column names in a case when using long form: table_name.column_name
* [before_first_part_long_field_name]table_name[after_first_part_long_field_name].[before_second_part_long_field_name]column_name[after_second_part_long_field_name]
*
*/
virtual void before_first_part_long_field_name();
virtual void after_first_part_long_field_name();
virtual void before_second_part_long_field_name();
virtual void after_second_part_long_field_name();
virtual const wchar_t * put_long_part_field_name(const wchar_t * field_name);
virtual void put_long_field_name(const wchar_t * field_name);
virtual void put_short_field_name(const wchar_t * field_name, ModelEnv * model_env);
virtual void before_field_value(const std::wstring &, const FT & field_type);
virtual void after_field_value(const std::wstring &, const FT & field_type);
virtual void before_field_value(const std::wstring &);
virtual void after_field_value(const std::wstring &);
virtual void before_field_value(const std::string &, const FT & field_type);
virtual void after_field_value(const std::string &, const FT & field_type);
virtual void before_field_value(const std::string &);
virtual void after_field_value(const std::string &);
virtual void before_field_value(const wchar_t *, const FT & field_type);
virtual void after_field_value(const wchar_t *, const FT & field_type);
virtual void before_field_value(const wchar_t *);
virtual void after_field_value(const wchar_t *);
virtual void before_field_value(const char *, const FT & field_type);
virtual void after_field_value(const char *, const FT & field_type);
virtual void before_field_value(const char *);
virtual void after_field_value(const char *);
virtual void before_field_value(wchar_t, const FT & field_type);
virtual void after_field_value(wchar_t, const FT & field_type);
virtual void before_field_value(const PT::Date &);
virtual void after_field_value(const PT::Date &);
virtual void before_field_value(char, const FT & field_type);
virtual void after_field_value(char, const FT & field_type);
virtual void before_field_value(const pt::Date &, const FT & field_type);
virtual void after_field_value(const pt::Date &, const FT & field_type);
virtual void before_field_value(const pt::Space &, const FT & field_type);
virtual void after_field_value(const pt::Space &, const FT & field_type);
template<typename FieldValue>
void before_field_value(const FieldValue &)
void before_field_value(const FieldValue &, const FT & field_type)
{
}
template<typename FieldValue>
void after_field_value(const FieldValue &)
void after_field_value(const FieldValue &, const FT & field_type)
{
}
@ -635,44 +669,55 @@ protected:
* put_type for: signed char, wchar_t, char16_t, char32_t
*
*/
virtual void put_type(char val, PT::TextStream & stream);
virtual void put_type(unsigned char val, PT::TextStream & stream);
virtual void put_type(const std::wstring & val, PT::TextStream & stream);