From zxbzswxr at gmail.com Thu Nov 1 07:31:56 2018 From: zxbzswxr at gmail.com (Music samal) Date: Fri Nov 2 06:58:45 2018 Subject: [odb-users] Questions about accessing database in parrallel(PPL library) using odb Message-ID: I want to read data from database , and using Microsoft PPL for parallel support, I write an class A, it has an id name which has string type and an Integer menber #pragma db object pointer(std::tr1::shared_ptr) class A { public: A(const string name_):name(name_) {} ~A() {} friend class odb::access; A() {} #pragma db id string name; int number; }; I just test three scenes the serial scene, the parrallel scene using parrallel_for_each from PPL the parrallel scene using task from PPL they all do the same thing, persisting 100 objects to database template __int64 time_call(Function&& f) { __int64 begin = GetTickCount(); f(); return GetTickCount() - begin; } // Parrallel test; create void ParrallelFun(std::vector & vAlist, shared_ptr & db) { parallel_for_each(begin(vAlist), end(vAlist), [&](int i) { transaction t(db->begin()); string newName = "Parallel_A" + to_string(i); shared_ptr tempA(new A(newName)); tempA->number = i; db->persist(tempA); // wait(10); t.commit(); // wait(4); }); } // serialize test void SerializeFun(std::vector & vAlist , shared_ptr & db) { for (auto iter : vAlist) { transaction t(db->begin()); string newName = "Serial_A" + to_string(iter); shared_ptr tempA(new A(newName)); tempA->number = iter; db->persist(tempA); // wait(10); t.commit(); } } // two task test void TaskParallel_1(); void TaskParallel_2(); int main(int argc, char* argv[]) { try { // PPLtest shared_ptr db(new odb::pgsql::database("postgres","123456","postgres","localhost",5432)); std::vector vList(100); for (int i = 0; i < 100; i++) { vList[i] = i; } __int64 elapseSerial = time_call([&vList, &db] { SerializeFun(vList, db); }); __int64 elapseParallel = time_call([&vList, &db] { ParrallelFun(vList, db); }); __int64 elapseParallelTask = time_call([]{ array, 2> tasks = { create_task([] { TaskParallel_1(); }), create_task([] { TaskParallel_2(); }) }; auto joinTask = when_all(begin(tasks), end(tasks)); joinTask.wait(); }); cout << "serial time: " << elapseSerial << " ms" << endl; cout << "parrallel time : " << elapseParallel << " ms" << endl; cout << "two Task time : " << elapseParallelTask << "ms" << endl; } catch (const odb::exception& odberr) { cerr << odberr.what() << endl; } system("pause"); return 0; } void TaskParallel_1() { shared_ptr db1(new odb::pgsql::database("postgres","123456","postgres","localhost",5432)); for (unsigned int i = 0; i < 50; i++) { transaction t(db1->begin()); string newName = "TaskParallel_1_" + to_string(i); shared_ptr temp(new A(newName)); temp->number = i; db1->persist(temp); t.commit(); } } void TaskParallel_2() { shared_ptr db2(new odb::pgsql::database("postgres", "123456", "postgres", "localhost", 5432)); for (unsigned int i = 0; i < 50; i++) { transaction t(db2->begin()); string newName = "TaskParallel_2_" + to_string(i); shared_ptr temp(new A(newName)); temp->number = i; db2->persist(temp); t.commit(); } } the ouput is somewhat puzzle to me, let me list the output here serial time : 406ms parrallel time : 2610ms two Task time: 359ms parrallel_for_each presents terriblely unacceptable result .Something must limit its performance. I tended to my friends for help , he told me may be it's the database connection ,not transaction that impacts the parrallel access performance.. so I just tried the third scene, I use two database variable for connection independently in task, the performace really improved. Really is the database connection the main factor impose the parrallel accessing perfomance? Can anyone supply more advices about parrallel accessing using odb? os : windows 10 compiler:vs2017 From boris at codesynthesis.com Fri Nov 2 08:01:03 2018 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Nov 2 08:10:49 2018 Subject: [odb-users] Questions about accessing database in parrallel(PPL library) using odb In-Reply-To: References: Message-ID: Music samal writes: > the ouput is somewhat puzzle to me, > let me list the output here > serial time : 406ms > parrallel time : 2610ms > two Task time: 359ms > > parrallel_for_each presents terriblely unacceptable result .Something must > limit its performance. I tended to my friends for help , he told me may be > it's the database connection ,not transaction that impacts the parrallel > access performance.. so I just tried the third scene, I use two database > variable for connection independently in task, the performace really > improved. Really is the database connection the main factor impose the > parrallel accessing perfomance? The database instance in ODB by default uses a connection pool so it should not matter whether you have one or two. I think the reason for poor parrallel_for_each performance lies in the way it is implemented, which is unclear. For example, if it tries to execute all 100 transactions simultaneously (e.g., from 100 different threads), then that would probably explain the result you are getting (due to high contention). From zxbzswxr at gmail.com Sun Nov 4 20:13:59 2018 From: zxbzswxr at gmail.com (Music samal) Date: Mon Nov 5 08:44:04 2018 Subject: [odb-users] Questions about accessing database in parrallel(PPL library) using odb In-Reply-To: References: Message-ID: following your advise , I have tried another sence .. I use 20 iterations and plus 200ms in every iteration using "wait(200);" the parralel scene is better than serial scence ... I used cout to pirnt commit message and found that code was been implemented in serial scene with no delay while take a little time before the iteration really began in parrallel scence , It's about 1500ms~ 2000ms delay I searched in MSDN and found parallel_for and parrallel_for_each which PPL supplies will take a short time rearrangging all iterations to work threads before iteration begin , and different scheduling policy can be choosen to lead to different performance influence .. Another scence, I increase the iteration number to 100'000.,obviously I kick out "wait(200)" and "cout" in every iteration and wait for result. the serial time 102062ms the parrallel time 27063ms It's amazing !!! From kexuetutu at sina.com Mon Nov 12 04:18:18 2018 From: kexuetutu at sina.com (Jerry) Date: Mon Nov 12 04:28:49 2018 Subject: [odb-users] Can I use relationship and polymorphic at the same time? Message-ID: <20181112091818.B350A5D0009A@webmail.sinamail.sina.com.cn> Hello ODB I'm trying use ODB in my program to save a class A that contains a std::map, which value is a pointer to base class B. My code is some what like below:there are 2 *.h to define each class/*----------File1----------*/ #pragma db object polymorphicclass B{......} #pragma db object no_idclass B1 : B{......} /*----------File2----------*/ #pragma db objectclass A{......protected: std::map> m_CheckSectionResultTable;......} When I compile the File2 with ODB, it tells me this D:\v1_8_1-New\src\YJKBridge\BridgePostProcess\BridgePostProcess\ElementDesignResult.h:40:68: error: unable to map C++ type '::std::map< long unsigned int, ::std::shared_ptr< ::SectionDesignResultBase > >::mapped_type' used in data member 'm_CheckSectionResultTable' to a SQLite database type My question are: 1.How to solve this error?Class B is already defined "object abstract", why can't Class A recognise the "std::map>" type in ODB compiler? 2.I'm confuse with the "value" and "object", this are my point:(1).I'll use "value" if one class is another class's member (direct, not by pointer);(2).I'll use "object" if i want to use the features of abstract and polymorphic;Question2: if a class need polymorphic and this class is another class's member(need "value" feature), how to define the ODB type? 3?I'm confuse with the "abstract" useage, this are my point:(1).I'll use "abstract" if i want to save class which contains base class's memeber; (I'm not sure if this is right. I have tried save Class B, which inherit Class A without the "abstract" lable, it seems the Class B can also save members which defined in Class A)(2).I'll use "polymorphic" if i want to save class by it's base class pointer;Question3: In program, class is common use both inherit and polymorphic. For this class, how can i define it's ODB type? (The manual tell me an object can't be both "abstract" and "polymorphic".) PS:I use VS2013 windowns Thinks -------------- next part -------------- A non-text attachment was scrubbed... Name: =?GBK?B?Q1N0cmluZy10cmFpdHMuemlw?= Type: application/zip Size: 4693 bytes Desc: not available Url : https://codesynthesis.com/pipermail/odb-users/attachments/20181112/b6dad9f6/GBKBQ1N0cmluZy10cmFpdHMuemlw.zip -------------- next part -------------- A non-text attachment was scrubbed... Name: =?GBK?B?MS5o?= Type: application/octet-stream Size: 590 bytes Desc: not available Url : https://codesynthesis.com/pipermail/odb-users/attachments/20181112/b6dad9f6/GBKBMS5o.obj From zxbzswxr at gmail.com Sat Nov 10 03:08:40 2018 From: zxbzswxr at gmail.com (Music samal) Date: Mon Nov 12 06:58:56 2018 Subject: [odb-users] Questions about enable cross-database access Message-ID: Does odb support cross-database access ? eg: A member in Table A of database AAA has foreign key constraint with Table B in database BBB. If it does, the tutorial is requried. Thank you ,Boris and other helpers OS : win10 Compiler: vs2017 From zxbzswxr at gmail.com Sat Nov 10 21:20:37 2018 From: zxbzswxr at gmail.com (Music samal) Date: Mon Nov 12 06:58:56 2018 Subject: [odb-users] Questions about export view class as DLL Message-ID: I want to use view structs on occasions. So I write some sample code to test it. It works well when I build it as EXE. But when I export it as dll. and use it in another project. VS post link errors LNK2001 let me show the code and error . my test.hxx ////// test.hxx /////// ////// ///// odb compile command /* odb -I D:\ODB\odbfiles -I E:\boost_1_67_0 -d pgsql --profile boost --export-symbol ODB_MODULE_EXPORT --generate-query --generate-schema --schema-format sql test.hxx */ #pragma once #ifdef BUILD_EXPORT #define ODB_MODULE_EXPORT __declspec(dllexport) #elif defined USE_DLL #define ODB_MODULE_EXPORT __declspec(dllimport) #else #define ODB_MODULE_EXPORT #endif #include // use boost::uuids::uuid as object Id #include #include #include #include using boost::uuids::uuid; using std::tr1::shared_ptr; using std::tr1::weak_ptr; using odb::tr1::lazy_weak_ptr; using odb::tr1::lazy_shared_ptr; using namespace odb::core; using namespace std; class SomeB; #pragma db object pointer(std::tr1::shared_ptr) class ODB_MODULE_EXPORT SomeA { public: SomeA() {} friend class odb::access; #pragma db id uuid m_Id; string m_strNodeId; #pragma db inverse(m_SupA) vector > m_vBs; }; #pragma db object pointer(std::tr1::shared_ptr) class ODB_MODULE_EXPORT SomeB { public: SomeB() {} friend class odb::access; #pragma db id uuid m_Id; string m_strNodeId; #pragma db on_delete(cascade) lazy_shared_ptr m_SupA; }; #pragma db view object(SomeB) pointer(std::tr1::shared_ptr) struct ODB_MODULE_EXPORT B_NodeId { string m_strNodeId; }; /////// /////// here is main.cpp in another project . ////// this main.cpp works well when it is builded with //// test.hxx , test-odb.hxx,test-odb.cxx ...... ///// as an exe ///// so I just remove main.cpp from project and build remain files ///// and export them as DLL. ///// //////// I copy the main.cpp to another project and import previous DLL /////// LINK error occured ////// error messages is listed at the bottom #include "database.hxx" #include #include "test.hxx" #include "test-odb.hxx" #include using boost::uuids::random_generator; using namespace odb::core; // using namespace boost::uuids; int main() { shared_ptr db(new odb::pgsql::database("postgres", "123456", "postgres", "localhost", 5432)); try { transaction t(db->begin()); random_generator rgen; shared_ptr SomeA1(new SomeA); SomeA1->m_Id = rgen(); SomeA1->m_strNodeId = "SomeA1"; uuid SomeA1Id = db->persist(SomeA1); vector vSomeBs; for (unsigned int i = 0; i < 5; i++) { shared_ptr tempB(new SomeB); tempB->m_Id = rgen(); tempB->m_strNodeId = "SomeB_" + to_string(i); tempB->m_SupA = SomeA1; vSomeBs.emplace_back(db->persist(tempB)); } t.commit(); t.reset(db->begin()); result resB_NodeIds(db->query(odb::query::SupA == SomeA1Id)); for (auto iB : resB_NodeIds) { cout << "B_NodeId : " << iB.m_strNodeId << endl; } db->erase(SomeA1Id); t.commit(); } catch (const odb::exception& odberror) { cerr << odberror.what() << endl; } catch (...) { } system("pause"); return 0; } //////// /////// this is link error tips /////// LNK2001 unsolved external symbol "public: static struct odb::pgsql::query_column const odb::pointer_query_columns >::SupA" (?SupA@ ?$pointer_query_columns@VSomeB@@$01V?$object_traits_impl@VSomeB@@$01@access @odb@@@odb@@2U?$query_column@Uuuid@uuids@boost@@$0O@@pgsql@2@B) structviewDllTest E:\structviewDllTest\main.obj 1 odb version: 2.4.0 release OS : win10 Compiler: VS2017 help!! From boris at codesynthesis.com Mon Nov 12 08:24:41 2018 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Nov 12 08:35:01 2018 Subject: [odb-users] Questions about enable cross-database access In-Reply-To: References: Message-ID: Music samal writes: > Does odb support cross-database access ? > > eg: A member in Table A of database AAA has foreign key constraint with > Table B in database BBB. If/how this works is database-specific with the only mechanism provided by ODB being support for qualifying the database name with a schema. See Section 14.1.8 "schema" for details. From boris at codesynthesis.com Mon Nov 12 08:31:41 2018 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Nov 12 08:41:59 2018 Subject: [odb-users] Can I use relationship and polymorphic at the same time? In-Reply-To: <20181112091818.B350A5D0009A@webmail.sinamail.sina.com.cn> References: <20181112091818.B350A5D0009A@webmail.sinamail.sina.com.cn> Message-ID: Jerry writes: > std::map> m_CheckSectionResultTable; > > When I compile the File2 with ODB, it tells me this > ElementDesignResult.h:40:68: error: unable to map C++ type '::std::map< long > unsigned int, ::std::shared_ptr< ::SectionDesignResultBase > >::mapped_type' > used in data member 'm_CheckSectionResultTable' to a SQLite database type This is most likely caused by shared_ptr not being the object pointer of B. See Section 3.3 "Object and View Pointers" for details. > 2. I'm confuse with the "value" and "object" [...] > 3. I'm confuse with the "abstract" useage [...] These are explained in the manual. Make sure you read through Chapter 3, "Working with Persistent Objects" in its entirety. From biohazard at hixxy.org Thu Nov 15 05:47:14 2018 From: biohazard at hixxy.org (Biohazard) Date: Thu Nov 15 05:58:01 2018 Subject: [odb-users] Fwd: Getting "different libodb-boost interface versions" when compiling from source In-Reply-To: References: Message-ID: Hello, I discovered this thread when having trouble using ODB with c++17 and the proceeded to give compiling the provided beta a try. Now I'm getting version mismatch errors that I can't figure out how to fix. These are the offending errors: src/data-odb.hpp:12:4: error: #error ODB and C++ compilers see different libodb-boost interface versions and: src/data-odb.hpp:22:2: error: #error ODB runtime version mismatch Are you able to advise me on how to solve this? Also, do you have any idea when the next stable release of ODB will be? Cheers, Troy From boris at codesynthesis.com Thu Nov 15 08:10:55 2018 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Nov 15 08:21:23 2018 Subject: [odb-users] Fwd: Getting "different libodb-boost interface versions" when compiling from source In-Reply-To: References: Message-ID: Biohazard writes: > Now I'm getting version mismatch errors that I can't figure out how to fix. You need to use matching versions of the ODB compiler and all the runtime libraries (libodb*). Also, after upgrading make sure that you have re-generated all the *-odb files with the new ODB compiler. > Also, do you have any idea when the next stable release of ODB will be? We are working towards a more continuous delivery and the new recommended way to acquire ODB is via build2 packages. Here are the instructions: https://codesynthesis.com/products/odb/doc/install-build2.xhtml We haven't packages the Boost and Qt profiles yet but can do that quickly if you would like to give it a try. From fengzhiwuxing05 at 163.com Tue Nov 20 20:12:04 2018 From: fengzhiwuxing05 at 163.com (=?gb2312?B?yqK35g==?=) Date: Wed Nov 21 05:44:23 2018 Subject: [odb-users] How should I use odb on ios, and how should I compile static libraries that are available on ios Message-ID: How should I use odb on ios, and how should I compile static libraries that are available on ios From lfiedler at informatik.uni-leipzig.de Wed Nov 21 05:42:30 2018 From: lfiedler at informatik.uni-leipzig.de (Lisa Fiedler) Date: Wed Nov 21 05:53:26 2018 Subject: [odb-users] Transaction within ODB Object class Message-ID: <8068af94-4f01-a3e8-61ee-82071b737e4d@informatik.uni-leipzig.de> Dear ODB community, I was trying to execute a databank transaction within an ODB Object class. That is I wanted to alter some of the attributes and update them in the databank within a member function. I therefore provided the databank object as parameter to the member function. However, I did not get this to work out. Is this even possible and if so how? Thanks. Best regards. From boris at codesynthesis.com Thu Nov 22 11:11:04 2018 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Nov 22 11:21:58 2018 Subject: [odb-users] Transaction within ODB Object class In-Reply-To: <8068af94-4f01-a3e8-61ee-82071b737e4d@informatik.uni-leipzig.de> References: <8068af94-4f01-a3e8-61ee-82071b737e4d@informatik.uni-leipzig.de> Message-ID: Lisa Fiedler writes: > I was trying to execute a databank transaction within an ODB Object class. > That is I wanted to alter some of the attributes and update them in the > databank within a member function. I therefore provided the databank object > as parameter to the member function. > > However, I did not get this to work out. Is this even possible and if so > how? It's hard to answer your question without more details. Specifically, what exactly you tried to do and what result you got (exceptions, etc). Showing the relevant code fragment is always helpful. From hua.wang at attobio.com Tue Nov 27 23:29:04 2018 From: hua.wang at attobio.com (=?gb2312?B?zfW7qg==?=) Date: Wed Nov 28 05:24:21 2018 Subject: [odb-users] how to use ODB for paged query Message-ID: <000001d486d2$e569d740$b03d85c0$@attobio.com> Hi Sir, I can?t find the solution for paged query of ODB, could you give me some advice for this section, Thanks! For example: there is a table have 1000 records, I want to get 100 items each time. ?? Walker ????? ??? ??????????????? Attogen Biomedical (Suzhou) Inc.Ltd. TEL?400-828-7399; FAX: 0512-62863009 ;Mobile:15151881025 E-Mail: hua.wang@attobio.com Website: www.attobio.com ?????????????218??????B3?401?? From boris at codesynthesis.com Thu Nov 29 06:57:26 2018 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Nov 29 07:08:42 2018 Subject: [odb-users] how to use ODB for paged query In-Reply-To: <000001d486d2$e569d740$b03d85c0$@attobio.com> References: <000001d486d2$e569d740$b03d85c0$@attobio.com> Message-ID: ?? writes: > For example: there is a table have 1000 records, I want to get 100 > items each time. This (the term is "pagination", BWT) is normally done in a database- specific way. See this earlier post for details: https://www.codesynthesis.com/pipermail/odb-users/2012-January/000429.html From zxbzswxr at gmail.com Thu Nov 29 20:50:24 2018 From: zxbzswxr at gmail.com (Music samal) Date: Fri Nov 30 05:02:54 2018 Subject: [odb-users] Question about complex query implementing Message-ID: If I have a class which has a std::string menber and It is stored in database as Name + index form #pragma db object class A{ public: A(){} friend class odb::access; #pragma db id uuid m_id; #pragma db column("name") std::string m_strName; }; If I want to store A object in the database, and make them show like that A1 has name AName_001; A2 has name AName_002; ..... AXX has name AName_0XX; ..... AZZZ has name AName_ZZZ; A1,A2.... AXX ....AZZZ are all A objects. If I want to query the an A object with this name form AName_XXX which has the biggist index, maybe it's AName_657 or other number and I want to return this number. what should I do to implement this query