Class: PG::TextEncoder::QuotedLiteral

Inherits:
CompositeEncoder show all
Defined in:
ext/pg_text_encoder.c

Overview

This is the encoder class for PostgreSQL literals.

A literal is quoted and escaped by the ' character, so that it can be inserted into SQL queries. It works equal to PG::Connection#escape_literal, but integrates into the type cast system of ruby-pg.

Both expressions have the same result:

conn.escape_literal(PG::TextEncoder::Array.new.encode(["v1","v2"])) # => "'{v1,v2}'"
PG::TextEncoder::QuotedLiteral.new(elements_type: PG::TextEncoder::Array.new).encode(["v1","v2"]) # => "'{v1,v2}'"

While escape_literal requires a intermediate ruby string allocation, QuotedLiteral encodes the values directly to the result string.

Constant Summary

Constants inherited from Coder

Coder::FORMAT_ERROR_MASK, Coder::FORMAT_ERROR_TO_PARTIAL, Coder::FORMAT_ERROR_TO_RAISE, Coder::FORMAT_ERROR_TO_STRING, Coder::TIMESTAMP_APP_LOCAL, Coder::TIMESTAMP_APP_UTC, Coder::TIMESTAMP_DB_LOCAL, Coder::TIMESTAMP_DB_UTC

Instance Attribute Summary

Attributes inherited from CompositeCoder

#elements_type

Attributes inherited from Coder

#name

Method Summary

Methods inherited from CompositeCoder

#delimiter, #delimiter=, #elements_type=, #inspect, #needs_quotation=, #needs_quotation?, #to_h

Methods inherited from Coder

#==, #dup, #flags, #flags=, #format, #format=, #initialize, #inspect, #inspect_short, #marshal_dump, #marshal_load, #oid, #oid=, #to_h

Constructor Details

This class inherits a constructor from PG::Coder