View Single Post
  #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