need help with "module" and variable

K

keinlezard

hello



My problem is

I have this code in a file

module DB_parc
Toto=2
def DB_parc::session()
begin
dbh = DBI.connect(CONF_parc::Db,CONF_parc::User,CONF_parc::password);
#backend = Backend.new(dbh)
#yield(backend)
# yield :provoque l'execution de la variable passée en parametre
yield(dbh)
rescue DBI::Error => e
puts "#{e.errstr}"
ensure
dbh.disconnect if dbh
end
end
end


And in another file I have something like
DB_parc.session{|dbh|
schema="sparc"

I try to get the dbh handler because I need to write a function that use
it ... may be I'm wrong and it exits another way to do this

My funtion is something like that


def List(some parameters)
query_tab_mater="select id, label from sparc.type_materiel order by
label asc"
sth=dbh.execute(query_tab_mater)
sth.fetch{|k,v|
output+="<option value='#{v}'"
type_materiel = 'non-connu'
if v == type_materiel
output+= " selected='selected'"
end
output+= ">#{v}</option>"
}
output+= "</select></td></tr> "
end



but at excecution time ruby complain about dbh not known

can somebody help me and explain it


thank you
 
K

keinlezard

Le 17/05/2011 23:57, 7stud -- a écrit :
Don't use global variables--ever.

I understand that ... what I want to know...

Is how make that without this damned global variables ....


It seems to me that my code do not use global variable ...



I meet this kid of problem when I try to write


query_tab_propriet="select id, label from sparc.proprietaire order by label asc"
sth=dbh.execute(query_tab_propriet)
def funct(sth)
sth.fetch{|k,v|
output="<option value='#{v}'"
label_proprietaire = 'non-defini'
if v == label_proprietaire
output+= " selected='selected'"
end
output+= ">#{v}</option>"
}
end

output+=funct(sth)


to replace
query_tab_propriet="select id, label from sparc.proprietaire order by label asc"
sth=dbh.execute(query_tab_propriet)
sth.fetch{|k,v|
output+="<option value='#{v}'"
label_proprietaire = 'non-defini'
if v == label_proprietaire
output+= " selected='selected'"
end
output+= ">#{v}</option>"
}


I know that an horrible code ... in fact that is just another test ...
that produce same problem than my other chunk of code ...
 
7

7stud --

keinlezard wrote in post #999948:
Le 17/05/2011 23:57, 7stud -- a =C3=A9crit :

I understand that ... what I want to know...

You posted no code in your first post, and you posted no code in your =

next post. So no one has any idea what your questions is or what you are =

talking about.

-- =

Posted via http://www.ruby-forum.com/.=
 
G

Gary Wright

=20
And in another file I have something like
=20
=20
I try to get the dbh handler because I need to write a function that =
use it ... may be I'm wrong and it exits another way to do this
=20
My funtion is something like that
=20
=20
def List(some parameters)
query_tab_mater=3D"select id, label from sparc.type_materiel order = by label asc"
sth=3Ddbh.execute(query_tab_mater)
sth.fetch{|k,v|
output+=3D"<option value=3D'#{v}'"
type_materiel =3D 'non-connu'
if v =3D=3D type_materiel
output+=3D " selected=3D'selected'"
end
output+=3D ">#{v}</option>"
}
output+=3D "</select></td></tr> "
end


make sure your definition of List includes a parameter for the dbh =
handle:

def List(dbh, other, parameters)
# stuff
end

Now use something like this:

DB_parc.session { |dbh|
schema=3D"sparc"
List(dbh, schema, other, stuff)
}


Gary Wright
 
K

keinlezard

Le 20/05/2011 22:35, 7stud -- a écrit :
keinlezard wrote in post #999948:

You posted no code in your first post, and you posted no code in your
next post. So no one has any idea what your questions is or what you are
talking about.


That is curious .. because ... I post with code ...
Problem with your provider / News reader / or something else ... I
suppose ...

greetings
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top