www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

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

↑ ↓ ← 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
↑ ↓ → 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