Re: how can I use 'C' programs accessing a MySql

2002-03-06 Thread Thomas Spahni

On Tue, 5 Mar 2002 [EMAIL PROTECTED] wrote:

 I'm trying to understand how can I use 'C' programs accessing a MySql
 DataBase, please, could you send me a small program or so that creates
 a Table or two and make some changes on them.  I read so many examples
 but all of them only contain parts of the code.  please... help...what
 library I must include...

Alexandre

there was an example on this list quite recently. It was a complete piece
of code showing how to insert image files into blob columns. This will get
you started.

Thomas


  quote
From: paradoxix [EMAIL PROTECTED]

#include stdio.h
#include stdlib.h
#include unistd.h
#include fcntl.h
#include sys/fcntl.h

#include mysql/mysql.h

MYSQL dbcon;

int main(int argc, char *argv[])
{
  int i;
  char *tmpQ=malloc(2*1024*1024);
  char *end;
  int file;
  int size;
  char *mem;
  char tmpstr[1024];

  mysql_init(dbcon);

  mysql_real_connect(dbcon, NULL, username, password,
 dbname,0,/tmp/mysql.sock,0);

  for(i=1;iargc;i++) {
file = open(argv[i], O_RDONLY);
lseek(file, 0, SEEK_SET);
size = lseek(file, 0, SEEK_END);
lseek(file, 0, SEEK_SET);

mem = malloc(size);
read(file,mem,size);

printf(inserting: %s\n,argv[i]);


end = (char *) strmov(tmpQ,INSERT INTO image values();
*end++ = '\'';
sprintf(tmpstr,%i,i);
end = strmov(end, tmpstr);
*end++ = '\'';
*end++ = ',';
*end++ = '\'';
sprintf(tmpstr,%i,i);
end = strmov(end, tmpstr);
*end++ = '\'';
*end++ = ',';
*end++ = '\'';
end += mysql_escape_string(end, mem, size);
*end++ = '\'';
*end++ = ')';

mysql_real_query(dbcon, tmpQ, (unsigned int) (end - tmpQ));
free(mem);
close(file);
  }
  mysql_close(dbcon);
  exit(0);
  return 0;
}


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




how can I use 'C' programs accessing a MySql

2002-03-05 Thread ale

The following form was submitted via MySQL.com feedback engine: 
  Name: Alexandre Adam
  E-mail address: [EMAIL PROTECTED]
  Company: sansoft informatica
  Position/Title: user
  Type of interest: for personal use
  State or province: SP
  Country: Brazil
  Support contract: no

  Enter Your Questions, Comments, Feedback or Your Message here:


I'm trying to understand how can I use 'C' programs accessing a MySql

DataBase, please, could you send me a small program or so that creates
a 
Table or two and make some changes on them. 
I read so many examples but all of them only contain parts of the
code.
please... help...what library I must include... 

Sincerely
Alexandre Adam
Sao Paulo - SP - BRAZIL

I wrote some code but nothing works... please read it below.

#include /usr/include/mysql/mysql.h
# include stream.h

int main () {  
{ Printf (Initializing...\n); }
if (mysql_create_db (mysql, DB_TEST)) {
fprintf (stderr, Failed to create DataBase, ERR!
%x\n, mysql_error( 
mysql));
}
return 0;
}
   

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




RE: how can I use 'C' programs accessing a MySql

2002-03-05 Thread Kenneth Hylton


The best book for c programming I found is the O'Reilly book, MySQL  mSQL
.  It has a good example of using the C API and even builds some simple C++
classes.

The book, MySQL by Paul DuBois is the best overall MySQL book I found.
Plus, Paul is a regular responder to this list, so I would buy his book,
too.

As far as creating tables (or just about anything else) the thing to
remember that about all the C API does is pass the command you want to the
SQL interpreter and then execute your command.

So, if you want to create a table, you would pass a CREATE statement into
mysql_query (or mysql_real_query) EXACTLY like you would have entered it
into the mysql client.

These is lots is some contributed software out there for the C/C++ API, but
they all have problems when it comes to inserting and updating records.  The
issues is in understanding exactly how MySQL returns stuff in the result
set.

I have attached some C++ classes (and a test program) to this document that
should get you started.  They deal with the type saftey issue, updating
different data types and different size strings, etc.

You will also need to go to boost.org and get some code to install something
called lexical_cast, too.


Zip file removed to post to list.  Email me if you want the classes



Hello MySQL employees - 

If you want to post this zip file on your contributed software section, you
have my permission to do so.  These would have saved me months of effort and
I know someone else can use them, too.


 Have A Great Scouting Day
 Ken Hylton
 7826 Falcon Ridge Drive
 San Antonio, Texas 78239-4032
 210-646-9508 (home)
 210-949-7261 (work)
 210-949-7254 (fax)
 210-287-6756 (cell)
 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] 
 [EMAIL PROTECTED]
mailto:[EMAIL PROTECTED] 


-Original Message-
From:   [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]] mailto:[mailto:[EMAIL PROTECTED]] 
Sent:   Tuesday, March 05, 2002 9:01 AM
To: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]

Subject:how can I use 'C' programs accessing a MySql

The following form was submitted via MySQL.com feedback
engine: 
  Name: Alexandre Adam
  E-mail address: [EMAIL PROTECTED]
mailto:[EMAIL PROTECTED] 
  Company: sansoft informatica
  Position/Title: user
  Type of interest: for personal use
  State or province: SP
  Country: Brazil
  Support contract: no

  Enter Your Questions, Comments, Feedback or Your Message
here:


I'm trying to understand how can I use 'C' programs
accessing a MySql

DataBase, please, could you send me a small program or
so that creates
a 
Table or two and make some changes on them. 
I read so many examples but all of them only contain
parts of the
code.
please... help...what library I must include... 

Sincerely
Alexandre Adam
Sao Paulo - SP - BRAZIL

I wrote some code but nothing works... please read it
below.

#include /usr/include/mysql/mysql.h
# include stream.h

int main () {  
{ Printf (Initializing...\n); }
if (mysql_create_db (mysql, DB_TEST)) {
fprintf (stderr, Failed to create
DataBase, ERR!
%x\n, mysql_error( 
mysql));
}
return 0;
}
   


-
Before posting, please check:
   http://www.mysql.com/manual.php
http://www.mysql.com/manual.php(the manual)
   http://lists.mysql.com/ http://lists.mysql.com/
(the list archive)

To request this thread, e-mail
[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED] 
To unsubscribe, e-mail
[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
 
Trouble unsubscribing? Try:
http://lists.mysql.com/php/unsubscribe.php
http://lists.mysql.com/php/unsubscribe.php 

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http