Compile your first SPDB project with DevC++ and MySQL

(If you find an error in this Howto please let me know via email at andreasbresser (at) gmx (dot) de)

1. Download MySQL and create a MySQL-ODBC connection
1.1 Download MySQL-ODBC from here (I'm using Version 3.51)
1.2 Install MySQL-ODBC
1.3 Click on Start -> Settings -> Control Panel
1.4 Once you are in the Control Panel, double-click on "ODBC Data Sources or 32-bit ODBC"
1.5 click on the "Add..." button
1.6 Now the "Create New Data Source" window appears.
1.7 Select MySQL ODBC x.xx Driver and click on "Finish"
Now you see this:


1.8 The "Data Source Name" must be "odbc_demo" (you can of course use another name for your own Projects).
1.9 In The MySQL Connection Parameters you must enter your MySQL settings (see MySQL documentation for details).
1.10 (If all required fields are filled) click on "OK".
1.11 now you can see a new entry in the "User Data Source" section.


2. Compile your first SPDB program
2.1 start Dev-C++.
2.2 Click on "File" -> "Import" -> "Import MS Visual C++ Project".
2.3 Click on "...".
2.4 Select the file sptk-x.x\VC6\db_list_view.dsp (x.x is the SPTK-Version number) and click on "Open".
2.5 Click on "Import".
2.6 Click on "Yes".
2.7 Press ALT+P.
2.8 (VERY IMPORTANT) Select "Win32 Console" in the "Type" Section!!!
2.9 Click on "Parameters".
2.10 Click on "Add Libary or Object" under the "Linker"-Textbox.
2.11 Select the file SPTKlib.a form the devcpp/lib directory.
2.12 Click on "Open".
2.13 Repeat 2.10 to 2.12 with the files libfltk.a, libfltk_forms.a, libfltk_images.a, libodbc32.a, libodbcpp32.a and libfltk_gl.a.

(should look like this ;-))


2.14 Compile and run the Program (press F9) -> a DOS-Box will appear and close immediately.


3. Examine your compiled Program
3.1 Run a MS-DOS Box (click on "Start"->"Run" and open command.exe (under Windows 2000/XP you must open cmd.exe))
3.2 Go into your SPTK-x.x\VC6 directory (cd sptk-2.2alpha\vc6).
3.3 Type "db_list_view" and press enter
3.4 Now you (maybe) see this error:

This is because my MySQL-Version does not understand the "TEMP" command in the MySQL syntax. So I've changed the original Source a bit :-):
First, I removed the "TEMP" in line 106.
Then, I added The following line:
     CQuery    query0(&db,"DROP TABLE IF EXISTS companies");
This creates a new CQuery called query0.
To execute this Query I added this line:
    query0.exec();
The edited program should look like this (I have underlined my changes in green):



3.5 Recompile and run your Program (F9). Now you should see this:



Congratulations! You have successfully compiled a SPDB program with Dev-C++.

If you want to compile and run any other SPTK-Samples (like the sptk_test or odbc_demo) you need to include all SPTK, FLTK and ODBC libraries and (may be) change the SQL syntax (remove the "TEMP" and add an "DROP TABLE IF EXISTS" query if you get MySQL errors).
When your program runs fine you can change the Type from Win32Console to Win32Gui (Press ALT+P and click on Win32GUI), but than the SQL-Errors will not be shown to the user.

by Andreas Bresser andreasbresser (at) gmx (dot) de