From cezanmeyen at gmail.com Fri Apr 5 09:44:24 2019 From: cezanmeyen at gmail.com (Cezan Meyen) Date: Fri Apr 5 10:02:45 2019 Subject: [odb-users] Unable to map a member of a member via #pragma Message-ID: Hello there, I am currently implementing ODB in a existing program and therefore I am unable to change the models. And it is working great so far but I am currently stuck on a single object member. I need in some way access to the member or a member via the pragma's. I don?t know if this is possible at all but I cannot find a way to map this member. I might be doing something completly wrong. I some posted example code underneath here for some context. template struct FixString { public: sampleget(); sampleSet(); private char m_str[max_length + 1]; } typedef FixString<24> name_string; struct string_id { public: FixString<24> uuid; } typedef string_id ID; struct main { name_string name; ID id; } //pragmas contained in a different file #pragma db object(main) #pragma db value(name_string) #pragma db member(name_string::m_str) get(sampleget()) set(sampleSet()) // this works okay! #pragma db value(ID) #pragma db member(ID::uuid) //unable to map C++ type 'FixString<24>' <--- expected error #pragma db member(ID::uuid::m_str) //unable to resolve type name '::ID::uuid' in db pragma member I can't seem to access m_str form ID which is necessary to define the get and set. Kind regards, Cezan From boris at codesynthesis.com Mon Apr 8 07:19:55 2019 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Apr 8 07:38:08 2019 Subject: [odb-users] Unable to map a member of a member via #pragma In-Reply-To: References: Message-ID: Cezan Meyen writes: > typedef FixString<24> name_string; > > struct string_id > { > public: > FixString<24> uuid; > } > typedef string_id ID; > > > //pragmas contained in a different file > #pragma db object(main) > > #pragma db value(name_string) > #pragma db member(name_string::m_str) get(sampleget()) set(sampleSet()) > // this works okay! > > #pragma db value(ID) > #pragma db member(ID::uuid) //unable to map C++ > type 'FixString<24>' <--- expected error You should use name_string (or some other named and mapped value type) for string_id::uuid. Or, better, yet, map FixString<24> as described here: https://www.codesynthesis.com/~boris/blog/2012/10/16/custom-cxx-to-database-type-mapping-in-odb/ Or, if you are using the 2.5.0 pre-release, using '#pragma db map'. From lfiedler at informatik.uni-leipzig.de Thu Apr 18 07:29:48 2019 From: lfiedler at informatik.uni-leipzig.de (Lisa Fiedler) Date: Thu Apr 18 07:48:48 2019 Subject: [odb-users] Use of postgresql array mapping for native views Message-ID: Hello, I was trying to use a postgresql array mapping to a vector within a native view. That is I generated a file "traits-pgsql.hxx" with content: #ifndef TRAITS_PGSQL_HXX #define TRAITS_PGSQL_HXX #include // std::size_t #include // std::strncmp, std::memset, std::memcpy #include #include #include #include #include "../configdb.hpp" #include ?? // localtime, mktime, time_t, tm #include namespace odb { ? namespace pgsql ? { ??? template <> ??? class value_traits, id_string> ??? { ??? public: ????? typedef std::vector value_type; ????? typedef value_type query_type; ????? typedef details::buffer image_type; ????? static void ????? set_value (value_type& v, ???????????????? const details::buffer& b, ???????????????? std::size_t n, ???????????????? bool is_null) ????? { ??????? v.clear (); ??????? if (!is_null) ??????? { ????????? char c; ????????? std::istringstream is (std::string (b.data (), n)); ????????? is >> c; // '{' ????????? for (c = static_cast (is.peek ()); c != '}'; is >> c) ????????? { ??????????? v.push_back (u_int64_t ()); ??????????? is >> v.back (); ????????? } ??????? } ????? } ????? static void ????? set_image (details::buffer& b, ???????????????? std::size_t& n, ???????????????? bool& is_null, ???????????????? const value_type& v) ????? { ??????? is_null = false; ??????? std::ostringstream os; ??????? os << '{'; ??????? for (value_type::const_iterator i (v.begin ()), e (v.end ()); ???????????? i != e;) ??????? { ????????? os << *i; ????????? if (++i != e) ??????????? os << ','; ??????? } ??????? os << '}'; ??????? const std::string& s (os.str ()); ??????? n = s.size (); ??????? if (n > b.capacity ()) ????????? b.capacity (n); ??????? std::memcpy (b.data (), s.c_str (), n); ????? } ??? }; ? } } #endif // TRAITS_PGSQL_HXX and in taxonomy.hxx, where I was planning to use this mapping I wrote: typedef std::vector id_vector; #pragma db value(id_vector) type("BIGINT[]") and tried to use this in a native query like this: #pragma db view struct queryTaxonomyPath_view{ ??? #pragma db type("BIGINT[]") ??? id_vector path; }; The error message I get is: ./include/complete/taxonomy.hxx:241:15: error: invalid PostgreSQL type declaration: unexpected character '[' Makefile:60: recipe for target 'include/complete/taxonomy-odb.cxx' failed make: *** [include/complete/taxonomy-odb.cxx] Error 1 make: *** Waiting for unfinished jobs.... ./include/complete/taxonomy.hxx:241:15: error: invalid PostgreSQL type declaration: unexpected character '[' terminate called after throwing an instance of 'cutl::fs::error' what(): filesystem error *** WARNING *** there are active plugins, do not report this as a bug unless you can reproduce it without enabling any plugins. Event | Plugins PLUGIN_START_UNIT | odb PLUGIN_PRAGMAS | odb PLUGIN_OVERRIDE_GATE | odb In file included from /usr/local/odb-2.5.0-b.13/libodb/include/odb/container-traits.hxx:217:0, from :4: /usr/local/odb-2.5.0-b.13/libodb/include/odb/std-unordered-set-traits.hxx: In function ?void __static_initialization_and_destruction_0(int, int)?: /usr/local/odb-2.5.0-b.13/libodb/include/odb/std-unordered-set-traits.hxx:122:1: internal compiler error: Aborted } ^ To generate the *odb.ixx and *odb.cxx files I used: /usr/local/odb-2.5.0-b.13/odb/bin/odb -d pgsql -I/usr/local/odb-2.5.0-b.13/libodb/include --std c++11 --generate-query --generate-prepared --hxx-prologue "#include \"traits-pgsql.hxx\"" ./include/complete/properties.hxx ./include/complete/structures.hxx ./include/complete/taxonomy.hxx ./include/complete/edge.hxx ./include/complete/record.hxx If I remove the native view there are no error messages. Thank you in advance! From becoggins at hotmail.com Sat Apr 20 12:20:58 2019 From: becoggins at hotmail.com (Brian Coggins) Date: Sat Apr 20 12:39:58 2019 Subject: [odb-users] Testing whether lazy_shared_ptr is null Message-ID: Imagine I have two types of object A and B with a unidirectional A to B relationship. If I load an object A containing a lazy_shared_ptr< B >, what is the best way to determine whether this lazy_shared_ptr< B > represents a relationship to an instance of B (of any kind, transient or persistent, loaded or unloaded), or if it is null? >From reading the docs, I think I could call lazy_shared_ptr< B >::load() and then test whether the returned shared_ptr< B > is nullptr. However, if lazy_shared_ptr< B > points to a B, this has the side effect of loading the instance of B, and I don?t actually need the B. I just need to know whether A has a relationship to B. It seems like there must be a way to check this without loading the pointed-to object? Of course, at the database level one could query for whether the field in A representing the relationship is NULL, but I was hoping to find a way to get this info from the C++ object. Thanks, Brian From boris at codesynthesis.com Mon Apr 22 12:02:43 2019 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Apr 22 12:21:43 2019 Subject: [odb-users] Use of postgresql array mapping for native views In-Reply-To: References: Message-ID: Lisa Fiedler writes: > value_traits, id_string> > > [...] > > typedef std::vector id_vector; > #pragma db value(id_vector) type("BIGINT[]") This doesn't make much sense to me: you are providing a mapping traits for vector to string but then trying to use BIGINT[] as the database type? I suggest that you read through this article and see if it clarifies things: https://www.codesynthesis.com/~boris/blog/2012/07/18/custom-database-to-cxx-type-mapping-in-odb/ From boris at codesynthesis.com Mon Apr 22 12:17:19 2019 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Apr 22 12:36:16 2019 Subject: [odb-users] Testing whether lazy_shared_ptr is null In-Reply-To: References: Message-ID: Brian Coggins writes: > Imagine I have two types of object A and B with a unidirectional A to B > relationship. If I load an object A containing a lazy_shared_ptr< B >, > what is the best way to determine whether this lazy_shared_ptr< B > > represents a relationship to an instance of B (of any kind, transient > or persistent, loaded or unloaded), or if it is null? Hm, if you want to check whether the pointer is not NULL (i.e., either contains an object id or points to a transient object), then that would simply be: if (p != nullptr) If you want to know if the above mentioned object id actually references something real in the database, then, naturally, the only way to answer that question is to try to load it. Also, just to add a point about weak pointers, to correctly test whether it is NULL you need to call it's lock() function, get the strong pointer, and then proceed as above. From lfiedler at informatik.uni-leipzig.de Tue Apr 23 03:05:40 2019 From: lfiedler at informatik.uni-leipzig.de (Lisa Fiedler) Date: Tue Apr 23 03:24:54 2019 Subject: [odb-users] Use of postgresql array mapping for native views In-Reply-To: References: Message-ID: <39c72fab-64f4-e9af-b252-37514454263c@informatik.uni-leipzig.de> On 4/22/19 6:02 PM, Boris Kolpackov wrote: > Lisa Fiedler writes: > >> value_traits, id_string> >> >> [...] >> >> typedef std::vector id_vector; >> #pragma db value(id_vector) type("BIGINT[]") > This doesn't make much sense to me: you are providing a mapping > traits for vector to string but then trying to use > BIGINT[] as the database type? I agree. I am sorry. But even after writing the following lines (note I am using vector now to reproduce the instructions in the article): #pragma db map type("BIGINT *\\[(\\d*)\\]") \ ?????????????? as("TEXT")??????????????????? \ ?????????????? to("(?)::BIGINT[$1]")??????? \ ?????????????? from("(?)::TEXT") typedef std::vector id_vector; #pragma db value(id_vector) type("BIGINT[]") and then using precisely the same value_traits as in https://www.codesynthesis.com/~boris/blog/2012/07/18/custom-database-to-cxx-type-mapping-in-odb/ and then trying to do #pragma db view struct queryTaxonomyPath_view{ ??? #pragma db type("BIGINT[]") ??? id_vector path; }; and ??? odb::result res ??????????? (db_->query("SELECT * FROM complete.generate_taxonomic_path(" +to_string(taxId) + "::bigint)")); ??? cout << "size: " << res.size() << endl; ??? for(auto & it : res){ ??????? cout << it.path.size() << endl; ??? } does compile, however never terminates upon execution. res.size() is still printed, but at the for loop the program gets stuck. generate_taxonomic_path is a postgresql user defined function, which returns a table with an attribute of type BIGINT[]. I don't understand why this does not work out ? > > I suggest that you read through this article and see if it > clarifies things: > > https://www.codesynthesis.com/~boris/blog/2012/07/18/custom-database-to-cxx-type-mapping-in-odb/ From lfiedler at informatik.uni-leipzig.de Tue Apr 23 03:43:14 2019 From: lfiedler at informatik.uni-leipzig.de (Lisa Fiedler) Date: Tue Apr 23 04:02:22 2019 Subject: [odb-users] Use of postgresql array mapping for native views In-Reply-To: <39c72fab-64f4-e9af-b252-37514454263c@informatik.uni-leipzig.de> References: <39c72fab-64f4-e9af-b252-37514454263c@informatik.uni-leipzig.de> Message-ID: <5f3d3e2b-6ba1-6bc6-1385-c7490acf832c@informatik.uni-leipzig.de> Never mind, it works now. Thank you very much for pointing me to this article!! On 4/23/19 9:05 AM, Lisa Fiedler wrote: > > On 4/22/19 6:02 PM, Boris Kolpackov wrote: >> Lisa Fiedler writes: >> >>> value_traits, id_string> >>> >>> [...] >>> >>> typedef std::vector id_vector; >>> #pragma db value(id_vector) type("BIGINT[]") >> This doesn't make much sense to me: you are providing a mapping >> traits for vector to string but then trying to use >> BIGINT[] as the database type? > > I agree. I am sorry. > > But even after writing the following lines (note I am using > vector now to reproduce the instructions in the article): > > #pragma db map type("BIGINT *\\[(\\d*)\\]") \ > ?????????????? as("TEXT")??????????????????? \ > ?????????????? to("(?)::BIGINT[$1]")??????? \ > ?????????????? from("(?)::TEXT") > > typedef std::vector id_vector; > #pragma db value(id_vector) type("BIGINT[]") > > and then using precisely the same value_traits as in > > https://www.codesynthesis.com/~boris/blog/2012/07/18/custom-database-to-cxx-type-mapping-in-odb/ > > > and then trying to do > > #pragma db view > struct queryTaxonomyPath_view{ > > ??? #pragma db type("BIGINT[]") > ??? id_vector path; > }; > > and > > ??? odb::result res > ??????????? (db_->query("SELECT * FROM > complete.generate_taxonomic_path(" +to_string(taxId) + "::bigint)")); > ??? cout << "size: " << res.size() << endl; > > ??? for(auto & it : res){ > ??????? cout << it.path.size() << endl; > > ??? } > > does compile, however never terminates upon execution. res.size() is > still printed, but at the for loop the program gets stuck. > > generate_taxonomic_path is a postgresql user defined function, which > returns a table with an attribute of type BIGINT[]. > > I don't understand why this does not work out ? > >> >> I suggest that you read through this article and see if it >> clarifies things: >> >> https://www.codesynthesis.com/~boris/blog/2012/07/18/custom-database-to-cxx-type-mapping-in-odb/ >> > From becoggins at hotmail.com Tue Apr 23 08:58:57 2019 From: becoggins at hotmail.com (Brian Coggins) Date: Tue Apr 23 09:18:06 2019 Subject: [odb-users] Testing whether lazy_shared_ptr is null In-Reply-To: References: Message-ID: On Apr 22, 2019, at 12:17 PM, Boris Kolpackov wrote: > Also, just to add a point about weak pointers, to correctly test whether > it is NULL you need to call it's lock() function, get the strong pointer, > and then proceed as above. Ah, my mistake! This was the problem. I have a number of lazy_shared_ptr and lazy_weak_ptr going in various directions in this schema, and the relationship I wanted to test was actually a lazy_weak_ptr. I couldn?t figure out why it wouldn?t convert to bool, but it makes sense that it has to be locked first. Thanks, Brian From noah.sk at protonmail.ch Fri Apr 26 04:01:21 2019 From: noah.sk at protonmail.ch (noah.sk) Date: Fri Apr 26 04:20:40 2019 Subject: [odb-users] CMake/autotools/meson support in release Message-ID: Hi! We look to use ODB as C++ ORM but currently we have discovered lack of support widely used build systems in ODB beta and git versions. Unfortunately, we are limited to use build tools like CMake, autotools or meson to make own build of ODB. Do you plan to continue support only build2? Is there any chance of adding CMake/autotools/maven support to ODB 2.5.0 release? Thanks. Best regards, Noah. From ps.georgiou at gmail.com Fri Apr 26 04:36:27 2019 From: ps.georgiou at gmail.com (Panayiotis Georgiou) Date: Fri Apr 26 04:55:56 2019 Subject: [odb-users] CMake/autotools/meson support in release In-Reply-To: References: Message-ID: Hi, Some time ago, I found the following repository: https://github.com/BtbN/OdbCmake It includes an example of CMakeLists.txt, and the useful modules FindODB.cmake and UseODB.cmake. I've been using it in my project with ODB 2.4.0 and Cmake with good success. Not all the command line parameters of the ODB compiler are supported, but if you have a look in UseODB.cmake, it's relatively easy to add new ones. P. On Fri, Apr 26, 2019 at 9:01 AM noah.sk wrote: > Hi! We look to use ODB as C++ ORM but currently we have discovered lack of > support widely used build systems in ODB beta and git versions. > > Unfortunately, we are limited to use build tools like CMake, autotools or > meson to make own build of ODB. > > Do you plan to continue support only build2? > > Is there any chance of adding CMake/autotools/maven support to ODB 2.5.0 > release? > > Thanks. Best regards, Noah. > > From noah.sk at protonmail.ch Fri Apr 26 06:50:32 2019 From: noah.sk at protonmail.ch (noah.sk) Date: Fri Apr 26 07:09:56 2019 Subject: [odb-users] CMake/autotools/meson support in release In-Reply-To: References: Message-ID: It is for building apps with ODB, not for building ODB itself. ??????? Original Message ??????? On Friday, April 26, 2019 11:36 AM, Panayiotis Georgiou wrote: > Hi, > > Some time ago, I found the following repository: > https://github.com/BtbN/OdbCmake > > It includes an example of CMakeLists.txt, and the useful modules FindODB.cmake and UseODB.cmake. > > I've been using it in my project with ODB 2.4.0 and Cmake with good success. Not all the command line parameters of the ODB compiler are supported, but if you have a look in UseODB.cmake, it's relatively easy to add new ones. > > P. > > On Fri, Apr 26, 2019 at 9:01 AM noah.sk wrote: > >> Hi! We look to use ODB as C++ ORM but currently we have discovered lack of support widely used build systems in ODB beta and git versions. >> >> Unfortunately, we are limited to use build tools like CMake, autotools or meson to make own build of ODB. >> >> Do you plan to continue support only build2? >> >> Is there any chance of adding CMake/autotools/maven support to ODB 2.5.0 release? >> >> Thanks. Best regards, Noah. From boris at codesynthesis.com Fri Apr 26 11:08:47 2019 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Apr 26 11:27:59 2019 Subject: [odb-users] CMake/autotools/meson support in release In-Reply-To: References: Message-ID: noah.sk writes: > Unfortunately, we are limited to use build tools like CMake, autotools > or meson to make own build of ODB. > > Do you plan to continue support only build2? Yes, currently we only plan to support build2 as a way to build ODB (which is not to say that you cannot use other build systems for your own project that use ODB). Note also that quite a few (also initially skeptical) users have successfully integrated a build2-based ODB build into their setup. The fact that build2 is dependency-free (all you need is a C++ compiler) and can easily be invoked from other build systems makes this fairly straightforward. So maybe give it a try? https://codesynthesis.com/products/odb/doc/install-build2.xhtml From per.edin at sequence-point.se Sun Apr 28 05:12:08 2019 From: per.edin at sequence-point.se (Per Edin) Date: Mon Apr 29 07:49:20 2019 Subject: [odb-users] CMake/autotools/meson support in release In-Reply-To: References: Message-ID: On Fri, Apr 26, 2019 at 5:09 PM Boris Kolpackov wrote: > > noah.sk writes: > > > Do you plan to continue support only build2? > > Yes, currently we only plan to support build2 as a way to build ODB > (which is not to say that you cannot use other build systems for your > own project that use ODB). > Noah, it's definitely worth the potential "trouble" of switching to build2. If CMake is the build-system equivalent of what SVN is to CVS, then build2 is the build-system equivalent of what Git is to SVN. Advanced, flexible, has a ton of new concepts and documentation, and a bit of a threshold to learn initilly. But I'll never go back to anything else for my own projects. Add the quality of ODB into the mix and it's a no-brainer. // Per From aheadsoftwaredeveloper at gmail.com Tue Apr 30 23:07:47 2019 From: aheadsoftwaredeveloper at gmail.com (Allan Head) Date: Wed May 1 09:29:03 2019 Subject: [odb-users] Visual Studio 2017 - LNK1104 cannot open file 'odb-mysql-d.lib' for Hello World Message-ID: OS: Win 10 Pro Build 17763 ver 1809 ODB Version: 2.5.0-b.13 Examples File: odb-examples-2.4.0.zip After following the Build2 installation instructions, I cannot seem to get the Hello World example to work. I opened the hello-mysql-vc12 project and upgraded it to vc141. The program compiles, but during the build it generates the error LINK: fatal error LNK1104: cannot open file 'odb-mysql-d.lib'. I do not have an 'odb-mysql-d.lib' file, but I do have an odb-mysql.lib file and an odb-mysql.dll.lib file. Should the odb-example-2.4.0 work under ODB 2.5.0-b.13 or am I trying to do the impossible? Allan