December 10, 2003 Connecting to a DB and Running SQL | ||||
---|---|---|---|---|
| ||||
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; |
December 10, 2003 Re: Connecting to a DB and Running SQL | ||||
---|---|---|---|---|
| ||||
Posted in reply to Cory in texas | 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 |
Copyright © 1999-2021 by the D Language Foundation