Commit Graph
100 Commits
Author SHA1 Message Date
tomasz.sowa 54c708f9a0 add a .clang-format file 2026-08-18 00:17:21 +02:00
tomasz.sowa 9747416efd allow to force installing a clangd and qtcreator files
Add a forceclangd target to Makefile to force installing a .clangd file.
Add a forceqtcreator target to force installing qtcreator files.
Existing files will be overwritten.

while here:
- update the c++ standard to c++23
2026-08-17 23:52:51 +02:00
tomasz.sowa 698256e2eb print qt environment ids only when .qtcreator directory was created 2024-09-25 09:50:03 +02:00
tomasz.sowa 4f2bc70a00 fix: set a correct global working dir when generating a .clangd file 2024-09-24 23:41:00 +02:00
tomasz.sowa 179e63f3ec use a QTCreator environmentid and a profileid from a local installation
When creating QTCreator project files use local EnvironmentId
and default profile id. By default the environment id is stored
in ~/.config/QtProject/QtCreator.ini and the profile id in
~/.config/QtProject/qtcreator/profiles.xml.
2024-09-24 16:44:41 +02:00
tomasz.sowa c5a53e8e47 sort a makedepend output
Makefile.dep is sorted now - it's better when making a diff to a previous version.
2024-09-22 15:25:04 +02:00
tomasz.sowa 456e24dd30 add a clangd and qtcreator make targets
Add a clangd make target:
$ make clangd
This installs a .clangd file with configuration (includes/macros/compiler flags)
for the clandg language server.

Add a qtcreator make target:
$ make qtcreator
This installs a .qtcreator directory with QTCreator IDE project files.
In the QTCreator you can open a project by selecting the .qtcreator/morm.creator
file.

You can use 'make qtcreator' again to refresh .qtcreator/morm.files,
the rest of the project files will not be modified.
2024-09-22 11:35:26 +02:00
tomasz.sowa 0e6df30a42 add a Finder::order_by(...) method 2024-07-02 21:52:04 +02:00
tomasz.sowa 8e757aff71 improve escaping characters from multibyte strings
Read the whole character from a multibyte string and then escape it.

while here:
- add more virtual methods for escaping strings to BaseExpression
2024-06-19 23:02:37 +02:00
tomasz.sowa e46c090b41 fix: correctly serialize a Space class to the json format in the JSONExpression 2024-06-04 16:54:05 +02:00
tomasz.sowa cd067ae5c3 add Model::field(...) methods with a pt::Stream argument 2024-06-04 10:24:05 +02:00
tomasz.sowa 90b4d9af0b use a char32_t character as a main character when converting strings
Use a char32_t instead of a wchar_t type. This is needed on systems
where sizeof(wchar_t) is equal to 2.
2024-06-01 00:17:01 +02:00
tomasz.sowa 6fb7e29867 fix: correctly escape a pt::Stream in Finder from like() and similar methods
while here:
- in Finder: use pt::Stream and pt::TextStreamBase<> instead of pt::TextStream and pt::WTextStream
- add Finder::raw(...) methods with short int, int, long long and integer unsigned types
2024-05-31 00:31:30 +02:00
tomasz.sowa 9a3f6a6e36 use pt::Stream instead of pt::TextStream as the output stream 2024-05-30 00:01:59 +02:00
tomasz.sowa e026af9994 add QT Creator files to .gitignore 2023-10-22 23:37:44 +02:00
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 21f12a8a98 add support for declared cursors
Declare a cursor with the Finder::declare_cursor() method and next get the cursor with get_cursor():
morm::Cursor<MyObject> cursor = finder.
  declare_cursor("mycursorname").
  select().
  raw("ORDER BY column_name ASC").
  get_cursor();

