Commit Graph

65 Commits

Author SHA1 Message Date
Tomasz Sowa 92d9d2c01b
add Finder::esc_like(...) methods 2023-10-10 19:43:02 +02:00
Tomasz Sowa 8200092524
add Finder::raw(pt::Date&,...) and esc(pt::Date &,...) methods 2023-07-17 03:42:14 +02:00
Tomasz Sowa 6619f3ecb5
fix: correctly use a table name when using Finder::use_table_prefix(true)
We cannot use aliases in the form of "tablename"."fieldname" - now it was
changed to "tablename.fieldname".

Sample how to get the id field, assuming the table name is 'mymodel'.
mymodel = finder2.
          select(morm::Select::no_auto_generated_columns).
          use_table_prefix(true).
          raw("SELECT id AS \"mymodel.id\"").
          raw("FROM mymodel").
          raw("WHERE id = 25").
          get();

In addition, there was an error that the table name was not correctly set
for the first object in the hierarchy - it was empty, e.g. ""."field_name"
2023-07-15 03:08:02 +02:00
Tomasz Sowa e7c62e35dc
add Finder::is_null() and is_not_null() methods 2023-07-08 23:26:54 +02:00
Tomasz Sowa 86177889af
add a CSVConnector/CSVExpression classes to serialize to csv format
Current limitation: list/vectors are not serialized.

while here:
- move the output_type flag from the DbExpression to BaseExpression class
- add Model::to_text(...) methods with an Export parameter
2023-04-12 17:20:29 +02:00
Tomasz Sowa cf377204a9
improve the xml serializer
while here:
- do some refactoring in BaseExpression
2023-02-26 22:19:46 +01:00
Tomasz Sowa 0fbd988eda
serialize a model to flat string even when a DO_NOTHING_ON_SAVE flag is set
while here:
- add FT::serialize_to_null_if_null and FT::do_not_serialize_if_null flags
2023-02-26 18:28:16 +01:00
Tomasz Sowa d1c86c84cf fix: allow to use a minus sign in strings with FT::numeric flag 2023-01-11 23:06:27 +01:00
Tomasz Sowa 794051fa15 add basic support for serializing objects to xml 2022-12-16 02:48:07 +01:00
Tomasz Sowa a4a1acebeb add Finder::like(...) and ilike(...) methods 2022-12-05 06:36:13 +01:00
Tomasz Sowa dfc631dd06 add more Finder::esc(...) and raw(...) methods 2022-12-02 13:26:30 +01:00
Tomasz Sowa 2ac8769d3a add Finder::esc(...) methods 2022-12-02 11:45:19 +01:00
Tomasz Sowa 43dfbd5d5a add possibility of calculating how many rows there were before LIMIT was applied
The Finder has get_rows_counter() method which returns how many rows there were
before LIMIT clause was applied. The select(...) method should be called with
Select::with_rows_counter flag in such a case.

while here:
- change the semantic of Finder, now the select(...) method takes a morm::Select flags,
  and we have such flags:
  - Select::no_auto_generated_columns - do not generate columns from models
  - with_rows_counter - add an additional column for the rows counter
- remove Finder::prepare_to_select() - now use select(...) with no_auto_generated_columns flag
2022-07-11 17:48:13 +02:00
Tomasz Sowa 1ad3d89d52 change headerfile_morm_* macros to headerfile_morm_src_* 2022-06-30 13:28:38 +02:00
Tomasz Sowa 1ace47266d fix: correctly escape output stream buffer for models getters 2022-05-31 01:45:27 +02:00
Tomasz Sowa 56cbebad4f add FT::numeric to be applied on string types 2022-05-16 13:42:51 +02:00
Tomasz Sowa 0bdabfc7b4 fix: put 'char' type directly to the output stream
Char type was converted to wchar_t and then was serialized as utf-8 stream.
Let char type will always be one char, of course it need to be a valid utf-8 sequence.

