473,320 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

embedded SQL in C

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.
Nov 14 '05 #1
3 1537
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

Nov 14 '05 #2
>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
Nov 14 '05 #3
On 17 May 2004 08:56:10 -0700, fa*********@act.com.lb (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
re************************@att.net
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Jean-David Beyer | last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2 V6.1 (with all the FixPacks) on my old machine. I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat...
11
by: Mark Yudkin | last post by:
The documentation is unclear (at least to me) on the permissibility of accessing DB2 (8.1.5) concurrently on and from Windows 2000 / XP / 2003, with separate transactions scope, from separate...
8
by: Colleyville Alan | last post by:
I have been working on an Access app that takes info from a file and writes it to a spreadsheet on a form, simultaneously saving the spreadsheet to Excel. I got the idea that the same concept...
0
by: Nick White [MSFT] | last post by:
Hello fellow Microsoft Windows Mobile and Embedded enthusiasts: I invite you to peruse the list below of upcoming technical chats and Webcasts offered by the Windows Mobile and Embedded Devices...
59
by: Jeff Bowden | last post by:
For ease of configuration and other reasons, I would like for my single-user GUI app to be able to use postgresql in-process as a library accessing a database created in the users home directory. ...
49
by: Alex Vinokur | last post by:
Are there any restrictions/problems for use of C++ STL in development in embedded systems? In particular: * Does STL require too much space/memory? * Is 'implementation of STL...
0
by: YellowFin Announcements | last post by:
Whitepaper: "Yellowfin Reporting" enables Embedded Business Intelligence -------------------------------------------------------------------------------- Embedded reports are a standard...
1
by: leeanngriego | last post by:
I have a client who has asked me to find him some solid up and coming embedded engineers. 2 to 3 years expereince with Embedded Linux, VxWorks, Nucleus or any other RTOS who has working in L2/L3...
20
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
There are a few guarantees I exploit in the C Standard. For instance, I might write (unsigned)-1 to get the maximum value for an unsigned integer. Also, I might rely on things such as: ...
30
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
Let's say we had a simple function for returning the amount of days in a month: unsigned DaysInMonth(unsigned const month) { switch (month) { case 8: case 3: case 5:
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.