Re: Simple C API question
Thanks for the response..it was helpful. The information I was missing was that numeric values appear in MYSQL_ROW arrays as null-terminated strings, not as binary data. Travis On 2003.02.26 00:58 Bernhard Döbler wrote: > Hi Travis, > > so far I see, you cannot simply interpret 'length' as the length in bytes > of the corresponding "byte string" in the MYSQL_ROW. > Think of the Type VARCHAR. > The length member of the FIELD tells you the maximum, the row gives you > the string in the actual length. > So far I know the Strings in the ROW are zero-terminated so you can use > it with ease and the regular C-character-functions. > > http://www.mysql.com/doc/en/mysql_fetch_row.html > > Regards > Bernhard > > - Original Message - > From: "Travis McLeskey" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Tuesday, February 25, 2003 10:04 PM > Subject: Simple C API question > > > > > > Question: Can I reliably interpret 'length' as the length in bytes of the > > corresponding "byte string" in the MYSQL_ROW, and is there a usual way to > > extract these data into regular C datatypes? > > > > - 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: Re: Simple C API question
This mail is a repost using words like: > sql,query,queries,smallint > I have written the following: > > Hi, > > I experience it on some list! > The problem is, someone posts a questions I cannot answer but I'm = > interested in a solution. I never get it because the questioner gets the = > answers via private mail. > > Bernhard > > - Original Message -=20 > From: "Andrew" <[EMAIL PROTECTED]> > To: "Bernhard D=F6bler" <[EMAIL PROTECTED]> > Sent: Wednesday, February 26, 2003 10:21 AM > Subject: RE: Simple C API question > > > > because you are the sender! Not the list also not everyone wants to = > see the > > replies to every message can you image the traffic and and ... the = > emaisl you > > would receive if you saw all the replies to every thread as some lists = > tend to > > be. > >=20 > >=20 > > >-Original Message----- > > >From: Bernhard D=F6bler [mailto:[EMAIL PROTECTED] > > >Sent: 26 February 2003 09:00 > > >To: [EMAIL PROTECTED] > > >Subject: Fw: Simple C API question > > > > > > > > >Why is the standard-receiver of a reply to the list, the original > > >poster, not the list itself? > > > > - 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
Fw: Simple C API question
Why is the standard-receiver of a reply to the list, the original poster, not the list itself? - Original Message - From: "Bernhard Döbler" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, February 26, 2003 9:58 AM Subject: Re: Simple C API question Hi Travis, so far I see, you cannot simply interpret 'length' as the length in bytes of the corresponding "byte string" in the MYSQL_ROW. Think of the Type VARCHAR. The length member of the FIELD tells you the maximum, the row gives you the string in the actual length. So far I know the Strings in the ROW are zero-terminated so you can use it with ease and the regular C-character-functions. http://www.mysql.com/doc/en/mysql_fetch_row.html Regards Bernhard - Original Message - From: "Travis McLeskey" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, February 25, 2003 10:04 PM Subject: Simple C API question > > Question: Can I reliably interpret 'length' as the length in bytes of the > corresponding "byte string" in the MYSQL_ROW, and is there a usual way to > extract these data into regular C datatypes? > - 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
Simple C API question
Maybe this is a stupid question but I couldn't find suitable sample code or an answer in the manual. mysql_fetch_row() returns a MYSQL_ROW representation of a row of data. According to the manual, this is "an array of counted byte strings". mysql_fetch_field() returns a MYSQL_FIELD with members 'type' and 'length', where 'length' is "the width of the field, as specified in the table definition". Question: Can I reliably interpret 'length' as the length in bytes of the corresponding "byte string" in the MYSQL_ROW, and is there a usual way to extract these data into regular C datatypes? Thanks, Travis - 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: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
C API Question
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 ? 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
C API Question
In the MYSQL struct in the C API, how does one access the MYSQL_FIELD data? for example, and MYSQL struct has MYSQL_FIELD *fields; as a member variable. However, when I try to access any of the variables within fields for example, mysql.fields[0].name, I get a segmentation fault. Does anyone know what I am doing wrong? Andrew - 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
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
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
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
RE: Programming with C API question
Hi, all MySQL team Thanks for your former help. Here is another question: As MySQL support multiple instances, each instance will run with different socket file and tcp/unix port number. I want to know when using MySQL client programs like mysqladmin to connect different instances, are both socket file and port number parameter necessary(without any Option file)? For example: we have 2 instances running on one machine Instance "West" runs with /var/lib/mysql/west.sock and port: 3307 Instance "East" runs with /var/lib/mysql/east.sock and port: 3308 So if we want to connect to instance "East" using mysqladmin, is following safety enough (not specify port number)? /usr/bin/mysqladmin -u root -p -S /var/lib/mysql/east.sock status In addition, how about with C API like "mysql_real_connect()"? Thanks for your help and best wishes Robert Li Computer Associates R&D Centre Beijing , China Tel:+86 10 6561 1136 ext 852 (O) +86 10 6731 1652 (H) Fax:+86 10 8529 8979 E-mail: [EMAIL PROTECTED] - 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: Programming with C API question
Li, Robert writes: > Hi, > I am a programmer. Now i want to know how to know > whether MySQL server is down or not through C API. > For me, i know if we use mysql_real_connect() to > connect MySQL server, when error returns we can not > distinguish it's due to authentation error or mysql server down. > Can we use mysql_error() after mysql_real_connect? > But what's the error code for mysql server down or > authentation error. > Thanks and regards. > Robert Li > Computer Associates > Programmer, R&D Beijing (China) > tel: +86 10 65611136 ext 852 > fax: +86 10 85298979 > [EMAIL PROTECTED] > Hi! You can try using our C API function mysql_ping(). Here is a description: int mysql_ping(MYSQL *mysql)' Description ... Checks whether or not the connection to the server is working. If it has gone down, an automatic reconnection is attempted. This function can be used by clients that remain idle for a long while, to check whether or not the server has closed the connection and reconnect if necessary. Return Values . Zero if the server is alive. Non-zero if an error occurred. Errors .. `CR_COMMANDS_OUT_OF_SYNC' Commands were executed in an improper order. `CR_SERVER_GONE_ERROR' The *MySQL* server has gone away. `CR_UNKNOWN_ERROR' An unknown error occurred. Would you be so nice to tell us what is Computer Associates of China using MySQL for ?? -- Regards, __ ___ ___ __ / |/ /_ __/ __/ __ \/ /Mr. Sinisa Milivojevic <[EMAIL PROTECTED]> / /|_/ / // /\ \/ /_/ / /__ MySQL AB, FullTime Developer /_/ /_/\_, /___/\___\_\___/ Larnaca, Cyprus <___/ www.mysql.com - 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
Programming with C API question
Hi, I am a programmer. Now i want to know how to know whether MySQL server is down or not through C API. For me, i know if we use mysql_real_connect() to connect MySQL server, when error returns we can not distinguish it's due to authentation error or mysql server down. Can we use mysql_error() after mysql_real_connect? But what's the error code for mysql server down or authentation error. Thanks and regards. Robert Li Computer Associates Programmer, R&D Beijing (China) tel: +86 10 65611136 ext 852 fax: +86 10 85298979 [EMAIL PROTECTED] - 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: Quick C API question
Evan James Dembskey wrote: > > Hi, > > I have this statement: > > res = mysql_query(&my_connection, "SELECT * FROM student WHERE studnum = > 31665222"); > for example something like this: char query[96]="SELECT * FROM student WHERE studnum="; int studnum; studnum=get_studnum(); sprintf(&query[36],"%d",studnum); res=mysql_query(&my_con,query); - 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
Quick C API question
Hi, I have this statement: res = mysql_query(&my_connection, "SELECT * FROM student WHERE studnum = 31665222"); How do I change this so that I can use a variable instead of an explicitly coded studnum? Regards, Evan - 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
C API question
Hi, If this is not the appropriate list for this question, please accept my apolgies and kindly direct me to the correct list. I have attempted to install MySQL under CLOS 1.2 (Corel Linux), using the instructions found in Howard Schultens' "MySQL for dummies - part 1". I have worked through W.J. Gilmore's tutorial on DevShed.com, and I would like to now experiment using gcc. I have looked at the MySQL manual, but I must admit that it is over my head at this point. What I need is a tutorial for a complete beginner to using MySQL(SQL) in a C environment. Barring that, a few example apps, showing how to add, delete and query MySQL would be perfect. At this point, I don't even know which library files to use. Regards, Evan - 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