On Wednesday, April 25, 2018 at 2:39:23 AM UTC-7, Dragutin Cvetkovic wrote:
>
> Hi all,
>
> I am pretty new to Sequel and Ruby in general, so I apologize if the 
> questions I ask are a bit repetitive and reek of newbiness:
>
> Consider the following code:
>
> begin
>
> dbh = Sequel.connect('oracle://user:password@hostname:port/databasename')
>
> sql = <<- SQL
> MERGE INTO
> smthsmth
> blabla
> SQL
>
> dbh.run(sql)
>
> rescue Sequel::DatabaseError => e
>
> puts e.err
> puts e.errstr
>
> ensure
>
> dbh.disconnect if dbh
>
> end
>
>
> 1) Is there a Sequel method/way/solution/the-usual-way-it-is-done which 
> will tell me how long a certain SQL request (dbh.run(sql) was running for?
>

If you add a database logger (:logger option), the timing information for 
each query is shown in the log.
 

> 2) would the above usage of rescue Sequel:DatabaseError be correct?
>

The rescue is fine, but e.err and e.errstr are not as those are not 
supported methods.

If you want to ensure a disconnect after you finish using the database, 
then you should do:

begin
  Sequel.connect('oracle://user:password@hostname:port/databasename') do 
|dbh|
    sql = <<- SQL
MERGE INTO
smthsmth
blabla
SQL

    dbh.run(sql)
  end
rescue Sequel::DatabaseError => e
  # ...
end

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to