From frankiegp at libero.it Sun Jul 2 07:02:20 2017 From: frankiegp at libero.it (Giovanni Loizzo) Date: Sun Jul 2 07:02:29 2017 Subject: [odb-users] =?utf-8?q?=E2=98=A2just_take_a_look?= Message-ID: <1646752522.20170702130220@libero.it> Hi! I've gathered some interesting information, just take a look, it may be helpful for you. You may read it here http://www.torres-zen.com/home.php?7372 Best Wishes, Giovanni Loizzo Sent from Mail for Windows 10 From bxt161230 at utdallas.edu Mon Jul 10 16:16:33 2017 From: bxt161230 at utdallas.edu (bxt161230@utdallas.edu) Date: Tue Jul 11 10:20:36 2017 Subject: [odb-users] Bad allocation exception thrown when executing query Message-ID: Hi I need am facing exceptions, both in release and debug, with exceptions thrown while executing a query. This is the query I try to execute : result r(db->query(query::bname.like(ss.str()))); The exception is Exception thrown at 0x00007FFE2B033C58 in test1.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x000000EA3C4FE9B0. Exception thrown at 0x00007FFE2B033C58 in test1.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x000000EA3C4FC3B0. Exception thrown at 0x00007FFE2B033C58 in test1.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000. Exception thrown at 0x00007FFE2B033C58 in test1.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x000000EA3C4FC3B0. Sometimes I also get a read access violation as below Exception thrown: read access violation. std::_Tree,odb::details::type_info_comparator,std::allocator > >,0> >::_Root(...) returned 0x8. Is this behavior because my table has 10000 entries and there is not enough memory to store this data? I have been trying to play with sessions and caches, but I think my premature knowledge of ODB takes me nowhere. Could you please help me with this problem? Regards Bipul From boris at codesynthesis.com Tue Jul 11 11:02:47 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Jul 11 11:02:57 2017 Subject: [odb-users] Bad allocation exception thrown when executing query In-Reply-To: References: Message-ID: bxt161230@utdallas.edu writes: > I need am facing exceptions, both in release and debug, with exceptions > thrown while executing a query. Try to run your application under a debugger and get the stack trace of where exactly the exception is thrown. > Is this behavior because my table has 10000 entries and there is not > enough memory to store this data? This depends on how much data is stored in each row/object and how much RAM you have. You didn't say which database you are using so it is hard to reason about any additional memory used for caching, etc. Boris From bxt161230 at utdallas.edu Tue Jul 11 12:40:24 2017 From: bxt161230 at utdallas.edu (bxt161230@utdallas.edu) Date: Tue Jul 11 13:37:12 2017 Subject: [odb-users] Bad allocation exception thrown when executing query In-Reply-To: References: Message-ID: Hi Boris, Thank you for your response. Using Visual Studios debugger, I get two different stack traces for the same query. I am using a MySQL database. I have attached the stack traces to this email, and also attaching my create file and the classes I have created to use odb. Thanks, Bipul -----Original Message----- From: Boris Kolpackov [mailto:boris@codesynthesis.com] Sent: Tuesday, July 11, 2017 10:03 AM To: Tarafdar, Bipul Cc: odb-users@codesynthesis.com Subject: Re: [odb-users] Bad allocation exception thrown when executing query bxt161230@utdallas.edu writes: > I need am facing exceptions, both in release and debug, with > exceptions thrown while executing a query. Try to run your application under a debugger and get the stack trace of where exactly the exception is thrown. > Is this behavior because my table has 10000 entries and there is not > enough memory to store this data? This depends on how much data is stored in each row/object and how much RAM you have. You didn't say which database you are using so it is hard to reason about any additional memory used for caching, etc. Boris -------------- next part -------------- #include "DataBase.h" using namespace odb; DataBase::DataBase() { } void DataBase::getSearch(string& searchKey, QStandardItemModel* model, QTableView * ui) { try{ auto_ptr db(new odb::mysql::database("root", "password", "library", "localhost", 3306)); { typedef odb::query query; typedef odb::result result; session s; transaction t(db->begin()); std::stringstream ss; ss << "%" << searchKey << "%"; result r(db->query(query::isbn.like(ss.str()))); ss.str(""); //result r(db->query(query::isbn.like(ss.str()) /*|| query::title.like(ss.str()) || // query::author.like(ss.str())*/)); for (result::iterator it(r.begin()); it != r.end(); ++it) { QList rowItems; rowItems << new QStandardItem(QString::fromStdString(it->getISBN())); rowItems << new QStandardItem(QString::fromStdString(it->getTitle())); //rowItems << new QStandardItem(QString::fromStdString(it->getAuthor())); //rowItems << new QStandardItem(it->getAvail()); model->appendRow(rowItems); ui->update(); /*string isbn = i->getISBN(); string title = i->getTitle(); string author = i->getAuthor(); bool avail = i->getAvail(); SearchResults r(isbn, title, author, avail); results.push_back(r);*/ } delete &r; t.commit(); } } catch (const odb::exception& e) { cerr << e.what() << endl; } catch (const std::bad_exception& e) { cerr << e.what() << endl; } catch (const std::exception& e) { cerr << e.what() << endl; } } -------------- next part -------------- #pragma once #include #include #include using namespace std; using std::tr1::shared_ptr; #pragma db object table("book") session(false) pointer(std::tr1::shared_ptr) class Book { private: friend class odb::access; #pragma db id type("char(13)") column("isbn") string isbn; #pragma db type("VARCHAR(200)") column("title") string title; public: Book() {}; Book(const string& isbn, const string& title) : isbn(isbn), title(title) {}; string getISBN() { return isbn; } string getTitle() { return title; } }; #pragma db object table("authors") session(false) pointer(std::tr1::shared_ptr) class Authors { private: friend class odb::access; #pragma db id auto type("int") column("author_id") int authorId; #pragma db type("VARCHAR(200)") column("name") string authorName; public: Authors() {}; Authors(const int& authorId, const string& authorName) : authorId(authorId), authorName(authorName) {}; int getId() { return authorId; } string getName() { return authorName; } }; /* Card_id CHAR(8) NOT NULL, SSN CHAR(11) NOT NULL, Bname VARCHAR(20) NOT NULL, Address VARCHAR(50) NOT NULL, Phone CHAR(14), */ #pragma db object table("borrower") session(false) pointer(std::tr1::shared_ptr) class borrower { private: friend class odb::access; #pragma db id auto type("char(8)") column("Card_id") string cardId; #pragma db type("CHAR(11)") column("SSN") string ssn; #pragma db type("VARCHAR(20)") column("bname") string bname; #pragma db type("VARCHAR(50)") column("address") string address; #pragma db type("char(14)") column("phone") string phone; public: borrower() {}; string getId() { return cardId; } string getssn() { return ssn; } string getName() { return bname; } string getaddress() { return address; } string getphone() { return phone; } }; //#pragma db object no_id table("book_authors") //class BookAuthors //{ //private: // friend class odb::access; ////#pragma db id auto type("int") column("author_id") //// int authorId; // shared_ptr authorsPtr; // shared_ptr bookPtr; // //public: // BookAuthors() {}; // /*Book(const int& authorId, const string& isbn) : // authorId(authorId), isbn(isbn) {}; // // int getId() { return authorId; } // string getName() { return isbn; }*/ //}; -------------- next part -------------- > LibraryApp.exe!std::_Tree,odb::details::type_info_comparator,std::allocator > >,0> >::_Lbound(const type_info * const & _Keyval) Line 2060 C++ LibraryApp.exe!std::_Tree,odb::details::type_info_comparator,std::allocator > >,0> >::lower_bound(const type_info * const & _Keyval) Line 1538 C++ LibraryApp.exe!std::_Tree,odb::details::type_info_comparator,std::allocator > >,0> >::find(const type_info * const & _Keyval) Line 1481 C++ LibraryApp.exe!odb::mysql::statement_cache::find_object() Line 30 C++ LibraryApp.exe!odb::access::object_traits_impl::query(odb::database & __formal, const odb::mysql::query_base & q) Line 607 C++ LibraryApp.exe!odb::database::query_::call >(odb::database & db, const odb::query & q) Line 478 C++ LibraryApp.exe!odb::database::query(const odb::query & q, bool cache) Line 19 C++ LibraryApp.exe!DataBase::getSearch(std::basic_string,std::allocator > & searchKey, QStandardItemModel * model, QTableView * ui) Line 24 C++ LibraryApp.exe!Business::search(std::basic_string,std::allocator > & searchKey, QStandardItemModel * model, QTableView * ui) Line 17 C++ LibraryApp.exe!LibraryApp::searchTextChanged() Line 20 C++ LibraryApp.exe!LibraryApp::qt_static_metacall(QObject * _o, QMetaObject::Call _c, int _id, void * * _a) Line 76 C++ Qt5Cored.dll!QMetaObject::activate(QObject * sender, int signalOffset, int local_signal_index, void * * argv) Line 3742 C++ Qt5Cored.dll!QMetaObject::activate(QObject * sender, const QMetaObject * m, int local_signal_index, void * * argv) Line 3603 C++ Qt5Widgetsd.dll!QAbstractButton::clicked(bool _t1) Line 310 C++ Qt5Widgetsd.dll!QAbstractButtonPrivate::emitClicked() Line 413 C++ Qt5Widgetsd.dll!QAbstractButtonPrivate::click() Line 405 C++ Qt5Widgetsd.dll!QAbstractButton::mouseReleaseEvent(QMouseEvent * e) Line 1010 C++ Qt5Widgetsd.dll!QWidget::event(QEvent * event) Line 8781 C++ Qt5Widgetsd.dll!QAbstractButton::event(QEvent * e) Line 967 C++ Qt5Widgetsd.dll!QPushButton::event(QEvent * e) Line 676 C++ Qt5Widgetsd.dll!QApplicationPrivate::notify_helper(QObject * receiver, QEvent * e) Line 3745 C++ Qt5Widgetsd.dll!QApplication::notify(QObject * receiver, QEvent * e) Line 3219 C++ Qt5Cored.dll!QCoreApplication::notifyInternal2(QObject * receiver, QEvent * event) Line 988 C++ Qt5Cored.dll!QCoreApplication::sendSpontaneousEvent(QObject * receiver, QEvent * event) Line 234 C++ Qt5Widgetsd.dll!QApplicationPrivate::sendMouseEvent(QWidget * receiver, QMouseEvent * event, QWidget * alienWidget, QWidget * nativeWidget, QWidget * * buttonDown, QPointer & lastMouseReceiver, bool spontaneous) Line 2713 C++ Qt5Widgetsd.dll!QWidgetWindow::handleMouseEvent(QMouseEvent * event) Line 618 C++ Qt5Widgetsd.dll!QWidgetWindow::event(QEvent * event) Line 240 C++ Qt5Widgetsd.dll!QApplicationPrivate::notify_helper(QObject * receiver, QEvent * e) Line 3745 C++ Qt5Widgetsd.dll!QApplication::notify(QObject * receiver, QEvent * e) Line 3105 C++ Qt5Cored.dll!QCoreApplication::notifyInternal2(QObject * receiver, QEvent * event) Line 988 C++ Qt5Cored.dll!QCoreApplication::sendSpontaneousEvent(QObject * receiver, QEvent * event) Line 234 C++ Qt5Guid.dll!QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent * e) Line 1928 C++ Qt5Guid.dll!QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent * e) Line 1712 C++ Qt5Guid.dll!QWindowSystemInterface::sendWindowSystemEvents(QFlags flags) Line 716 C++ qwindowsd.dll!QWindowsGuiEventDispatcher::sendPostedEvents() Line 83 C++ Qt5Cored.dll!qt_internal_proc(HWND__ * hwnd, unsigned int message, unsigned __int64 wp, __int64 lp) Line 223 C++ user32.dll!00007ffe2e151c24() Unknown user32.dll!00007ffe2e15156c() Unknown Qt5Cored.dll!QEventDispatcherWin32::processEvents(QFlags flags) Line 613 C++ qwindowsd.dll!QWindowsGuiEventDispatcher::processEvents(QFlags flags) Line 74 C++ Qt5Cored.dll!QEventLoop::processEvents(QFlags flags) Line 135 C++ Qt5Cored.dll!QEventLoop::exec(QFlags flags) Line 212 C++ Qt5Cored.dll!QCoreApplication::exec() Line 1261 C++ Qt5Guid.dll!QGuiApplication::exec() Line 1658 C++ Qt5Widgetsd.dll!QApplication::exec() Line 2922 C++ LibraryApp.exe!main(int argc, char * * argv) Line 9 C++ LibraryApp.exe!WinMain(HINSTANCE__ * __formal, HINSTANCE__ * __formal, char * __formal, int __formal) Line 111 C++ LibraryApp.exe!invoke_main() Line 99 C++ LibraryApp.exe!__scrt_common_main_seh() Line 253 C++ LibraryApp.exe!__scrt_common_main() Line 296 C++ LibraryApp.exe!WinMainCRTStartup() Line 17 C++ kernel32.dll!00007ffe2e098364() Unknown ntdll.dll!00007ffe2e6170d1() Unknown -------------- next part -------------- KernelBase.dll!00007ffe2b033c58() Unknown vcruntime140.dll!00007ffe1d382a10() Unknown ntdll.dll!00007ffe2e65a193() Unknown > odb-mysql-2.4-vc12.dll!`std::basic_string,std::allocator >::_Copy'::`1'::catch$107() Line 2200 C++ vcruntime140.dll!00007ffe1d38c220() Unknown vcruntime140.dll!00007ffe1d3829b2() Unknown ntdll.dll!00007ffe2e65a193() Unknown odb-mysql-2.4-vc12.dll!std::basic_string,std::allocator >::_Copy(unsigned __int64 _Newsize, unsigned __int64 _Oldlen) Line 2196 C++ odb-mysql-2.4-vc12.dll!std::basic_string,std::allocator >::assign(const std::basic_string,std::allocator > & _Right, unsigned __int64 _Roff, unsigned __int64 _Count) Line 1155 C++ odb-mysql-2.4-vc12.dll!odb::mysql::query_base::append(const std::basic_string,std::allocator > & q) Line 108 C++ odb-mysql-2.4-vc12.dll!odb::mysql::query_base::operator+=(const std::basic_string,std::allocator > & q) Line 342 C++ test1.exe!odb::mysql::query_column,std::allocator >,16>::like(odb::mysql::val_bind,std::allocator > > p) Line 125 C++ test1.exe!odb::mysql::query_column,std::allocator >,16>::like(const std::basic_string,std::allocator > & pattern) Line 713 C++ test1.exe!main() Line 36 C++ test1.exe!invoke_main() Line 65 C++ test1.exe!__scrt_common_main_seh() Line 253 C++ test1.exe!__scrt_common_main() Line 296 C++ test1.exe!mainCRTStartup() Line 17 C++ kernel32.dll!00007ffe2e098364() Unknown ntdll.dll!00007ffe2e6170d1() Unknown -------------- next part -------------- A non-text attachment was scrubbed... Name: create_script.sql Type: application/octet-stream Size: 2604 bytes Desc: create_script.sql Url : http://codesynthesis.com/pipermail/odb-users/attachments/20170711/c6f711ea/create_script.obj From boris at codesynthesis.com Thu Jul 13 09:52:28 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Jul 13 09:52:38 2017 Subject: [odb-users] Bad allocation exception thrown when executing query In-Reply-To: References: Message-ID: bxt161230@utdallas.edu writes: > Using Visual Studios debugger, I get two different stack traces for > the same query. I am using a MySQL database. I have attached the > stack traces to this email, and also attaching my create file and > the classes I have created to use odb. I looked at your database and it is unlikely you are really running out of memory. So this most likely a memory corruption. Try to run your application under a memory checking tool. I am not sure what's the options are on Windows, on Linux you could try valgrind or an address sanitizer. Another thought: check that your are not loading the same object recursively (e.g., via a cyclical relationship). If that's the case, then use odb::session (see the manual for details). Boris From andrew at a-cunningham.com Thu Jul 13 15:01:09 2017 From: andrew at a-cunningham.com (Andrew Cunningham) Date: Fri Jul 14 03:29:25 2017 Subject: [odb-users] Wrapping existing members with std::atomic<> Message-ID: I need to take some of my 'existing' persistent member variables (typically int and bool) and wrap them in std::atomic<> without messing with my schema. Can you suggest a strategy? I can imagine a number of ways , but the best approach is not that obvious. Andrew From boris at codesynthesis.com Fri Jul 14 03:58:09 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Jul 14 03:58:20 2017 Subject: [odb-users] Wrapping existing members with std::atomic<> In-Reply-To: References: Message-ID: Andrew Cunningham writes: > I need to take some of my 'existing' persistent member > variables (typically int and bool) and wrap them in std::atomic<> without > messing with my schema. I think the "proper" way to handle this would be to define the odb::wrapper_traits specialization for std::atomic, similar to nullable, optional, smart pointers, etc. For an example, see the specialization for boost::optional in libodb-boost (files of interest are optional.options and optional/wrapper-traits.hxx in the odb/boost/ subdirectory). Except in your case it won't be a NULL handler. There is one snag with this approach: the odb::wrapper_traits interface expects you to return references to the underlying value. I think there is a way to make it work if you don't need atomicity during database operations. Is this a reasonable assumption in your case? Boris From odb at a-cunningham.com Fri Jul 14 10:25:03 2017 From: odb at a-cunningham.com (Andrew Cunningham) Date: Fri Jul 14 10:25:16 2017 Subject: [odb-users] Wrapping existing members with std::atomic<> In-Reply-To: References: Message-ID: Hi Boris, That's correct. I do not need to worry about atomicity during DB operations. It's used when I am doing multi-threaded operations on the objects after they are loaded. Andrew On Fri, Jul 14, 2017 at 12:58 AM, Boris Kolpackov wrote: > Andrew Cunningham writes: > > > I need to take some of my 'existing' persistent member > > variables (typically int and bool) and wrap them in std::atomic<> without > > messing with my schema. > > I think the "proper" way to handle this would be to define the > odb::wrapper_traits specialization for std::atomic, similar to > nullable, optional, smart pointers, etc. For an example, see the > specialization for boost::optional in libodb-boost (files of > interest are optional.options and optional/wrapper-traits.hxx in > the odb/boost/ subdirectory). Except in your case it won't be a > NULL handler. > > There is one snag with this approach: the odb::wrapper_traits > interface expects you to return references to the underlying > value. I think there is a way to make it work if you don't > need atomicity during database operations. Is this a reasonable > assumption in your case? > > Boris > From odb at a-cunningham.com Fri Jul 14 10:36:43 2017 From: odb at a-cunningham.com (Andrew Cunningham) Date: Fri Jul 14 10:36:55 2017 Subject: [odb-users] Wrapping existing members with std::atomic<> In-Reply-To: References: Message-ID: HI Boris, I already have defined a wrapper for my 'own' smart pointer, so am pretty clear about the process. I was hoping for something simpler - I think my solution is to use a transient atomic and copy that to/from a persistent field "pre persist" and "postload." Andrew On Fri, Jul 14, 2017 at 7:25 AM, Andrew Cunningham wrote: > Hi Boris, > That's correct. I do not need to worry about atomicity during DB > operations. > It's used when I am doing multi-threaded operations on the objects after > they are loaded. > > Andrew > > On Fri, Jul 14, 2017 at 12:58 AM, Boris Kolpackov > wrote: > >> Andrew Cunningham writes: >> >> > I need to take some of my 'existing' persistent member >> > variables (typically int and bool) and wrap them in std::atomic<> >> without >> > messing with my schema. >> >> I think the "proper" way to handle this would be to define the >> odb::wrapper_traits specialization for std::atomic, similar to >> nullable, optional, smart pointers, etc. For an example, see the >> specialization for boost::optional in libodb-boost (files of >> interest are optional.options and optional/wrapper-traits.hxx in >> the odb/boost/ subdirectory). Except in your case it won't be a >> NULL handler. >> >> There is one snag with this approach: the odb::wrapper_traits >> interface expects you to return references to the underlying >> value. I think there is a way to make it work if you don't >> need atomicity during database operations. Is this a reasonable >> assumption in your case? >> >> Boris >> > > From boris at codesynthesis.com Sun Jul 16 12:03:44 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Sun Jul 16 12:03:54 2017 Subject: [odb-users] Wrapping existing members with std::atomic<> In-Reply-To: References: Message-ID: Andrew Cunningham writes: > I already have defined a wrapper for my 'own' smart pointer, so am pretty > clear about the process. I was hoping for something simpler - I think my > solution is to use a transient atomic and copy that to/from a persistent > field "pre persist" and "postload." You could use a virtual data member then: class foo { #pragma db transient std::atomic count; #pragma db member(count_) virtual(std::uint64_t) \ get(this.count.load (std::memory_order_relaxed)) \ set(this.count.store ((?), std::memory_order_relaxed)) }; Alternatively, if you have several such members, you can map std::atomic along these lines: using atomic_uint64_t = std::atomic; #pragma db map type(atomic_uint64_t) as(std::uint64_t) \ to((?).load (std::memory_order_relaxed)) \ from(atomic_uint64_t (?)) Then in your classes they can be used as any other members: class foo { std::atomic count1; std::atomic count2; } Boris From odb at a-cunningham.com Tue Jul 18 13:53:19 2017 From: odb at a-cunningham.com (Andrew Cunningham) Date: Tue Jul 18 13:53:32 2017 Subject: [odb-users] Wrapping existing members with std::atomic<> In-Reply-To: References: Message-ID: Hi Boris, Thanks for the useful and comprehensive answer - I certainly learned something about #pragma db map.. Andrew On Sun, Jul 16, 2017 at 9:03 AM, Boris Kolpackov wrote: > Andrew Cunningham writes: > > > I already have defined a wrapper for my 'own' smart pointer, so am pretty > > clear about the process. I was hoping for something simpler - I think my > > solution is to use a transient atomic and copy that to/from a persistent > > field "pre persist" and "postload." > > You could use a virtual data member then: > > class foo > { > > #pragma db transient > std::atomic count; > > #pragma db member(count_) virtual(std::uint64_t) \ > get(this.count.load (std::memory_order_relaxed)) \ > set(this.count.store ((?), std::memory_order_relaxed)) > > }; > > Alternatively, if you have several such members, you can map std::atomic > along these lines: > > using atomic_uint64_t = std::atomic; > > #pragma db map type(atomic_uint64_t) as(std::uint64_t) \ > to((?).load (std::memory_order_relaxed)) \ > from(atomic_uint64_t (?)) > > Then in your classes they can be used as any other members: > > class foo > { > std::atomic count1; > std::atomic count2; > } > > Boris >