Hi all!

I am looking for some advice on how to best design C++ programs that read, write, and update data in MySQL databases. I have completed a system that successfully does this but I'm not sure if I designed it the right way to take advantage of OOP principles and strengths.

The system I have built was something I wanted to manage my collection of woodworking articles from various magazines collected over the years. I wanted to query into my collection by keywords for all articles that would help me with a current woodworking project. For example, I can find all articles about building raised panel doors when I have a project to build a cabinet. I couldn't rely simply on a magazine's online or paper index because I have a collection of various mags that I have been receiving over many years and I inherited some from my father.

Some background: I am a retired IT tech professional. I started as an IBM mainframe systems programmer and became a fair programmer in 370 assembler, SAS, and some procedural languages. When I retired, I wanted to keep learning and have done a few things in PHP, Perl, and lately, C++. All of this work is done under and for Linux.

My woodworking index system is written in C++ with a MySQL data store. I wrote it as a GUI using Gtk. I have it working but feel I could do a better job (ie, tighter code and more in ...

Thanks, FBody! I'll rework my design to incorporate this and hope to make the code more elegant and tighter.

This is a request for some 'best practices' comments from experienced OOP practitioners. I have been in IT from the days of punched cards and have had considerable experience with legacy languages like 370 ASM, SAS, and REXX. For fun, I've taken a college class in C++ and am now working on a program for my personal use.

I am building a program that will let me create, maintain, and search a database of articles from woodworking magazines and books I've gathered over the years. When I want to start a new project, I want to search this database for articles that I can use in my project. I'm doing the program in C++ with GTKMM and using a MYSQL database, all under Linux.

I've built tables in MYSQL for the source of the article (magazine name, book, etc.), type of source (magazine, book, clipping, etc.), the article category (indoor furniture, etc.), the date/vol/issue, and some info on the article (source, page, category, title, and short synopsis). Some of these tables are simply used for reference (ie, category, type of source) while others contain data (source, date/vol/issue, and article).

I have a working program to enter data and am now working on classes to let me search and view the records and let me edit them (to correct errors). In today's working program, I have a class for the database with methods to connect, write data, retrieve data, and will write a method to let me update data. I also ...

The solution is to use GTK and GDA.

The problem is an incompatibility between the GTK programs and MySQL++. I have moved to using GDA and this is working!

Also look into D. S. Malik's books on C++. The local tech college used his "C++ Programming: From Problem Analysis to Program Design" for the C++ classes I took (which were labeled as intro and advanced object-oriented programming). I believe he has written others as well.

I am learning to write C++ code to access data in a MySQL database. My goal is to use a separate class to control the database access so I can use this class elsewhere. To facilitate my learning, I'm working on simple code to connect to a database (success!) and return all rows in a simple and small table (failing!).

The connection is OK through the class constructor but I'm getting a segmentation fault in the queryResults = query.store() in the class method. The backtrace, as I read it, says the failure is in a MySQL routine. (PS: The gtkmm.h is because I eventually want this class to be used by a GUI written in gtkmm.)

Any suggestions would be greatly appreciated!

Dave

[program messages and backtrace of gdb:]
Starting program: /home/dave/Code/mysql/main 
[Thread debugging using libthread_db enabled]
main: Trying to instantiate db class...
database: Trying to connect to test...
database: Connection was successful.
main: After instantiation of db class
main: Calling dbselect using:SELECT * FROM SourceType ORDER BY SourceTypeId
database: Do query using SELECT * FROM SourceType ORDER BY SourceTypeId
database: Did 'query << selectsql' 

Program received signal SIGSEGV, Segmentation fault.
0x00f15e94 in mysql_send_query () from /usr/lib/libmysqlclient.so.16
(gdb) bt
#0  0x00f15e94 in mysql_send_query () from /usr/lib/libmysqlclient.so.16
#1  0x00f15f30 in mysql_real_query () from /usr/lib/libmysqlclient.so.16
#2  0x00e8445f in mysqlpp::Query::store(char const*, unsigned int) ()
   from /usr/lib/libmysqlpp.so.3
#3  0x00e86e05 in mysqlpp::Query::store(mysqlpp::SQLTypeAdapter const&) ()
   from /usr/lib/libmysqlpp.so.3
#4  0x0804b2ae in mysqlpp::Query::store (this=0xbffff250)
    at /usr/include/mysql++/query.h:467
#5  0x0804a9b7 in DataBase::dbselect (this=0xbffff238, selectsql=...)
    at database.cc:31
#6  0x0804c74f in main ...

I am writing a GUI in GKTMM for my own learning experience and to use on a personal project I have at home. The data will be stored in a MySQL database on a server I already have running in my home and which I use for some PHP/JavaScript code that supports a 'library' application I wrote to keep track of the books my wife and I read.

I have a working GUI program but need to tie it into MySQL. Should I use MySQL++ for this or one of the Gnome data access middleware systems (e.g., libgdamm)? What are the advantages of one over the other? I have doc for MySQL++ and am working on a non-GUI program to learn those classes and methods (see another post) and would appreciate if you recommend libgdamm or like middleware, if you could include a link to that doc as well.

BTW, my target system is a Ubuntu 10.04 and I may look to port it to Windows (but that's a ways down the road).

Many Thanks!
Dave

Never mind! I had a brain fart. It's working now!

I'm running OpenSUSE 10.3 on a server with SAMBA providing file and printer services to PCs in my house (XP & Linux). I have a CRON entry starting a PERL program I wrote to backup the shared SAMBA files and other data to DVD on a weekly basis.

Currently the messages from this PERL program go to me via UNIX mail on that server. What do I need to do to get those messages sent to an Email account outside my home network? I'm not looking to put a full-function email server on this file server - I just want to get the CRON process messages sent to an Email account.

Thanks!