Hi Justin - 

I have run into the same issues and have given up on using MySQL++ interface
for that reason, plus it doesn't have the ability to update tables
dynamically.

That is, if you need to update anything, you have to define the table to a
macro at compile time!  Change a table, recompile everything!  NOT GOOD.

If all you want to do is to read result sets, then there are some classes
that work (sort of) in the contributed software under C++ interfaces called
MyDAO that sort of work.

I started writing my own classes (based on some ADO classes I wrote to work
with MS SQL Server) and then found these and based what I was doing off of
them as we had the same idea in mind.

They have some problems, but will work for retrieval of everything, but the
updating doesn't work right under all circumstances.

They have the virtue of loading table data at run time so they are dynamic,
too.

Some things to note, everything is returned as a string.  This means that if
you store a float in the database, you won't get a pointer back to for bytes
storing the actual float, you will get a string with the value of the float
(i.e.: "123.45").  It does data conversion for you. 

Likewise, the meanings of a few of the fields seems odd and getting the
table metadata for inserting is trickier than it seems.

Anyhow, take a look at those MyDAO classes.  If you just want retrieval,
they should work.

If you want update and insert capability, let me know and I'll send you my
expanded versions which are type safe, handle insert and update, and handle
binary data (blob and text) data types.

I'd send them to you know, but I am working on them this weekend to get them
touched up a bit and add documentation for doxygen to pick up.  They should
be done some time Monday afternno and I can send them to you then if you
want.

I have some connection and result set classes that are based on some virtual
base classes that invoke the same methods for MySQL and ADO data sources. 

There is also some wrappers for MySQL at sourceforge.net, but, I didn't like
them as much as I did my own.



        > Ken Hylton
        > 7826 Falcon Ridge Drive
        > San Antonio, Texas 78239-4032
        > 210-646-9508 (home)
        > 210-949-7261 (work)
        > 210-949-7254 (fax)
        > 210-287-6756 (cell)
        > [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> 
        > [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> 


                -----Original Message-----
                From:   Pure Krome [mailto:[EMAIL PROTECTED]]
                Sent:   Friday, March 01, 2002 6:52 PM
                To:     [EMAIL PROTECTED]
                Subject:        [NEWBIE] Problems with the RESULT Class.
Please Help :(

                Hello All.
                I'm trying to make a Class, that incorporates the MySQL++
code.  I'm trying
                to do this, so i don't have to have so much of the same
code, but instead
                re-use a common public function.

                This way, i can do something like this  in my c++ code...
                Result res = Database.ReturnRecordSet ("SELECT * FROM
tbl_Table");
                Result res = Database.ReturnRecordSet ("SELECT ID FROM
tbl_Table");
                etc..

                so when i do this ...  blnResult =
Database.DatabaseTablesExists ();
                it goes into that public member function, which calls the
ReturnRecordSet public member function to return a RESULT.
                A RESULT is returned, but when i leave the function, it
crashes.  I assume it's trying to destroy the local instance of the RESULT
class...

                Could i PLEASE have some help ?  I'm so confussed to why it
is crashing,
                when i'm basically copying the code straight from the
MYSQL++ examples. :(


                Thank you kindly to anyone that helps.
                Regards - Justin Adler-

                ++++++++++++++++++++++++++++++++++++++++++
                #define DATABASE_CC

                #include <sqlplus.hh>
                #include "Configuration.h"
                #include "Database.h"
                #include "Player.h"
                #include "Types.h"
                #include "String.h"




                CDatabase::CDatabase ()
                {
                // Create the Database Connection
                try {
                        con = new Connection (use_exceptions);
                        con->connect (DB_CONN_STRING);

                        query = new Query (con->query () );
                  }

                catch (BadQuery &er) {
                        HandleBadQuery (er);
                   }
                        catch (BadConversion &er) {
                        HandleBadConversion (er);
                  }
                #ifdef USE_STANDARD_EXCEPTION
                catch (exception &er) {
                        cerr << "[Exception] Error: " << er.what() << endl;
                  }
                #endif
                }


                CDatabase::~CDatabase ()
                {
                if (con)
                delete con; if (query)
                        delete query;
                }


                // Does a table in MySQL Table exist?  const bool
CDatabase::DatabaseTablesExists (void)
                {
                Result res;
                snprintf (sqlBuf, BUF_SIZE, "SHOW TABLES LIKE
'tbl_THINGS'");
                try {
                        res = ReturnRecordSet (sqlBuf); if (res.size () < 1)
return false;
                        else
                        return true;
                  }
                catch (BadConversion &er) {
                        HandleBadConversion (er);
                  }
                #ifdef USE_STANDARD_EXCEPTION
                catch (exception &er) {
                        cerr << "[Exception] Error: " << er.what() << endl;
                  }
                #endif
                return false;
                }



                Result CDatabase::ReturnRecordSet (const String sSQLString)
                {
                Result res;
                try {
                        (std::ostream&)*query << sSQLString; res =
query->store ();
                  }

                catch (BadQuery &er) {
                        HandleBadQuery (er);
                   }
                        catch (BadConversion &er) {
                        HandleBadConversion (er);
                  }
                #ifdef USE_STANDARD_EXCEPTION
                catch (exception &er) {
                        cerr << "[Exception] Error: " << er.what() << endl;
                  }
                #endif
                return res;
                }



                // Handle any connection or query errors that may come up
void CDatabase::HandleBadQuery (const BadQuery er)
                {
                #ifdef USE_STANDARD_EXCEPTION
                        cerr << "[Bad Query] Error: " << er.what() << endl;
                #else
                        cerr << "[Bad Query] Error: " << er.error << endl;
                #endif
                }


                // Handle bad conversions void
CDatabase::HandleBadConversion (const BadConversion er)
                {
                #ifdef USE_STANDARD_EXCEPTION
                                cerr << "[Bad Conversion] Error: " <<
er.what() << "\"." << endl
                << "retrieved data size: " << er.retrieved << " actual data
size: " << er.actual_size << endl;
                #else
                                cerr << "[Bad Conversion] Error: Tried to
convert \"" << er.data << "\"
                to a \""
                                << er.type_name << "\"." << endl;
                #endif
                }


                ++++++++++++++++++++++++++++++++++++++++++++++++
                #ifndef DATABASE_H
                #define DATABASE_H

                #include <sqlplus.hh>
                #include "Configuration.h"
                #include "String.h"
                #include "Types.h"

                // ---- NO INCLUDES BELOW THIS LINE ----
                #ifdef EXTERN
                #undef EXTERN
                #endif

                #ifdef DATABASE_CC
                #define EXTERN
                #else
                #define EXTERN extern
                #endif


                class CDatabase {
                public:

                        CDatabase ();
                            ~CDatabase ();

                        const bool DatabaseTablesExists (void);
                                // MySQL++ Database Communication
                                Result ReturnRecordSet (const String
sSQLString); // Returns a MySql++
                Result Class (a Recordset)
                    void   HandleBadQuery (const BadQuery er);
                    void   HandleBadConversion (const BadConversion er);


                private:
                        char sqlBuf[BUF_SIZE];
                        // MySQL++ Variables
                    Connection *con;   // A connection to the MySQL Database
                    Query *query;      // The SQL Query, passed through the
above Connection

                };

                EXTERN CDatabase Database;
                #endif   // DATABASE_H
                

---------------------------------------------------------------------
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