Let FT::dont_use_utf8 apply only to wchar_t and std::wstring
but ignore it if FT::hexadecimal or FT::binary are defined.

Now we have bool BaseExpression::esc_char(wchar_t val, pt::TextStream & stream) method
which (in most cases) will be used in derived classes.

Let wchar_t (and std::wstring) will be stored as 8 hex digits when using FT::hexadecimal
or FT::binary (and ignore FT::dont_use_utf8 in such a case).
2022-02-08 12:47:34 +01:00
Tomasz Sowa 84fd351bfc fixed: in BaseExpression::put_field_value_list_model() model_env_local.model pointer was not set to the child object
reported by clang with -fsanitize=undefined
main.cpp:55:63: runtime error: member access within address 0x614000000040 which does not point to an object of type 'Krolik'
0x614000000040: note: object is of type 'Item'
 02 00 00 73  00 4e 75 00 00 00 00 00  a0 b9 ff ff ff 7f 00 00  c0 80 ff ff ff 7f 00 00  00 00 00 00
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'Item'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior main.cpp:55:63 in
main.cpp:55:97: runtime error: member access within address 0x614000000040 which does not point to an object of type 'Krolik'
0x614000000040: note: object is of type 'Item'
 02 00 00 73  00 4e 75 00 00 00 00 00  a0 b9 ff ff ff 7f 00 00  c0 80 ff ff ff 7f 00 00  00 00 00 00
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'Item'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior main.cpp:55:97 in
2021-07-01 22:39:50 +02:00
Tomasz Sowa a8fe798279 fixed: getters method (Model::*getter_method)(pt::Stream &) produced boolean value when serializing to flat string
- changed in Model::field_list_generic(...): message "you should set FT::is_foreign_key or FT::is_foreign_key_in_child flag" print only
  for work mode MORM_MODEL_WORK_MODE_SET_PARENT_ID or MORM_MODEL_WORK_MODE_ITERATE_THROUGH_CHILDS_WITHOUT_FOREIGN_KEY
- pt::TextStream::to_string(...) is now pt::TextStream::to_str(...)
- in Model::get_raw_value() for ezc 'pt::TextStream & stream' changed to 'pt::Stream & stream' (a base class of pt::TextStream)
  similar in field(...) methods which take getters: void (Model::*getter_method)(pt::TextStream &) -> void (Model::*getter_method)(pt::Stream &)
2021-06-20 17:49:54 +02:00
Tomasz Sowa 5cf55ecce3 added basic support for containers with pointers to models
added to Model:
template<typename ContainerItemType>
void field(const wchar_t * db_field_name, const wchar_t * flat_field_name, std::list<ContainerItemType*> & field_value, const FT & field_type = FT::default_type);

template<typename ContainerItemType>
void field(const wchar_t * db_field_name, const wchar_t * flat_field_name, std::vector<ContainerItemType*> & field_value, const FT & field_type = FT::default_type);
2021-06-17 21:31:58 +02:00
Tomasz Sowa aeb02f82b1 changed the way how we get a specific field value - now we do not use expressions (BaseExpression), to get the raw value we don't need an expression object:
- removed MORM_WORK_MODE_GET_SPECIFIC_FIELD_VALUE from expression work mode
- removed: void BaseExpression::field(const wchar_t * field_name, void (Model::*getter_method)(pt::TextStream &), const FT & field_type, ModelEnv * model_env)
- removed from BaseExpression: template<typename FunInfoStreamType> void field(const wchar_t * field_name, void (Model::*fun)(Ezc::FunInfo<FunInfoStreamType> &), const FT & field_type, ModelEnv * model_env)
- removed: void FlatConnector::to_text(const wchar_t * flat_field_name, pt::TextStream & stream, Model & model)
- renamed/changed: Model::put_field_value(...) -> Model::get_raw_value()

