[odb-users] Bad allocation exception thrown when executing query
bxt161230 at utdallas.edu
bxt161230 at utdallas.edu
Tue Jul 11 12:40:24 EDT 2017
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 at codesynthesis.com]
Sent: Tuesday, July 11, 2017 10:03 AM
To: Tarafdar, Bipul <Bipul.Tarafdar at utdallas.edu>
Cc: odb-users at codesynthesis.com
Subject: Re: [odb-users] Bad allocation exception thrown when executing query
bxt161230 at utdallas.edu <bxt161230 at 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<database> db(new odb::mysql::database("root", "password", "library", "localhost", 3306));
{
typedef odb::query<Book> query;
typedef odb::result<Book> result;
session s;
transaction t(db->begin());
std::stringstream ss;
ss << "%" << searchKey << "%";
result r(db->query<Book>(query::isbn.like(ss.str())));
ss.str("");
//result r(db->query<SearchResults>(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<QStandardItem *> 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 <string>
#include <odb/core.hxx>
#include <odb/tr1/memory.hxx>
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<Authors> authorsPtr;
// shared_ptr<Book> 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<std::_Tmap_traits<type_info const * __ptr64,odb::details::shared_ptr<odb::mysql::statements_base>,odb::details::type_info_comparator,std::allocator<std::pair<type_info const * __ptr64 const,odb::details::shared_ptr<odb::mysql::statements_base> > >,0> >::_Lbound<type_info const * __ptr64>(const type_info * const & _Keyval) Line 2060 C++
LibraryApp.exe!std::_Tree<std::_Tmap_traits<type_info const * __ptr64,odb::details::shared_ptr<odb::mysql::statements_base>,odb::details::type_info_comparator,std::allocator<std::pair<type_info const * __ptr64 const,odb::details::shared_ptr<odb::mysql::statements_base> > >,0> >::lower_bound(const type_info * const & _Keyval) Line 1538 C++
LibraryApp.exe!std::_Tree<std::_Tmap_traits<type_info const * __ptr64,odb::details::shared_ptr<odb::mysql::statements_base>,odb::details::type_info_comparator,std::allocator<std::pair<type_info const * __ptr64 const,odb::details::shared_ptr<odb::mysql::statements_base> > >,0> >::find(const type_info * const & _Keyval) Line 1481 C++
LibraryApp.exe!odb::mysql::statement_cache::find_object<Book>() Line 30 C++
LibraryApp.exe!odb::access::object_traits_impl<Book,0>::query(odb::database & __formal, const odb::mysql::query_base & q) Line 607 C++
LibraryApp.exe!odb::database::query_<Book,5,0>::call<odb::query<Book,odb::mysql::query_base> >(odb::database & db, const odb::query<Book,odb::mysql::query_base> & q) Line 478 C++
LibraryApp.exe!odb::database::query<Book>(const odb::query<Book,odb::mysql::query_base> & q, bool cache) Line 19 C++
LibraryApp.exe!DataBase::getSearch(std::basic_string<char,std::char_traits<char>,std::allocator<char> > & searchKey, QStandardItemModel * model, QTableView * ui) Line 24 C++
LibraryApp.exe!Business::search(std::basic_string<char,std::char_traits<char>,std::allocator<char> > & 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<QWidget> & 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<enum QEventLoop::ProcessEventsFlag> 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<enum QEventLoop::ProcessEventsFlag> flags) Line 613 C++
qwindowsd.dll!QWindowsGuiEventDispatcher::processEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags) Line 74 C++
Qt5Cored.dll!QEventLoop::processEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags) Line 135 C++
Qt5Cored.dll!QEventLoop::exec(QFlags<enum QEventLoop::ProcessEventsFlag> 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<char,std::char_traits<char>,std::allocator<char> >::_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<char,std::char_traits<char>,std::allocator<char> >::_Copy(unsigned __int64 _Newsize, unsigned __int64 _Oldlen) Line 2196 C++
odb-mysql-2.4-vc12.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _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<char,std::char_traits<char>,std::allocator<char> > & q) Line 108 C++
odb-mysql-2.4-vc12.dll!odb::mysql::query_base::operator+=(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & q) Line 342 C++
test1.exe!odb::mysql::query_column<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,16>::like(odb::mysql::val_bind<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > p) Line 125 C++
test1.exe!odb::mysql::query_column<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,16>::like(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & 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
More information about the odb-users
mailing list