Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2005

    Unanswered: embedded SQL into C Program


    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,

  2. #2
    Join Date
    Sep 2005
    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???????

  3. #3
    Join Date
    Oct 2002
    Baghdad, Iraq
    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:

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

    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('', '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.

  4. #4
    Join Date
    Jul 2008
    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.
    Last edited by Mitexi; 07-15-08 at 04:37.

  5. #5
    Join Date
    Dec 2008
    For this problem visit this link. Hope this is useful for you..
    DB2 Universal Database

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts