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 ([EMAIL PROTECTED])


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 <[EMAIL PROTECTED]>
 / /|_/ / // /\ \/ /_/ / /__   MySQL AB, FullTime Developer
/_/  /_/\_, /___/\___\_\___/   Larnaca, Cyprus
       <___/   www.mysql.com

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to