[ruby-gnome2-doc-cvs] [Hiki] update - tut-libgda-errors

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2003年 9月 29日 (月) 19:28:39 JST


-------------------------
REMOTE_ADDR = 217.117.55.140
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/?tut-libgda-errors
-------------------------
  = Managing errors
  
  You can manage errors using the Gda::Error class, and obtain objects with the method Gda::Connection#errors.
  
  A GDA error contains 4 distinct piece of information.
  
  :Gda::Error#description
   A full description of the error. 
  
  :Gda::Error#number
   Error's number.
  
  :Gda::Error#source
   Error's source.
  
  :Gda::Error#sqlstate
   SQL state.
  
  Here you can see an example of using this:
  
    def show_errors(conn)
        # Obtains errors list and loop for getting error information.
        conn.errors.each do |error|
            puts "Error no: #{error.number.to_s}"
            puts "Description: #{error.description}"
            puts "Source: #{error.source}"
            puts "SQL state: #{error.sqlstate}"
        end
    end
  
  Usually, you can check errors when Gda::Connection query methods fail.  For instance:
  
    # For Gda::Connection#execute_non_query:
    if conn.execute_non_query(cmd) == -1
        show_errors(conn)
    end
  
    # For Gda::Connection#execute_single_command:
-   ds = conn.execute_single_command(cmd)
-   if ds.nil?
+   dm = conn.execute_single_command(cmd)
+   if dm.nil?
        show_errors(conn)
    end
  
    # For Gda::Connection#execute_command:
    arr = conn.execute_command(cmd)
-   arr.each do |ds|
-       if ds.nil?
+   arr.each do |dm|
+       if dm.nil?
            show_errors(conn)
        end
    end
  
  Also, it is possible to be notified with a GLib signal when an error occurs:
  
    conn.signal_connect('error') { show_errors(conn) }





ruby-gnome2-cvs メーリングリストの案内
Back to archive index