The cursor now can be used with fetch.*() methods and then get() or get_list():
MyObject myobject = cursor.fetch_next().get();
std::list<MyObject> myobjects = cursor.fetch_forward_count(10).get_list();
2023-07-16 04:03:03 +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 25a91168ac fix: correctly use a table name when a Select::no_auto_generated_columns flag is used 2023-05-08 10:26:31 +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 d61fc31b5c allow to set a custom name for the auto generated rows counter column 2023-02-28 09:51:05 +01:00
tomasz.sowa c56bae57ca fix: propagate the model_data in the cursor
model_data can be used in Model::fields() method
2023-02-28 09:48:44 +01:00
tomasz.sowa 1821c562f7 add a Select::distinct flag 2023-02-28 03:37:20 +01:00
tomasz.sowa dee48ea2b5 use an <item> field when serializing a table to xml 2023-02-27 00:29:51 +01: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 a3c337355d fix: correctly read a date from a database if a date_only flag is set 2022-12-15 17:33:46 +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 7f4deaf847 update to the new pikotools api: change converting functions to the snake case 2022-11-14 03:38:27 +01:00
tomasz.sowa 0ce05850b3 add FT::date_only, FT::time_only and FT::no_time_zone flags 2022-10-22 16:29:40 +02:00
tomasz.sowa 38e790c2ac fix: correctly delete child objects - use the original value from save_mode 2022-08-17 07:43:58 +02:00
tomasz.sowa bc92654be9 let Finder::page() takes a page number and not an offset 2022-08-04 14:54:04 +02:00
tomasz.sowa c54a5bed05 add Model::get_logger() 2022-08-01 03:58:07 +02:00
tomasz.sowa 8373f9e9d8 make depend 2022-07-30 03:32:33 +02: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 4e8f3af8fc (finder): take pt::TextStream by const ref in raw(...) method 2022-07-08 22:02:02 +02:00
tomasz.sowa 128f43482a make depend 2022-07-05 19:48:17 +02:00
tomasz.sowa 3ddeb78c97 add LICENSE file 2022-07-03 11:01:14 +02:00
tomasz.sowa ea6f9fd13e remove empty src/outstream.h file 2022-06-30 13:30:06 +02:00
tomasz.sowa 1ad3d89d52 change headerfile_morm_* macros to headerfile_morm_src_* 2022-06-30 13:28:38 +02:00
tomasz.sowa 576d537177 add src/version.h with macros: MORM_VERSION_MAJOR, MORM_VERSION_MINOR, MORM_VERSION_PATCH
Let the version be 0.7.0.
2022-06-30 13:19:55 +02:00
tomasz.sowa c89d4f76bc add global Makefile
src/Makefile uses now 'find' for looking for *.cpp files
and we don't need Makefile.o.dep anymore
2022-06-26 06:15:19 +02:00
tomasz.sowa fc50c8ca5e fixed: in Finder::select(PT::TextStream & out_stream, ModelConnector & model_connector)
and Finder::select(PT::TextStream & out_stream, ModelConnector * model_connector)
       there was 'out_stream' parameter ignored

merged from 0890f27fe5733ba8bcfe8ab13e3014b77659c7df
2022-06-25 18:30:53 +02:00
tomasz.sowa 1ace47266d fix: correctly escape output stream buffer for models getters 2022-05-31 01:45:27 +02:00
tomasz.sowa 21117e24c0 do Transaction::commit/rollback only on the same group for which a begin was called 2022-05-27 00:06:56 +02:00
tomasz.sowa dd04ee84b7 capitalize INSERT/UPDATE/DELETE sql statements 2022-05-26 20:19:05 +02:00
tomasz.sowa 1d4de8abe2 add support for nested transactions
while here:
- don't allow to copy/move DbConnector
2022-05-26 20:14:14 +02:00
tomasz.sowa 907f10671d do not allow to copy/move transactions objects 2022-05-26 00:45:49 +02:00
tomasz.sowa c5cf4a2672 add Transaction class as a wrapper for transactions 2022-05-26 00:34:17 +02:00
tomasz.sowa b32917afe7 use pikotools Log::put_multiline() method when printing PostgreSQL error messages 2022-05-25 19:58:13 +02:00
tomasz.sowa 0ce7578de3 fix: the way how we test if there is a connection issue
If there is a connection issue then PQexec returns a resultset now
- older versions of PostgreSQL returned null pointer.
2022-05-25 19:11:42 +02:00
tomasz.sowa 12232bf722 propagate status from childs in Model::insert, Model::update, Model::remove and Model::save 2022-05-24 23:27:07 +02:00
tomasz.sowa 1ad4cb4fbd trim white lines after PostgreSQL error message 2022-05-24 20:06:06 +02:00
tomasz.sowa 56cbebad4f add FT::numeric to be applied on string types 2022-05-16 13:42:51 +02:00
tomasz.sowa 3bde64e033 add possibility to set save status for the whole tree
add method:
void Model::set_save_mode2(SaveMode save_mode, bool update_whole_tree = true)
in the future it may be renamed to set_save_mode()
2022-05-12 00:21:42 +02:00
tomasz.sowa df44296c04 fix: only insert primary keys from the first descendant childs 2022-05-11 23:18:25 +02:00
tomasz.sowa 469294502e allow specify how many times we can try to connect to the database 2022-04-29 05:56:02 +02:00
tomasz.sowa d384929e75 allow to use host connection parameter 2022-04-28 06:03:40 +02:00
tomasz.sowa ac77abb8fd allow to use hostaddr, port or conn_string to connect to PostgreSQL 2022-04-20 18:36:06 +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 48d515ea64 if pt::Space has FT::json type then let JSONExpression serialize it as json and not string 2022-02-03 11:18:01 +01:00
tomasz.sowa c25a5d2215 - code from JSONExpression::esc(char val, ...) moved to Pikotools (convert/misc.h)
- added ModelContainerWrapper::set_iterator_at_first_model() method
2021-10-12 19:59:19 +02:00
tomasz.sowa e682e057ad added to SpaceWrapper class: void invalidate_iterators(size_t space_index_start) 2021-08-13 21:43:02 +02:00
tomasz.sowa f94a9e27db added flags FT::json and FT::space for pt::Space class - serializing/parsing to/from json/space 2021-08-12 21:56:32 +02:00
tomasz.sowa d162ca13bb fixed: in Model::add_field_for_select(...) there was a table name added 2021-07-07 01:06:01 +02:00
tomasz.sowa f4d92bec5d added clearing of existing objects in Wrapper::operator=(...) 2021-07-01 23:22:49 +02:00
tomasz.sowa dc6c70499c added: Wrapper class as a wrapper for: a model, model container (list/vector), Space or Date
added BaseObjectWrapper as base class for: SpaceWrapper and ModelContainerWrapper
removed: ModelWrapperModel, now one Model doesn't need a wrapper
renamed: ModelWrapperSpace -> SpaceWrapper, now as a base class it has BaseObjectWrapper
renamed: Model::get_model_wrapper() -> Model::get_wrapper() - now it returns Wrapper object
removed logging from Model::get_model() and Model::get_wrapper()
field() methods don't take ModelWrapper** but Wrapper& now
2021-07-01 22:55:56 +02: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 097c09b9e3 added to Model: virtual bool db_query(const char ** raw_sql, size_t len); 2021-06-27 22:43:10 +02:00
tomasz.sowa e35a1d09a5 added ModelWrapper::space_indices_table_size() method 2021-06-25 16:18:06 +02:00
tomasz.sowa 89148de66d updated samples
- pikotools is in src subdirectory now
- map_fields() -> fields()
- prepare_table() -> table()
- instead of pt::MainSpaceParser we have pt::MainOptionsParser now
2021-06-24 21:14:29 +02:00
tomasz.sowa 86bf9cf688 added ModelWrapperSpace for wrapping the pt::Space class 2021-06-22 17:59:44 +02:00
tomasz.sowa e74575db42 fixed: in ModelWrapper::clear_childs() childs_map.clear() was called in the loop, should be at the end 2021-06-22 11:59:11 +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 aba454a4bf methods Model::get_raw_value(...) now returns boolean - true if a field was found 2021-06-19 20:25:38 +02:00
tomasz.sowa 9a142548d0 fixed in Model::field_generic_put_raw_value_to_stream() - a boolean status for ezc was not set
added to Model:
- method field() which can take a pointer to a member which returns bool:
  void field(const wchar_t * field_name, bool (ClassName::*method)(), const morm::FT & field_type = morm::FT::default_type)
