[ruby-gnome2-doc-cvs] [Hiki] create - tut-libgda-exec-queries

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2003年 9月 22日 (月) 06:02:14 JST


-------------------------
REMOTE_ADDR = 217.117.55.140
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/?tut-libgda-exec-queries
-------------------------
= Making queries

== Making 'non' queries

Non queries are queries that does not return data, only the number of rows affected, as a DELETE or an UPDATE. 

We use Gda::Connection#execute_non_query to make this kind of queries:

  def execute_sql_non_query(conn, text)
      command = Gda::Command.new(text, Gda::Command::TYPE_SQL, Gda::Command::STOP_ON_ERRORS)
      conn.execute_non_query(command)
  end

Gda::Connection#execute_non_query returns the number of affected rows by the executed command, or -1 on error.

== Making normal queries

Normal queries are queries that return data (data models). You have two ways to do this:

:Gda::Connection#execute_single_command
 Use this method when you want to invoke only a single command.  This is the recommended way.

 This method returns a reference to a Gda::DataModel object. 
:Gda::Connection#execute_command
 Use this method when you want to invoke several comma-separated sentences, embedded in a single Gda::Command object.

 This method returns an array of Gda::DataModel objects.

Here you see an example:

  def execute_sql_command(conn, text)
      command = Gda::Command.new(text, Gda::Command::TYPE_SQL, Gda::Command::STOP_ON_ERRORS)
      array = conn.execute_command(command)
      array.each { |datamodel| show_table(datamodel) }
  end






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