Hi,
The question is on what platform and which compiler VC++ or VC++/MFC,
X-Windows with C++. You can create gui's on all of them and can access a
mysql database to by linking to the mysql client library or use ODBC on the
windows platform, probably you can link to mysql on MS-Windows too but I
have never tried that combination..
Querying the database is quite easy too.
Here is some code from a lex/yacc (on unix) parser I wrote, to check router
configuration files for security holes, that does some lookups in a database
(it is in C since flex/bison is C based, however that shouldn't make a
difference):
So you have (mysql) init, connect,select, store, fetch and close. That's
about it.
It is real easy actually and works great.
Regards, Ron AF Greve.
----------------------------------------------------------------------------
------------------
int Refresh = 1; // This variable determines if we want to refresh. This is
set after each run
// so everytime the rules file is read the fields are
refreshed
int CheckFields( char *Field )
{
typedef struct tagFieldname_t {
char *Fieldname;
struct tagFieldname_t *Next;
}Fieldname_t;
unsigned int num_fields;
MYSQL_FIELD *fields;
MYSQL_ROW Row;
MYSQL MySQL;
MYSQL_RES *Result;
static Fieldname_t *FieldnameList;
Fieldname_t *FieldWalk = FieldnameList, *Next, **ListWalk;
int FieldCnt;
int Cnt;
int Found = 0;
if( Refresh || !FieldnameList )
{
Refresh = 0; // Reset the refresh variable
// Free list if anything in it.
while( FieldWalk )
{
Next = FieldWalk->Next;
if( FieldWalk->Fieldname ) free( FieldWalk->Fieldname );
free( FieldWalk );
FieldWalk = Next;
}
FieldnameList = NULL; // if we leave prematurly
mysql_init( &MySQL );
if( !mysql_connect( &MySQL, CoCoConf.Database, CoCoConf.Account,
CoCoConf.Password ) )
{
printf( "Couldn't connect to database account<%s> password<%s>
%s:%d\n",CoCoConf.Account, CoCoConf.Password, __FIL
E__, __LINE__ );
return 0;
}
if( mysql_select_db( &MySQL, "Asap_Auth" ) )
{
printf( "Couldn't select database in %s:%d\n", __FILE__, __LINE__ );
mysql_close( &MySQL );
return 0;
}
if( mysql_query( &MySQL, "SHOW COLUMNS FROM Routers" ) )
{
printf( "Couldn't list database fields in %s:%d\n", __FILE__,
__LINE__ );
mysql_close( &MySQL );
return 0;
}
if( !( Result = mysql_store_result( &MySQL ) ) )
{
printf( "Couldn't list database fields in %s:%d\n", __FILE__,
__LINE__ );
mysql_close( &MySQL );
return 0;
}
// Fil the list
ListWalk = &FieldnameList;
while( Row = mysql_fetch_row( Result ) )
{
if( !( *ListWalk = (Fieldname_t*)malloc( sizeof( Fieldname_t ) ) ) )
{
fprintf( stderr, "Out of memory in %s:%d\n", __FILE__, __LINE__ );
exit(1);
}
memset( *ListWalk, 0, sizeof( Fieldname_t ) );
if( !( (*ListWalk)->Fieldname = (char*)malloc( strlen( Row[0] ) +
1 ) ) )
{
fprintf( stderr, "Out of memory in %s:%d\n", __FILE__, __LINE__ );
exit(1);
}
strcpy( (*ListWalk)->Fieldname, Row[0] );
ListWalk = &(*ListWalk)->Next;
}
mysql_free_result( Result );
mysql_close( &MySQL );
}
FieldWalk = FieldnameList;
while( FieldWalk && !Found )
{
Found = !strcmp( FieldWalk->Fieldname, Field );
FieldWalk = FieldWalk->Next;
}
return Found;
}