C API Function for count(*)
C API Function for count(*)
am 15.05.2010 05:39:22 von Tim Johnson
I have MySQL version 5.0.84 on linux slackware 13.0 32-bit.
I am working with a relatively new API written in a programming
language with a small user base (newlisp). The newlisp API imports a
number of C API functions from the system MySQL shared object.
If I were to issue a count(*) query from my monitor
interface:
Example:
mysql> select count(*) from clients;
+----------+
| count(*) |
+----------+
| 16 |
+----------+
If "select count(*) from clients" is issued from the newlisp API, is
there a a C API function that would return '16'?
I have reviewed
http://dev.mysql.com/doc/refman/5.1/en/c-api-functions.html
and haven't been enlightened so far.
I believe that I could parse the results as a string, but
if I could access count(*) as a C function, it would be
more efficient.
I have a background in C.
thanks
--
Tim
tim at johnsons-web.com or akwebsoft.com
http://www.akwebsoft.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org
Re: C API Function for count(*)
am 15.05.2010 06:35:33 von Dan Nelson
In the last episode (May 14), Tim Johnson said:
> I have MySQL version 5.0.84 on linux slackware 13.0 32-bit.
>
> I am working with a relatively new API written in a programming language
> with a small user base (newlisp). The newlisp API imports a number of C
> API functions from the system MySQL shared object.
>
> If I were to issue a count(*) query from my monitor interface:
> Example:
> mysql> select count(*) from clients;
> +----------+
> | count(*) |
> +----------+
> | 16 |
> +----------+
>
> If "select count(*) from clients" is issued from the newlisp API, is
> there a a C API function that would return '16'?
You can't do it with one function call, but you can do it, since the MySQL
cli was able to print "16" in your example above, and it was written in C.
Take a look at mysql_store_result(), mysql_num_fields(),
mysql_field_count(), mysql_fetch_row(), and mysql_fetch_lengths(). There's
a simple code fragment to print a resultset on this page:
http://dev.mysql.com/doc/refman/5.1/en/mysql-fetch-row.html
--
Dan Nelson
dnelson@allantgroup.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org
Re: C API Function for count(*)
am 15.05.2010 16:40:08 von Bob Cole
You might get closer to what you want if you put your command in a text =
file and run it from the command line.
On a Mac OS X, I put a similar command:
select count(*) from testTable;
into a small text file:=20
testCount.txt
and ran this command from the Terminal:
mysql -u username -ppassword < =
/Users/myname/Documents/testCount.txt
The result was:
COUNT(*)
12
without the decorations.
Bob
On May 14, 2010, at 11:35 PM, Dan Nelson wrote:
> In the last episode (May 14), Tim Johnson said:
>> I have MySQL version 5.0.84 on linux slackware 13.0 32-bit. =20
>>=20
>> I am working with a relatively new API written in a programming =
language
>> with a small user base (newlisp). The newlisp API imports a number =
of C
>> API functions from the system MySQL shared object.
>>=20
>> If I were to issue a count(*) query from my monitor interface:
>> Example:
>> mysql> select count(*) from clients;
>> +----------+
>> | count(*) |
>> +----------+
>> | 16 |
>> +----------+
>>=20
>> If "select count(*) from clients" is issued from the newlisp API, is
>> there a a C API function that would return '16'?
>=20
> You can't do it with one function call, but you can do it, since the =
MySQL
> cli was able to print "16" in your example above, and it was written =
in C.=20
> Take a look at mysql_store_result(), mysql_num_fields(),
> mysql_field_count(), mysql_fetch_row(), and mysql_fetch_lengths(). =
There's
> a simple code fragment to print a resultset on this page:
>=20
> http://dev.mysql.com/doc/refman/5.1/en/mysql-fetch-row.html
>=20
> --=20
> Dan Nelson
> dnelson@allantgroup.com
>=20
> --=20
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: =
http://lists.mysql.com/mysql?unsub=3Dbobcole@earthlink.net
>=20
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql-2@m.gmane.o rg
Re: C API Function for count(*)
am 15.05.2010 17:01:35 von Tim Johnson
* Dan Nelson [100514 21:38]:
>
> You can't do it with one function call, but you can do it, since the MySQL
> cli was able to print "16" in your example above, and it was written in C.
> Take a look at mysql_store_result(), mysql_num_fields(),
> mysql_field_count(), mysql_fetch_row(), and mysql_fetch_lengths(). There's
> a simple code fragment to print a resultset on this page:
>
> http://dev.mysql.com/doc/refman/5.1/en/mysql-fetch-row.html
Thanks Dan. I can use the C code there to model the
code for the API.
cheers
--
Tim
tim at johnsons-web.com or akwebsoft.com
http://www.akwebsoft.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org
Re: C API Function for count(*)
am 15.05.2010 17:04:43 von Tim Johnson
* Bob Cole [100515 06:58]:
> You might get closer to what you want if you put your command in a text file and run it from the command line.
> On a Mac OS X, I put a similar command:
> select count(*) from testTable;
> into a small text file:
> testCount.txt
> and ran this command from the Terminal:
> mysql -u username -ppassword < /Users/myname/Documents/testCount.txt
> The result was:
> COUNT(*)
> 12
Hi Bob:
That's a good trick. It doesn't "fit" the API that I am trying to
enhance, but it could be a good workaround by 'echo'ing to
a tmpfile.
Thanks.
--
Tim
tim at johnsons-web.com or akwebsoft.com
http://www.akwebsoft.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org