Commit Graph

172 Commits

Author SHA1 Message Date
Tomasz Sowa fcf1d28b18 added FT class which is used in Model::field() methods
FT class has following types:
   enum FieldType
   {
	default_type = 0,
        primary_key = 1,
	foreign_key = 2,
	foreign_key_in_child = 4,
	no_insertable = 8,
	no_updatable = 16,
	no_fetchable = 32, /* not supported yet */
   };
an object of FT class are now used in Model::field() methods instead of insertable/updatable/is_primary_key/... boolean flags

changed the semantic of has_foreign_key (which was a bool) flag in child Models:
now on Models and list/vector of Models you should use either FT::foreign_key or FT::foreign_key_in_child
1. FT::foreign_key means that field with this flag is a foreign key and is pointing to the child object
   (it was the case when has_foreign_key was equal to true beforehand)
2. FT::foreign_key_in child means that the foreign key is in the child object and is pointing to the parent object
2021-03-10 16:20:11 +01:00
Tomasz Sowa 133a45c84b Added flag has_primary_key_set to Model
Now we know whether the primary key is defined or not
and we do not allow to make update/remove if the key is not defined.

And when doing insert/update we can put NULL if child models don't have
the primary key set (fields with has_foreign_key set to true).

Now in after_select() we should also set has_primary_key_set flag
or just call get_last_sequence_for_primary_key instead of get_last_sequence.

fixed: added prefix +00 when serializing PT::Date to PostgreSQL (time zone)
(for a column with a time zone there was a wrong value saved)
2021-03-09 18:10:34 +01:00
Tomasz Sowa ff551a64b8 in BaseExpression: changed the way how field names are escaped:
methods removed:
  virtual void before_field_name();
  virtual void after_field_name();
methods added:
  virtual void before_short_field_name();
  virtual void after_short_field_name();
  they are used for escaping column names in a case when using short form - just only column_name
  e.g.: [before_short_field_name]column_name[after_short_field_name]
methods added:
  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();
  they are used for escaping column names in a case when using long form: table_name.column_name
  e.g.: [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]
methods added:
  virtual void esc(wchar_t val, PT::TextStream & stream);
2021-02-24 01:15:17 +01:00
Tomasz Sowa 0843e384eb added get_connector() method to Model 2021-02-23 16:58:45 +01:00
Tomasz Sowa b672b67e5c added get_vector() methods to Finder and Cursor
bool get_vector(std::vector<ModelClass> & result, bool clear_list = true);
  std::vector<ModelClass> get_vector();
2021-02-23 16:55:28 +01:00
Tomasz Sowa c18bb48cc8 fixed: incorrect query was created when using neq() method with finder - there was no and or or conjunction 2021-02-23 16:51:43 +01:00
Tomasz Sowa b0a277c0eb added 'using FlatExpression::esc' to JSONExpression in order to suppress clang warning:
'morm::JSONExpression::esc' hides overloaded virtual function [-Woverloaded-virtual]
2021-02-17 18:01:37 +01:00
Tomasz Sowa 98536b3413 added .gitignore file 2021-02-17 17:06:51 +01:00
Tomasz Sowa 7571535ff4 added comments to PostgreSQLQueryResult::get_value_from_result():
* in the future we can use single row mode:
 * https://www.postgresql.org/docs/10/libpq-single-row-mode.html
 *
 * or just cursors from database:
 * https://www.postgresql.org/docs/current/sql-fetch.html




git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1230 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-11-22 13:40:30 +00:00
Tomasz Sowa d9dc49d699 added some comments (what to do)
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1220 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-09-25 17:21:12 +00:00
Tomasz Sowa ac67f0079a fixed: in Model::remove(ModelData & model_data, bool remove_whole_tree) we didn't use remove_whole_tree parameter
fixed: compilation erorr when inserting/updating a Model object which has child lists without Model objects such as std::list<int>
added: to Model: methods insert, update, remove and save with one argument: bool save_whole_tree




git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1217 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-09-25 16:20:37 +00:00
Tomasz Sowa 334201fe15 fixed: a parent key was not properly set to simple childs (insert statements)
fixed: a parent key was not set in list of childs (insert statements)




git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1215 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-09-24 17:08:45 +00:00
Tomasz Sowa cff4c1518e added support for UPDATE, INSERT and REMOVE for lists childs
(need some testing)




git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1214 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-09-24 11:09:11 +00:00
Tomasz Sowa a5d5a81a57 removed: doc functionality (generating documentation from a model)
we can use our own class (based on FlatConnector and FlatExpression) to generate documentation




