Compile your first SPDB Project with DevC++ and Microsoft Access

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

1. Create an Access Database.
1.1 Start Microsoft Access.
1.2 Click on File -> New.
(The new Database-Window appears).
1.3 Select any folder and click on Create.
1.4 Close MS Access.

2. Create an ODBC Connection to your Database 2.1 Click on Start -> Settings -> Control Panel.
2.2 Once you are in the Control Panel, double-click on "ODBC Data Sources or 32-bit ODBC".
2.3 click on the "Add..." button.
2.4 Now the "Create New Data Source" window appears.
2.5 Select "Microsoft Access Driver (*.mdb)" and click on "Finish"
Now the "ODBC Microsoft Access Setup" Window appears.
2.6 The "Data Source Name" must be "odbc_demo" (you can of course use another name for your own Projects).
2.7 Click on "Select" in the Database section and select your Database.
2.8 Click on "OK" (When you get a "File-not-found" error close Microsoft Access and make sure that nobody is connected to this database).
2.9 now you can see a new entry in the "User Data Source" window.
2.10 Click on "OK".


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 Library 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 (may be) see this error:

This is because my Microsoft Access version (Access 2002) does not understand the "TEMP" command in the MySQL-Syntax. So I change 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 (maybe) 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