added classes:
class ModelWrapper - base wrapper class for a model or a model container
class ModelWrapperModel : public ModelWrapper - wrapper for a model
template<typename VectorType> class ModelWrapperVector : public ModelWrapper - wrapper for vector of models
template<typename ListType> class ModelWrapperList : public ModelWrapper - wrapper for list of models
ModelWrapper... classes are used by ezc library for iterating through child models and for iterating in [for...] statements

added to Model:
Model * get_model(const wchar_t * db_field_name, const wchar_t * flat_field_name, bool put_log_if_not_found = true);
ModelWrapper * get_model_wrapper(const wchar_t * db_field_name, const wchar_t * flat_field_name, bool put_log_if_not_found = true);
2021-06-16 14:01:07 +02:00
Tomasz Sowa dd01fafa40 - added support for calling member functions (setters/getters) from Models
those functions can be used with databases and flat files
- removed support for calling static function
- if MORM_HAS_EZC_LIBRARY macro is defined then we can call a function
  which has a first argument Ezc::FunInfo<>& object
  (only for generating flat files)
2021-06-01 19:34:34 +02:00
Tomasz Sowa 515e806a50 start adding support for Ezc library - Ezc::Generator is able to get variable value and call a static function 2021-05-31 18:40:28 +02:00
Tomasz Sowa 34274ca230 namespace PT renamed to pt 2021-05-20 16:25:01 +02:00
Tomasz Sowa 2ad6c8c258 changed the way how to quote schemas, tables and field names,
added escaping table names in insert/update/remove

removed methods from BaseExpression:
virtual void before_short_field_name();
virtual void after_short_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();

added methods to BaseExpression:
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();
2021-05-13 02:32:03 +02:00
Tomasz Sowa a1537cf8d5 BaseExpression: removed methods: put_long_field_name() and put_short_field_name()
now method put_field_name() is not making a test whether field_name is in long format
and only puts the field name (without table name),
this allows us to have a dot in the column name (field_name)
2021-05-13 00:19:22 +02:00
Tomasz Sowa aadc5be350 FT field_type changed to const FT & field_type in functions arguments 2021-05-12 04:53:23 +02:00
Tomasz Sowa c7797ff2f1 fixed #2: escape tables/columns names in Finder left join queries
some methods moved from model.h to model.cpp and from baseexpression.h to baseexpression.cpp
2021-05-12 00:27:35 +02:00
Tomasz Sowa 009955a0fd added support for hex strings and binary strings
added FT::hexadecimal, FT::binary and FT::dont_use_utf8
2021-05-11 22:11:31 +02:00
Tomasz Sowa 2afe111c57 escape table names in Finder (select sql statement)
WIP: #2
2021-04-30 01:23:22 +02:00
Tomasz Sowa 1c5d32551a fixed: a null was printed for id when serializing lists/vectors
in BaseExpression::put_field_value_list(): has_primary_key_set flag was not copied to model_env
2021-04-14 16:21:10 +02:00
Tomasz Sowa 9a4fd9b050 fixed: add_field_for_select from Model incorrectly escaped a field string (column name)
fixed: Finder didn't use full table name (schema.table) in "from" clause
2021-04-12 18:53:55 +02:00
Tomasz Sowa 7bef1d5ead added support for PT::Space as a field in a Model
methods before_field_value_string() and after_field_value_string() moved
from DbExpression and JsonExpression to BaseExpression and made virtual
and now methods before_field_value(const std::wstring &) and after_field_value(const std::wstring &)
(and the rest of them with string arguments) can be removed from DbExpression, PostgreSqlExpression and JsonExpression
2021-03-11 18:40:32 +01:00
Tomasz Sowa f7490594ad changed the way how the table name is set in a Model - added prepare_table() method
removed from Model:
virtual void table_name(PT::TextStream & stream);

added to Model:
virtual void prepare_table();
virtual void table(const wchar_t * table_name);
virtual void table(const wchar_t * schema_name, const wchar_t * table_name);
2021-03-11 12:22:37 +01:00
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 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 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 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 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 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 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 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 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