git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1213 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-09-18 15:55:42 +00:00
Tomasz Sowa bb3f69fe8d refactoring: ModelEnv::model_connector_mode renamed to model_work_mode
ModelEnv::model_connector_submode renamed to model_work_submode
             and similarly macros MORM_MODEL_CONNECTOR_MODE.* -> MORM_MODEL_WORK_MODE_*
	     MORM_MODEL_CONNECTOR_SUBMODE.* -> MORM_MODEL_WORK_SUBMODE_*



git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1212 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-09-18 15:28:06 +00:00
Tomasz Sowa 3d73a64f23 rafactoring in Model class (in field_generic and field_model methods)
added: ModelEnv::model_connector_submode (used in iterating through childs)




git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1211 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-09-18 14:36:13 +00:00
Tomasz Sowa ba5f702257 fixed: in 'left join' statements there were not table indices used
added: now we set flag save_mode = DO_NOTHING_ON_SAVE for objects for which
       all fields from a database result set are null



git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1210 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-09-18 12:29:20 +00:00
Tomasz Sowa afce2234c3 fixed: get_value_by_field_name() is able to correctly take values when
we do not use auto generated 'select' and when we are using prefixes for columns



git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1209 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-09-17 17:55:39 +00:00
Tomasz Sowa 057d879b4c added: to Model::to_text() methods added dump_mode (bool) parameter
an additional field (model_save_mode) is printed
changed: if there is no an object the Cursor returns a Model with DO_NOTHING_ON_SAVE flag now
         (DO_INSERT_ON_SAVE was beforehand)
fixed:   when reading a result from db: for auto generated select there should be used
         get_value_by_field_index() method instead of get_value_by_field_name() 
changed: flat string (json) is generated only if a model has DO_INSERT_ON_SAVE
         or DO_UPDATE_ON_SAVE or is dump_mode turn on
         




git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1208 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-09-13 18:17:02 +00:00
Tomasz Sowa c133e949ce changed: SetFieldValueHelper -> FieldValueHelper
it's a much simpler structure now
removed: FieldValueBase and FieldValueContainer




git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1207 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-09-11 18:16:22 +00:00
Tomasz Sowa 0be9feda44 added support in Model for removing the whole tree
(without lists/vectors at the moment yet)




git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1206 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-09-05 16:32:35 +00:00
Tomasz Sowa d2f851faf9 now Model.update() and Model.insert() can update/insert the whole tree with child models
(at the moment without lists/vectors only model childs)



git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1205 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-09-04 16:02:18 +00:00
Tomasz Sowa 7ff05f493c added: to Model: virtual void set_parent_key_in_childs()
for setting a parent key id in child models,
       it is called after after_insert() method
added: SetFieldValueHelper class used for storing primary key values from a parent model




git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1204 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-08-22 18:33:35 +00:00
Tomasz Sowa 52422d929e start adding support for inserting child models
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1203 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-08-21 17:42:50 +00:00
Tomasz Sowa 074be938ca added 'samples' directory for samples and tests
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1202 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-08-21 15:59:03 +00:00
Tomasz Sowa 265197ce47 fixed: update/insert for child models generated an incorrect query (blocked for a while)
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1201 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-08-21 12:15:55 +00:00
Tomasz Sowa f8d88d1459 fixed: in Model::generate_insert_query there was not ModelEnv set (was a null pointer)
similarly in generate_update_query and generate_remove_query
added: support std::vector<> in Model::field() methods
added: serializing std::vector and std::list for non-model classes in BaseExpression




git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1200 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-08-20 15:49:37 +00:00
Tomasz Sowa 0a324a38ce merge from branches/join_models
(added possibility to fetch Model objects when they are used as a field in a Model class)




git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1196 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-07-20 18:04:37 +00:00
Tomasz Sowa 2533b18cfd fixed: in cursor in add_models_to_list(): added_model.model_env should be set after added_model.clear()
fixed: when generating: insert, update or remove statements we have used prefixes for columns
       but the table name was not set in ModelEnv (now we do not use prefixes in such statements)
changed: log_queries field moved from PostgreSQLConnector to DbConnector





git-svn-id: svn://ttmath.org/publicrep/morm/branches/join_models@1195 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-06-17 10:59:39 +00:00
Tomasz Sowa b6fbe29805 added BaseExpression::is_long_field_name()
added BaseExpression::need_to_add_field_prefix()
      now the fields() methods don't take add_column_prefix parameter
      but the field_name (wchar_t*) is tested whether is it a long (with a period) or short name
added BaseExpression::save_foreign_key() (code moved from field())
removed some default method arguments from BaseExpression
added neq() method for Finder
added DbExpression::prepare_short_table_name(const PT::TextStream & table_name, PT::TextStream & short_table_name)




