Hi,

On 03/07/2013 03:10 AM, Nicolas wrote:
> #hosttype.rb
> 
> require "mysql"
> 
> module Puppet::Parser::Functions
> 
>     newfunction(:hosttype, :type => :rvalue, :doc => "Gets host type
> from db.") do |args|
> 
>         dbh = Mysql.real_connect("mysql_server_ip", "username",
> "password", "puppet")
> 
>         res = dbh.query("SELECT host_type FROM host_extra_info where
> name='" + args[0] + "'")
> 
> #        return res.fetch_row
> 
>         puts res.fetch_row
> 
>           res.free
> 
>          dbh.close if dbh
> 
>     end
> 
> end
> 
> 
> It becomes nil,and I just don't know why.

The way I read it, you return the value of the last statement, i.e.
dbh.close. nil sounds realistic.

Why is there a puts in the function?

Try

  result = res.fetch_row
  res.free
  dbh.close
  result
end

HTH
Felix

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to