1. Michael Granger
  2. ruby-pg

Commits

Lars Kanis  committed 9959003

Add usage examples for put_copy_data and get_copy_data.

  • Participants
  • Parent commits 6d3d184
  • Branches default

Comments (0)

Files changed (1)

File ext/pg_connection.c

View file
  * is in nonblocking mode, and this command would block).
  *
  * Raises an exception if an error occurs.
+ *
+ * Example with CSV format and blocking mode:
+ *   conn.exec( "COPY my_table FROM STDIN CSV" )
+ *   begin
+ *     conn.put_copy_data "some,csv,data,to,copy\n"
+ *     conn.put_copy_data "more,csv,data,to,copy\n"
+ *   rescue => err
+ *     errmsg = "%s while copy data: %s" % [ err.class.name, err.message ]
+ *     conn.put_copy_end( errmsg )
+ *     conn.get_result
+ *     raise
+ *   else
+ *     conn.put_copy_end
+ *     res = conn.get_result
+ *     raise res.result_error_message if res.result_status!=PG::PGRES_COMMAND_OK
+ *   end
+ *
  */
 static VALUE
 pgconn_put_copy_data(self, buffer)
  * if the copy is done, or +false+ if the call would
  * block (only possible if _async_ is true).
  *
+ * Example with CSV format and blocking mode:
+ *   conn.exec( "COPY my_table TO STDIN CSV" )
+ *   begin
+ *     while row=conn.get_copy_data
+ *       # do something with the CSV row
+ *     end
+ *   rescue => err
+ *     conn.cancel
+ *     while conn.get_copy_data
+ *     end
+ *     conn.get_result
+ *     raise
+ *   else
+ *     res = conn.get_result
+ *     raise res.result_error_message if res.result_status!=PG::PGRES_COMMAND_OK
+ *   end
+ *
  */
 static VALUE
 pgconn_get_copy_data(int argc, VALUE *argv, VALUE self )