git-svn-id: svn://ttmath.org/publicrep/morm/branches/join_models@1194 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-05-31 18:28:09 +00:00
Tomasz Sowa a1d18735b0 - removed prefix() method from Finder
(this was for a custom prefix)
- removed column_prefix and column_prefix_index from BaseExpression
  now we have a pointer to ModelEnv passed in field() method
- to ModelEnv: added table_name, table_name_simple and table_index





git-svn-id: svn://ttmath.org/publicrep/morm/branches/join_models@1193 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-05-21 17:24:12 +00:00
Tomasz Sowa 958e89fb02 some work in branches/join_models
- added FinderHelper class - used as a global object for the whole model tree in Finder
  (some fields moved from ModelData)
- added CursorHelper class - used as a global object for the whole model tree in Cursor
  (some fields moved from ModelData)







git-svn-id: svn://ttmath.org/publicrep/morm/branches/join_models@1192 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-05-21 15:51:13 +00:00
Tomasz Sowa b37a577713 some work in branches/join_models
added: ModelEnv class - now Model has a pointer to ModelEnv
       and ModelEnv has a pointer to ModelData, model_connector_mode, table_index and doc_field_pointer
       



git-svn-id: svn://ttmath.org/publicrep/morm/branches/join_models@1191 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-05-13 17:59:28 +00:00
Tomasz Sowa 34ddf11351 some work in branches/join_models
git-svn-id: svn://ttmath.org/publicrep/morm/branches/join_models@1190 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-05-13 03:12:31 +00:00
Tomasz Sowa 6d9b9045fe fixed: generating a correct table names with indices for JOIN statements and column prefixes
git-svn-id: svn://ttmath.org/publicrep/morm/branches/join_models@1188 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-03-31 20:21:12 +00:00
Tomasz Sowa ab54a3fc3e some work: we need a different way of naming tables for joins
git-svn-id: svn://ttmath.org/publicrep/morm/branches/join_models@1187 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-03-26 20:35:05 +00:00
Tomasz Sowa 9c7a0f3d7e added: support for generating LEFT JOIN statement in Finder
(the primary key should consist of only one column at the moment)



git-svn-id: svn://ttmath.org/publicrep/morm/branches/join_models@1186 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-03-26 18:34:07 +00:00
Tomasz Sowa 440f56e376 creating branch branches/join_models
git-svn-id: svn://ttmath.org/publicrep/morm/branches/join_models@1185 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-03-26 18:22:21 +00:00
Tomasz Sowa 79f9522708 used PT::Log::logsave in postgresqlconnector in some places
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1181 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-03-19 17:54:33 +00:00
Tomasz Sowa 48b04fb5de fixed in Finder: in select(ModelConnector & model_connector) there was not an out_stream set
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1177 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-03-08 18:32:58 +00:00
Tomasz Sowa cf0a0c96fe changed: ModelData moved outside Model
added:   using ModelData in BaseExpression so Model::to_text() functions can use a ModelData object now





git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1175 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-03-07 18:02:29 +00:00
Tomasz Sowa 41684eb969 Makefile.dep
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1165 e52654a7-88a9-db11-a3e9-0013d4bc506e
2019-01-07 04:33:31 +00:00
Tomasz Sowa eb3703c323 updated to the new pikotools api
(Logger -> Log)




git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1150 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-11-23 17:13:50 +00:00
Tomasz Sowa 8c5eaacadb changed: testing result status in do_query() in PostgreSQLConnector
renamed: some fields in QueryResult and PostgreSQLQueryResult




git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1142 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-11-15 08:50:10 +00:00
Tomasz Sowa 1f9e4ee70a added Cursor class
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1140 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-11-14 17:14:26 +00:00
Tomasz Sowa 011d8f96e8 fixed: in Finder: we should set model_data to nullptr after fetching an object
model_data points often to a local object (on the stack) so it would be incorrect
       to use it in the future



git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1131 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-10-24 16:28:19 +00:00
Tomasz Sowa 346fe193f3 start working on generating documentation from a model
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1124 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-07-15 22:36:04 +00:00
Tomasz Sowa fdc44c56eb 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
2018-07-05 11:15:16 +00:00
Tomasz Sowa 38b85722b8 Model and BaseExpression: changed the template taking a container to std::list
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1121 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-07-05 09:51:26 +00:00
Tomasz Sowa d6e428d929 removed: set_connector_for_childs from ModelConnector
changed: model connector is propagated to childs when needed
         (when update, insert, save, to_text is called or in finder)




git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1120 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-07-04 13:52:40 +00:00