chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Help with the mysql egg


From: Jean-Philippe Theberge
Subject: Re: [Chicken-users] Help with the mysql egg
Date: Tue, 22 Jan 2008 17:29:25 -0500
User-agent: Mozilla-Thunderbird 2.0.0.9 (X11/20080109)

OK, I keep in mind that you can easily and succesfully modify an egg you had never used. I think this should be added to the mysql egg. I can provide a diff or add it myself to the egg if I am provided with a repository access.

Thanks a lot!

--
JP Theberge


Kon Lovett wrote:

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






--
BuddyPilots <http://www.buddypilots.com>
*Jean-Philippe Théberge*
*Programmeur Architecte*
Tel: (514) 353-2307







reply via email to

[Prev in Thread] Current Thread [Next in Thread]