[prev in list] [next in list] [prev in thread] [next in thread]
List: mysql-plusplus
Subject: Re: MYSQL++: Any ideas why this code causes the program to crash?
From: Sinisa Milivojevic <sinisa () mysql ! com>
Date: 2001-06-18 10:20:05
[Download RAW message or body]
David Ayliffe writes:
> I wrote this program in VC++ using the MYSQL++ API for VC. I have a
> generic function (below) which I call numerous times each time with a
> different query string. It works fine the first time around. But the
> second time I call this function it causes the program to crash. I
> think it could be that a constructor is called but no deconstructor.
> Could this be the problem? What deconstructor should I use??
>
> I have trimmed the code for functionality:
>
> <--CODE-->
>
> void main()
> { bool j = ExecQuery("select * from stock"); }
>
>
> bool ExecQuery(string sQuery)
> {
> Connection con(def_db_name, def_host_name, def_user_name,
> def_password);
> Query query = con.query();
> // This creates a query object that is bound to con.
>
> query << sQuery;
> // You can write to the query object like you would any other
> ostrem
>
> cout << endl << "Query: " << query.preview() << endl;
> // Show the query before it is executed
> // Query::preview() simply returns a string with the current
> query
> // string in it.
>
> Result res = query.store();
> // Query::store() executes the query and returns the results
>
> Row row;
> cout.setf(ios::left);
> // cout << setw(17) << "Database Name" << endl << endl;
>
> Result::iterator i;
>
> for (i = res.begin(); i != res.end(); i++)
> {
> row = *i;
> cout << setw(17) << row[0]
> << setw(4) << row[1]
> << setw(7) << row[2]
> << setw(7) << row[3]
> << row[4] << endl;
> }
> cout << endl << "Records Found: " << res.size() << endl;
>
> return 1;
> }
>
> <--END OF CODE-->
>
> ANY INPUT APPRECIATED
>
> Thanks lots
> David Ayliffe (mail@ayliffe.com)
Hi!
No, destructor is not a problem. In C++, you do not have to call
destructor except implicitely, e.g. with delete operator on dynamic
objects.
In your program you only use local objects, so C++ itself generates
calls to destructors.
Your problem is may be that you do send queries to the above method
that do not return result sets.
--
Regards,
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Mr. Sinisa Milivojevic <sinisa@mysql.com>
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, FullTime Developer
/_/ /_/\_, /___/\___\_\___/ Larnaca, Cyprus
<___/ www.mysql.com
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic