Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1
Large/Binary Objects | 101

However, the Oracle client library still maps net service names to connection speci-
fications, so thehostparameter provides a service name rather than a physical
hostname:


development:
adapter: oci
host: ORCL
username: user
password: pass

TheORCLin the preceding configuration corresponds to an entry in theTNSNAMES.
ORAfile, which will look something like this:


ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = srv)(PORT = 1521))
)

)

Alternatively, you can provide the connection specification on one line with the Rails
database configuration:


development:
adapter: oci
host: (DESCRIPTION = (ADDRESS_LIST = (...)))
username: user
password: pass

The connection setup is the hardest part. Once the database is connected, Rails sup-
ports Oracle connections just as it does connections to any other DBMS. Stored pro-
cedures and other Oracle-specific syntax are available through the standard methods
that expose an SQL interface, such asActiveRecord::Base.find_by_sql.


Large/Binary Objects


Sooner or later, many web applications must deal with the issue of LOB (large
object) data. LOB data may be small, but it is usually large compared to other
attributes being stored (tens of kilobytes to hundreds of gigabytes or larger). The defin-
ing characteristic of LOB data, however, is that the application has no knowledge of the
semantics of the internal structure of the data.


The canonical example is image data; a web application usually has no need to know
the data in a JPEG file representing a user’s avatar as long as it can send it to the
client, replace it, and delete it when needed.


LOB storage is usually divided into CLOB (character large object) for text data and
BLOB (binary large object) for everything else. Some DBMSs separate the two as sep-
arate data types. CLOB types can often be indexed, collated, and searched; BLOBs
cannot.

Free download pdf