www.digitalmars.com         C & C++   DMDScript  

c++.windows.32-bits - Connecting to a DB and Running SQL

reply Cory in texas <Cory_member pathlink.com> writes:
I'd like to create a small program that will make a connection to a database and
then execute a few SQL commands.  What header files and or syntax would be best
to allow me to perform these actions?

Thanks for any help you can provide.

BTW here is  sample of the code I am writing:
/** Declaring variables **/
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 


EXEC SQL INCLUDE SQLCA;

int main(int argc, char *argv[]) { 
EXEC SQL BEGIN DECLARE SECTION; 
long col1; 
long col3; 
char userid[9]; 
char passwd[19]; 
short counter;
EXEC SQL END DECLARE SECTION; 
Dec 10 2003
parent Jan Knepper <jan smartsoft.us> writes:
HA!
No, that's not how it works.
C++ is NOT a database language.
If you want to connect to a database (server) you usually have to link a 
client with your code. MySQL for instance has such a client.
Than you have to establish connection and send the SQL command and 
receive the data back.

It's more like (very cryptical):

// Necessary #include's.

int  main ( int, char **, char ** )
{
    MySQLClient *    client = new  MySQLClient ( "<server name>", 
"<userid>", "<password>" );

    if ( client -> IsConnected () )
    {
       char *    response = 0;

       client -> Execute ( "SELECT * FROM ...", &reponse );

       // process 'response'.
    }

    delete  client;

    return (  0 );
}

Cory in texas wrote:
 I'd like to create a small program that will make a connection to a database
and
 then execute a few SQL commands.  What header files and or syntax would be best
 to allow me to perform these actions?
 
 Thanks for any help you can provide.
 
 BTW here is  sample of the code I am writing:
 /** Declaring variables **/
 #include <stdio.h> 
 #include <stdlib.h> 
 #include <string.h> 
 
 
 EXEC SQL INCLUDE SQLCA;
 
 int main(int argc, char *argv[]) { 
 EXEC SQL BEGIN DECLARE SECTION; 
 long col1; 
 long col3; 
 char userid[9]; 
 char passwd[19]; 
 short counter;
 EXEC SQL END DECLARE SECTION; 
 
 
-- ManiaC++ Jan Knepper
Dec 10 2003