[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Help with the mysql egg
From: |
Kon Lovett |
Subject: |
Re: [Chicken-users] Help with the mysql egg |
Date: |
Tue, 22 Jan 2008 12:19:34 -0800 |
On Jan 22, 2008, at 6:42 AM, Jean-Philippe Theberge wrote:
Hi,
I am having some trouble with the mysql egg mostly die to my
misunderstanding of c-pointers
With the egg you get data either by index or by name. What I would
like is more something like this example from the mysql-api
documentation
unsigned int num_fields;
unsigned int i;
MYSQL_FIELD *fields;
num_fields = mysql_num_fields(result);
fields = mysql_fetch_fields(result);
for(i = 0; i < num_fields; i++)
{
printf("Field %u is %s\n", i, fields[i].name);
}
The egg provide the foreign-mysql-fetch-fields. it return a
#<pointer> object
How can I extract the name from this object in scheme? I want to
do what "fields[i].name" do in the example above?
Thanks
I have never used the mysql egg so keep that in mind.
(define conn (mysql-connect ...))
;; (mysql-fetch-field-list DB) -> LIST | BOOLEAN
;; Returns a list of field names for the current connection result, or
;; #f when no result.
(define mysql-fetch-field-list
(let ([get-field-name
(foreign-lambda* c-string ([c-pointer fields] [unsigned-
integer idx])
"return (((MYSQL_FIELD *)fields)[idx].name);")])
(lambda (conn)
(and-let* ([res (mysql-connection-result conn)])
(let ([fields (foreign-mysql-fetch-fields res)])
(let loop ([count (foreign-mysql-num-fields res)] [names
'()])
(if (zero? count)
names
(let ([nxtcnt (sub1 count)])
(loop nxtcnt (cons (get-field-name fields nxtcnt)
names)) ) ) ) ) ) ) ) )
HTH
--
BuddyPilots <http://www.buddypilots.com>
*Jean-Philippe Théberge*
*Programmeur Architecte*
Tel: (514) 353-2307
_______________________________________________
Chicken-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/chicken-users
Best Wishes,
Kon