Retrieving mysql columns by name
[1/4] from: didier::jacquemart::libertysurf::fr at: 7-Apr-2002 11:31
To retrieve mysql data, i wrote this program ... sqlchain: "select .... join ...." insert db sqlchain fic: copy db foreach row fic print row/1 ... Is it possible to retrieve the columns with their name ("numliv"), rather than with their order number in the row? I think about a series that would contain the names of the fields; that would then give the order number trough a function call. How can i fill in automatically this series. Does a solution already exist.
[2/4] from: bobosity:hot:mail at: 7-Apr-2002 21:22
Select * from mydb will return the columns in thier original order Try this: "select column3, column9, column2 from mydb" Substitute your column names :)
[3/4] from: g:santilli:tiscalinet:it at: 8-Apr-2002 10:15
Hi Didier, On Sunday, April 07, 2002, 11:31:36 AM, you wrote: DJ> Is it possible to retrieve the columns with their name ("numliv"), rather than with their order number in the row? Are you using Command or Nenad's protocol? Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r
[4/4] from: didier:jacquemart:libertysurf at: 8-Apr-2002 23:08
Thank you for answering my question. Here's another one. --------------------------------------------- I wrote this program : ;; this is the list of columns in my Mysql request zlistechamps: copy [ "livnum" "livtit" "livaut" "livcat" "livdif" "autnum" autabr "autcom" ] getcol: func [ prow 'pnom ] ; prow is the row i get from mysql request ; pnom is the name of the field i want to retrieve [ use [ xind ] [ xind: index? find zlistechamps pnom pick prow xind ] ] I then get my values by : print getcol row "livnum" print getcol row "livtit" print getcol row "autcom" which is equivalent to print row/1 print row/2 print row/8 This way seems to me much more easy and self-explaining than using order numbers. It has the advantage to be request independent. Last problem to solve : How can i automatically create the list of fields in zlistechamps; can i retrieve the columns names from mysql, in a manner like show columns from table . The difference is that the sql request is not upon a table but is a join request. Further, I think the ultimate goal would be object oriented programming, something that could look like this : rq: open_request("select .....") rq/next x: rq/fields "livnum" ... It's just an idea from a newbie in Rebol (i don't even know if the syntax is correct); perhaps does this already exist ? Thank you.