- method field() which can take a pointer to a member which can set morm::ModelWrapper object
  void field(const wchar_t * field_name, void (ClassName::*method)(morm::ModelWrapper **), const morm::FT & field_type = morm::FT::default_type)
- methods: bool Model::convert_to_bool(...) - they are used for creating a result for ezc from local fields
2021-06-18 19:05:50 +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 dc1c601eac in Model: added a test whether Model is a base class of ContainerItemType (list/vector) when doing MORM_MODEL_WORK_MODE_GET_MODEL_WRAPPER 2021-06-16 22:23:30 +02:00
tomasz.sowa d8f7216a73 added .editorconfig file 2021-06-16 14:21:34 +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 284cbc5c66 Merge pull request 'winix_fullmorm' (#4) from winix_fullmorm into master
Reviewed-on: #4
2021-05-27 10:49:46 +02:00
tomasz.sowa 2f72bd29ec fixed: has_primary_key_set was always set to false in Model::insert()
and this prevented to insert a model which had a primary key set by hand
2021-05-21 22:36:04 +02:00
tomasz.sowa e0e3465673 fixed: such field types: no_insertable, no_updatable were not taken into account on Model child objects
added: field type: no_removable - it is used only with child Models objects
2021-05-21 22:12:10 +02:00
tomasz.sowa fcd2c4775b updated to the new pikotools api: snake_case names of methods from SpaceParser 2021-05-21 04:51:12 +02:00
tomasz.sowa 9598cc4def updated to the new pikotools api: SpaceParser::SetSpace(...) methods have been removed 2021-05-21 01:35:16 +02:00
tomasz.sowa 0ff900f626 updated to the new pikotools api: changed utf8 functions PascalCase to snake_case 2021-05-21 00:32:29 +02:00
tomasz.sowa 34274ca230 namespace PT renamed to pt 2021-05-20 16:25:01 +02:00
tomasz.sowa b12037a7e5 added basic support for making migrations 2021-05-14 03:24:53 +02:00
tomasz.sowa de4abeb91c added to Finder: methods eq() and similar with table_name as an argument
Finder<ModelClass> & eq(const wchar_t * table_name, const wchar_t * field_name, const FieldValue & field_value)
Finder<ModelClass> & eq(const wchar_t * table_name, int table_index, const wchar_t * field_name, const FieldValue & field_value)
and similar for neq(), lt(), gt(), le(), ge() and in()
2021-05-13 19:32:31 +02:00
tomasz.sowa 6eaa9088e5 renamed in Model: map_fields() to fields(), prepare_table() to table() 2021-05-13 03:27:21 +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