Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > embedded SQL in C

Reply
Thread Tools

embedded SQL in C

 
 
Fadi Komati
Guest
Posts: n/a
 
      05-17-2004
Dear C Gurus,
I am currently working on finalysing my final project for Masters
degree.
However, i have stumbled into a tiny technical detail.
I need to execute SQL queries , create, and update statements from
within C.

I have been searching for two weeks to find an easy way of doing it
without success.

Does anyone has a small running sample C Code that execute SQL queries
???
or if you can point me in the right direction

I am using MS Visual C++ as a developping environment on windows !!!
(although my program is a C application)

Thank you for your help.
 
Reply With Quote
 
 
 
 
Thomas Matthews
Guest
Posts: n/a
 
      05-17-2004
Fadi Komati wrote:
> Dear C Gurus,
> I am currently working on finalysing my final project for Masters
> degree.
> However, i have stumbled into a tiny technical detail.
> I need to execute SQL queries , create, and update statements from
> within C.
>
> I have been searching for two weeks to find an easy way of doing it
> without success.
>
> Does anyone has a small running sample C Code that execute SQL queries
> ???
> or if you can point me in the right direction
>
> I am using MS Visual C++ as a developping environment on windows !!!
> (although my program is a C application)
>
> Thank you for your help.


The _standard_ method to do this is to place your SQL
statements into a string then send them to their destination.
Perhaps through a stream interface.

A non-portable method is to consult your OS and see how
to send commands to another application, such as a database
driver. How to do this is off-topic in news:comp.lang.c
so you will have to research a platform specific newsgroup.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

 
Reply With Quote
 
 
 
 
Gordon Burditt
Guest
Posts: n/a
 
      05-17-2004
>I need to execute SQL queries , create, and update statements from
>within C.
>
>I have been searching for two weeks to find an easy way of doing it
>without success.
>
>Does anyone has a small running sample C Code that execute SQL queries
>???
>or if you can point me in the right direction
>
>I am using MS Visual C++ as a developping environment on windows !!!
>(although my program is a C application)


Some databases provide an interface using standard C with an
additional library added, with no fancy tricks, preprocessors, or
extended syntax beyond that of C. (How you execute SQL is going
to be *HIGHLY* dependent on what database you are using, even given
a specific C compiler on a specific platform.) You make a string
with a query in it and then execute it. sprintf() is often useful
here:

#include <stdio.h>
#include <mysql.h>

MYSQL *m;
char querybuf[10240]; /* hope this is big enough */
char *host;

m = mysql_connect( /* appropriate args here */);
... /* check that m is not NULL */
... /* host points at something valid here */

sprintf(querybuf,
"INSERT INTO spammers(ip, date) VALUES ('%s', now())",
host);
mysql_query(m, querybuf); /* may want to test return value */

Note that if host points (or could point) to a string with funny
characters in it, you are vulnerable to a SQL injection attack.
Quoting those characters is beyond the scope of this post.

Gordon L. Burditt
 
Reply With Quote
 
Alan Balmer
Guest
Posts: n/a
 
      05-17-2004
On 17 May 2004 08:56:10 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (Fadi Komati)
wrote:

>Dear C Gurus,
>I am currently working on finalysing my final project for Masters
>degree.
>However, i have stumbled into a tiny technical detail.
>I need to execute SQL queries , create, and update statements from
>within C.
>
>I have been searching for two weeks to find an easy way of doing it
>without success.
>
>Does anyone has a small running sample C Code that execute SQL queries
>???
>or if you can point me in the right direction
>
>I am using MS Visual C++ as a developping environment on windows !!!
>(although my program is a C application)
>
>Thank you for your help.

{OT}
What you probably want is "Embedded SQL", or ESQL. This is
accomplished by using a preprocessor supplied by the database
developer. While the SQL itself is standardized, I don't think the
embedding method is, so you'll need documentation from the vendor.

What database are you using? Ask in a newsgroup which discusses that
database.

--
Al Balmer
Balmer Consulting
(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Embedded <divs> with events: How to prevent the parent div's eventfrom being fired when the embedded div's event is fired? Num GG Javascript 2 11-17-2008 08:56 PM
Embedded vs. Non-embedded Tests Trans Ruby 11 09-05-2007 11:22 AM
Embedded languages based on early Ada (from "Re: Preferred OS, processor family for running embedded Ada?") Colin Paul Gloster VHDL 48 04-10-2007 10:31 AM
How to display images embedded in e-mail as embedded, not attachments Jim Firefox 4 12-11-2004 05:36 AM
Databind an embedded control in an embedded datagrid Thomas Dodds ASP .Net Datagrid Control 0 07-26-2004 08:20 PM



Advertisments