Re: C API Question
At 11:13 -0600 2/19/03, Paul DuBois wrote: At 10:57 -0600 2/19/03, William R. Mattil wrote: Hello, I am having some cockpit trouble with the following MYSQL_RES *mysql_list_fields(MYSQL *mysql, const char *table, const char *wild); and it is like lack of understanding on my part. Syntax is: if (mysql_list_fields( &mysql, "some table name", "some field name")) mysql_store_result and mysql_fetch_row follow but nothing is ever returned. If I replace the mysql_list_fields with: if (mysql_query(&mysql,"Describe some_table_name")) everything works. Where am I missing the boat here ? Nothing. It's just that the documentation for this function is unclear/ incorrect. I just came to realize this myself a few weeks ago. :-( The information that mysql_list_fields() returns about the columns is returned in the result set *metadata*. So what you should do is call mysql_fetch_field() to retrieve the metadata for each column of the result set. Note that the max_length value will always be zero. Thanks Bill -- William R. Mattil | Statisticians define a lottery as a tax Sr. System Aministrator | on not understanding mathematics (972) 399-4106 | To follow up on my own posting: Here's an example. It shows how to retrieve various bits of metadata, including the column metadata. It assumes tbl_name is a string containing the table name. MYSQL_ROW row; MYSQL_FIELD *field; unsigned long *length; unsigned inti; MYSQL_RES *res_set = mysql_list_fields (conn, tbl_name, NULL); if (res_set == NULL) fprintf (stderr, "list_fields failed\n"); else { printf ("Number of columns: %d\n", mysql_num_fields (res_set)); printf ("Number of rows: %d\n", mysql_num_rows (res_set)); printf (" %-12s %-12s", "name", "table"); printf (" %-12s %3s %3s %4s %4s %s\n", "default", "len", "max", "type", "dec", "not null"); for (i = 0; i < mysql_num_fields (res_set); i++) { field = mysql_fetch_field (res_set); printf ("%2u %-12s %-12s", i, field->name, field->table ? field->table : "NULL"); printf (" %-12s %3u %3u %3u %3u %0x %3d\n", field->def ? field->def : "NULL", field->length, field->max_length, field->type, field->decimals, field->flags, IS_NOT_NULL(field->flags) ); } } mysql_free_result (res_set); - 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: C API Question
At 10:57 -0600 2/19/03, William R. Mattil wrote: Hello, I am having some cockpit trouble with the following MYSQL_RES *mysql_list_fields(MYSQL *mysql, const char *table, const char *wild); and it is like lack of understanding on my part. Syntax is: if (mysql_list_fields( &mysql, "some table name", "some field name")) mysql_store_result and mysql_fetch_row follow but nothing is ever returned. If I replace the mysql_list_fields with: if (mysql_query(&mysql,"Describe some_table_name")) everything works. Where am I missing the boat here ? Nothing. It's just that the documentation for this function is unclear/ incorrect. I just came to realize this myself a few weeks ago. :-( The information that mysql_list_fields() returns about the columns is returned in the result set *metadata*. So what you should do is call mysql_fetch_field() to retrieve the metadata for each column of the result set. Note that the max_length value will always be zero. Thanks Bill -- William R. Mattil | Statisticians define a lottery as a tax Sr. System Aministrator | on not understanding mathematics (972) 399-4106 | - 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: C API question
hi, I think u don't need to convert it in to string... all the column values comes out in string only... I have used it... Chetan Lavti -Original Message- From: Federico Halperin [mailto:[EMAIL PROTECTED]] Sent: Thursday, March 28, 2002 10:40 AM Subject: C API question In a table, I declared a column which is an integer unsigned. After calling mysql_fetch_row, I need to convert the value of the column (i.e. row[0]) to a string. I tried to solve it doing this: char var[11]; sprintf (var, "%u", row[0]); , but it doesn't work. Is *row[0] an unsigned int? Can anybody help me??? _ Con MSN Hotmail súmese al servicio de correo electrónico más grande del mundo. http://www.hotmail.com/ES - 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 - 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: C API question
hi, I think u don't need to convert it in to string... all the column values comes out in string only... or even u need to use atoi() Function for getting the Int ot unsigned int... I have used it... Chetan Lavti -Original Message- From: Federico Halperin [mailto:[EMAIL PROTECTED]] Sent: Thursday, March 28, 2002 10:40 AM Subject: C API question In a table, I declared a column which is an integer unsigned. After calling mysql_fetch_row, I need to convert the value of the column (i.e. row[0]) to a string. I tried to solve it doing this: char var[11]; sprintf (var, "%u", row[0]); , but it doesn't work. Is *row[0] an unsigned int? Can anybody help me??? _ Con MSN Hotmail súmese al servicio de correo electrónico más grande del mundo. http://www.hotmail.com/ES - 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 - 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: C API question
At 5:09 + 3/28/02, Federico Halperin wrote: >In a table, I declared a column which is an integer unsigned. > >After calling mysql_fetch_row, I need to convert the value of the >column (i.e. row[0]) to a string. According to the manual, *all* column values are returned as strings. I'd say you don't need to convert it. > >I tried to solve it doing this: > >char var[11]; >sprintf (var, "%u", row[0]); > >, but it doesn't work. > >Is *row[0] an unsigned int? > >Can anybody help me??? It's a good idea to take a good look at the descriptions of these functions (and the data types they use) in the manual to see how they work. No point in guessing. - 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: C API Question
At 11:35 + 3/20/02, Javier wrote: >Hi, > >I have a text file , with several MySQL instructions (CREATE TABLE, INSERT, >SET @var, etc.). > > I want to execute all these instructions from a C program , using the API. > >It is possible to use the function mysql_query(), to execute all the >instructions contained in the file in a single call to this function? , Can >I execute several MySQL instructions in one only call to mysql_query() >function? No. Not for the C API, or for any API. The client-server protocol requires that you issue a single query at at time. But there's nothing to stop you from writing a utility function that takes all the statements and issues them. Then you just call *that* function once. And remember that you don't include a terminating semicolon on the statements when you use an API. > >If it is possible, which is the best way to do this? > >Thanks in advance > >Javier Diaz >IT Developer - 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: C API Question
Not as far as I know, you need to open your file, read the commands and process them one at a time. The C API is not magic and has no more capability than you do setting down and typing in the commands yourself. What you can do is build one HUGE insert command from lots of individual row inserts, but you need to do that programatically, too. If you have loads of inserts to perform, it may be better to bulk load the data from a file made of the inserts' data than a record at a time if speed is an issue. I'd sure try the simple way first, though. Ken -Original Message- From: Javier [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 20, 2002 5:35 AM To: [EMAIL PROTECTED] Subject: C API Question Hi, I have a text file , with several MySQL instructions (CREATE TABLE, INSERT, SET @var, etc.). I want to execute all these instructions from a C program , using the API. It is possible to use the function mysql_query(), to execute all the instructions contained in the file in a single call to this function? , Can I execute several MySQL instructions in one only call to mysql_query() function? If it is possible, which is the best way to do this? Thanks in advance Javier Diaz IT Developer - Scanned for all known viruses by Messagelabs -- - 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 - 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