If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > embedded SQL into C Program

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-09-08, 11:18
digiman digiman is offline
Registered User
 
Join Date: Sep 2005
Posts: 9
embedded SQL into C Program

Hi,

I would like to write a C client program which streams in data into a table in a database (row by row) from a relatively large data file.

Has any body done this before? I am a complete amateur so would welcome any suggestions/ideas please!

Best Regards,
Digi.
Reply With Quote
  #2 (permalink)  
Old 04-09-08, 13:26
digiman digiman is offline
Registered User
 
Join Date: Sep 2005
Posts: 9
Where do I begin????

I am using Transact SQL on unix platform. I've written some basic C scripts and compiled them with success. I know want to connect to my SQL database and insert some records into a table from a file......

Can sum1 please help???????
Reply With Quote
  #3 (permalink)  
Old 04-26-08, 21:48
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Baghdad, Iraq
Posts: 697
So, let me see what I can glean from this.

You're writing in C on Unix. ANSI C, for gcc? Does it have to be C?

If you're a complete amateur, you'd be better off using a language like Perl. There are just far fewer headaches to deal with involving compilers and all the string manipulation a high level language takes care of.

I am using Transact SQL on unix platform. ... connect to my SQL database

Let's be absolutely clear: you are connecting to a Microsoft SQL Server DBMS via some unspecified interface and wish to send queries in the Transact SQL dialect of SQL. Is this correct?

Or are you connecting to a MySQL DBMS via some unspecified interface and wish to send queries in the MySQL dialect of SQL?

For the record, to connect to either of these databases through Perl and do what you want, you'd need to issue these commands (from the command line) to download the necessary libraries:

Code:
cpan install DBI
cpan install DBD::mysql
cpan install DBD::Sybase
And then this program would do what you're trying to do:

Code:
use DBI;

# For a SQL Server with TCP/IP on and using the default username / password, which is a huge security risk
my $dbh = DBI->connect('dbi:Sybase:host=sqlserver.acme.com', 'sa', '');
# For a MySQL running on localhost
my $dbh = DBI->connect('dbi:mysql:host=localhost;database=test', 'user', 'pass');
for my $num (1..100) {
    $dbh->execute('INSERT INTO test (foo, bar) VALUES (?, ?)', 
        {}, $num, 'test');
}
You can do it in C, the only caveat is that it would be far more code and not noticeably faster. In fact, it might be slower if you make some common amateur mistakes with string handling or memory management.

If you're determined to do it in C, the libsql library looks quite promising as it can connect to quite a few databases from a number of platforms with a much simpler interface than ODBC. In fact, it looks a lot like Perl's very nice DBI interface. But you've still got to be comfortable with your compiler and linker and with reading the APIs.
Reply With Quote
  #4 (permalink)  
Old 07-15-08, 04:01
Mitexi Mitexi is offline
Registered User
 
Join Date: Jul 2008
Posts: 13
I love programming . i always want update myself by learning new language. i have hear first time mysql with c. plz send some tutorial sites . so i can learn easily.
__________________
free web templates................website design
free flash templates...............website design company

Last edited by Mitexi; 07-15-08 at 04:37.
Reply With Quote
  #5 (permalink)  
Old 01-27-09, 00:32
hkp819 hkp819 is offline
Registered User
 
Join Date: Dec 2008
Posts: 59
For this problem visit this link. Hope this is useful for you..
EMBEDDED SQL IN C
DB2 Universal Database
__________________
New York Web design
Website design

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On