Re: Programmers toolkit - C api sprintf-like mysql_query()
Date: Thu, 6 Jul 2017 10:51:22 -0500
Message-ID: <slrnolsn3q.4ah.hellsop_at_nibelheim.ninehells.com>
[Quoted] On Wed, 05 Jul 2017 17:02:45 -0400, Lew Pitcher wrote:
> mysql_stmt_init()
> mysql_stmt_prepare()
> mysql_stmt_bind() for my selection value
[Quoted] mysql_stmt_bind_param()
> mysql_stmt_execute()
> mysql_stmt__bind() for my returned data
[Quoted] mysql_stmt_bind_result()
> mysql_fetch()
>
> I have an additional question: for the returned data mysql_stmt_bind(), what
> buffer_type do I use for an SQL COUNT() value? The manual(s) don't say.
[Quoted] I'm as familiar with the C API as I'd like to be, but I THINK you can get that by storing your result and then fetching the field and looking in the MYSQL_FIELD structure.
Doing it via sql gets the following:
mysql> select *,count(*) from TableName1 group by id ;
+----+------------+----------+
| id | loyalty_id | count(*) |
+----+------------+----------+
| 1 | 1 | 1 | | 2 | 2 | 1 | | 3 | 3 | 1 | | 4 | 4 | 1 | | 5 | 5 | 1 | | 6 | 5 | 1 | | 7 | 5 | 1 | | 8 | 1 | 1 | | 9 | 3 | 1 | | 10 | 1 | 1 |
+----+------------+----------+
10 rows in set (0.00 sec)
mysql> create table layouttest select *,count(*) from TableName1 group
by id ;
Query OK, 10 rows affected (0.01 sec)
Records: 10 Duplicates: 0 Warnings: 0
mysql> describe layouttest ;
+------------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------+------+-----+---------+-------+
| id | int(11) | NO | | 0 | | | loyalty_id | int(11) | NO | | NULL | | [Quoted] | count(*) | bigint(21) | NO | | 0 | |+------------+------------+------+-----+---------+-------+ 3 rows in set (0.01 sec)
-- 97. My dungeon cells will not be furnished with objects that contain reflective surfaces or anything that can be unravelled. --Peter Anspach's list of things to do as an Evil OverlordReceived on Thu Jul 06 2017 - 17:51:22 CEST