Commit Graph

51 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 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 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 d61fc31b5c
allow to set a custom name for the auto generated rows counter column 2023-02-28 09:51:05 +01:00
Tomasz Sowa 1821c562f7
add a Select::distinct flag 2023-02-28 03:37:20 +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 bc92654be9 let Finder::page() takes a page number and not an offset 2022-08-04 14:54:04 +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 1ad3d89d52 change headerfile_morm_* macros to headerfile_morm_src_* 2022-06-30 13:28:38 +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 0890f27fe5
2022-06-25 18:30:53 +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 34274ca230 namespace PT renamed to pt 2021-05-20 16:25:01 +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 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 2afe111c57 escape table names in Finder (select sql statement)
WIP: #2
2021-04-30 01:23:22 +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 d78aa325d3 fixed: prepare_to_select() should initialize 'model' but it was initialized only in select() 2021-04-08 17:19:52 +02: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 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 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 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 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 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 08cd621d41 changed: some methods from ModelConnector moved to Model
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1119 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-07-04 11:34:49 +00:00
Tomasz Sowa e25b6d9a29 added: Finder::prefix() method
code not thoroughly tested



git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1106 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-05-01 23:22:32 +00:00
Tomasz Sowa 98206fdb7a added: field_model() method to Model
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1103 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-04-26 18:58:31 +00:00
Tomasz Sowa 3da8d1f411 fixed: finder.get() didn't check whether the resultset had exactly one item
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1098 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-04-23 19:02:38 +00:00
Tomasz Sowa fd1cc7debe added: Model::ModelData base class to use with Finder, Model.update(), Model.insert() and Model.remove()
added: Model.add_field_for_select() method 




git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1092 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-04-22 21:04:50 +00:00
Tomasz Sowa 4c0d203fc8 added:
removing objects
saving objects (either insert or update or remove)





git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1091 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-04-22 01:26:46 +00:00
Tomasz Sowa 476e5de292 added support for 'in()' statement in 'select'
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1086 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-04-18 17:52:09 +00:00
Tomasz Sowa ffb7ac85a6 added: QueryResult stack to PostgreSQLConnector
this allowes us to call query() recursively (from after_select() callback)



git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1085 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-04-18 10:22:01 +00:00
Tomasz Sowa 72b2622d08 some work in morm
- support for fetching rows from db
- support for inserting/updating rows



git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1081 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-04-16 22:46:25 +00:00
Tomasz Sowa 09f31b2803 some work in morm (select statement)
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1079 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-04-15 23:00:17 +00:00
Tomasz Sowa fceec43d07 some work for SELECT statement
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1077 e52654a7-88a9-db11-a3e9-0013d4bc506e
2018-03-30 19:34:45 +00:00