lib/conn_exec.c
/*
 * call-seq:
 *    conn.putline( str)         -> nil
 *    conn.putline( ary)         -> nil
 *    conn.putline( str) { ... } -> nil
 *
 * Sends the string to the backend server.
 * You have to open the stream with a +COPY+ command using +copy_stdin+.
 *
 * If +str+ doesn't end in a newline, one is appended.  If the argument
 * is +ary+, a line will be built using +stringize_line+.
 *
 * If the connection is in nonblocking mode and no data could be sent
 * the closure will be called and its value will be returned.
 */


Sends the string to the backend server.
You have to open the stream with a +COPY+ command using +copy_stdin+.

If +str+ doesn't end in a newline, one is appended.  If the argument
is +ary+, a line will be built using +stringize_line+.

If the connection is in nonblocking mode and no data could be sent
the closure will be called and its value will be returned.
Sends the string to the backend server . You have to open the stream with a + COPY + command using + copy_stdin + . If + str + doesn ' t end in a newline one is appended . If the argument is + ary + a line will be built using + stringize_line + . If the connection is in nonblocking mode and no data could be sent the closure will be called and its value will be returned .
VALUE
pgconn_putline( VALUE self, VALUE arg)
{
    struct pgconn_data *c;
    VALUE str;
    const char *p;
    int l;
    int r;
    switch (TYPE( arg)) {
    case T_STRING:
        str = arg;
        break;
    case T_ARRAY:
        str = pgconn_stringize_line( self, arg);
        break;
    default:
        str = rb_obj_as_string( arg);
        break;
    }
    if (RSTRING_PTR( str)[ RSTRING_LEN( str) - 1] != '\n') {
        VALUE t;
        t = rb_str_dup( str);
        rb_str_buf_cat( t, "\n", 1);
        str = t;
    }
    c = get_pgconn( self);
    p = pgconn_destring( c, str, &l);
    r = PQputCopyData( c->conn, p, l);
    if (r < 0)
        rb_raise( rb_ePgConnCopy, "Copy from stdin failed.");
    else if (r == 0)
        return rb_yield( Qnil);
    return Qnil;
}
VALUE pgconn_putline ( VALUE self , VALUE arg ) { struct pgconn_data * c ; VALUE str ; const char * p ; int l ; int r ; switch ( TYPE ( arg ) ) { case T_STRING : str = arg ; break ; case T_ARRAY : str = pgconn_stringize_line ( self , arg ) ; break ; default : str = rb_obj_as_string ( arg ) ; break ; } if ( RSTRING_PTR ( str ) [ RSTRING_LEN ( str ) - 1 ] != ' \n ' ) { VALUE t ; t = rb_str_dup ( str ) ; rb_str_buf_cat ( t , " \n " , 1 ) ; str = t ; } c = get_pgconn ( self ) ; p = pgconn_destring ( c , str , & l ) ; r = PQputCopyData ( c -> conn , p , l ) ; if ( r < 0 ) rb_raise ( rb_ePgConnCopy , " " ) ; else if ( r == 0 ) return rb_yield ( Qnil ) ; return Qnil ; }
call-seq:
    conn.putline( str)         -> nil
    conn.putline( ary)         -> nil
    conn.putline( str) { ... } -> nil
call - seq : conn . putline ( str ) - > nil conn . putline ( ary ) - > nil conn . putline ( str ) { ... } - > nil