Hi Sushil!

I think you need to prepare the query, execute it, and then fetch the
result.  I've created a method to do this:

def getDBValue(connection, query, id1, *id2)
    dbi_query = connection.prepare(query)
    dbi_query.execute(id1, *id2)
    #fetch the result
    return dbi_query.fetch
end

Using this method, you can get the value you're looking for like this:

result = getDBValue(test_db, 'select ObjectId from testTable where
Name like ?', 'test')

The *id2 values are optional.

If you're expecting more than one value, you can use a method similar
to the one above:

def getDBArray(connection, query, id1, *id2)
    dbi_query = connection.prepare(query)
    dbi_query.execute(id1, *id2)
    #fetch the result
    return dbi_query.fetch_all
end

I hope this helps!

-Tiffany


On Feb 17, 3:38 am, SushilKarwa <sushil.ka...@gmail.com> wrote:
> Hi All,
>    Am trying to execute a sql query and looking for the value it
> returned. What am trying to do is in a particular table am looking for
> a particular value in a field. I want to fetch this value. Am trying
> the following but stuck at point on how to use that value.
>
> def dbconnect(Server)
>    connectstring = "DBI:ODBC:#{server}"
>    db = DBI.connect(connectstring, username, password)
>    return db
> end
>
> test_db=dbconnect(SQLServer)
> result=test_db.select_all("select ObjectID from testTable where Name
> like 'test' ")
>
> It returns me something like this:
> [[221]]:Array
>
> I need to fetch that 221 which is the objectID iam interested in.
>
> Please help me on how to get that value.
>
> ~Sushil
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---

Reply via email to