Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

CUBRID Perl Driver Development


DBD::cubrid - CUBRID driver for the Perl5 Database Interface (DBI)

CUBRID Perl driver are ready to be developed. The development process is divided into two stages. The first stage is to provide the minimum coverage functions to ensure that users can access the database. We will make some changes and improvement in the second stage, such as add lob operations, add interfaces that can get information about fields, etc. The following table will list the methods and attributes that will be provided.

Object Methods/Attributes Decription Phase1 Phase2
DRH Methods connect() Establishes a database connection
DBH Methods prepare() Prepares a statement for later execution by the database engine and returns a reference to a statement handle object.
commit() Commit (make permanent) the most recent series of database changes if the database supports transactions and AutoCommit is off.
rollback() Rollback (undo) the most recent series of uncommitted database changes if the database supports transactions and AutoCommit is off.
disconnect() Disconnects the database from the database handle.
ping() Check whether the database server is still running and the connection to it is still working.
last_insert_id() Returns a value identifying the row just inserted
table_info() Returns an active statement handle that can be used to fetch information about tables and views that exist in the database.
tables() Simple interface to table_info(), returns a list of matching table names
type_info_all() Returns a reference to an array which holds information about each data type variant supported by the database and driver.
type_info() Returns a list of hash references holding information about one or more variants of datatype.
column_info() Returns an active statement handle that can be used to fetch information about columns in specified tables.
primary_key_info() Returns an active statement handle that can be used to fetch information about columns that make up the primary key for a table.
primary_key() Simple interface to the primary_key_info() method. Returns a list of the column names that comprise the primary key of the specified table. The list is in primary key column sequence order.
foreign_key_info() Returns an active statement handle that can be used to fetch information about foreign keys in and/or referencing the specified table(s).
get_info() Returns information about the implementation, i.e. driver and data source capabilities, restrictions etc.
DBH Attributes AutoCommit Type: Boolean. If true, then database changes cannot be rolled-back (undone). If false, then database changes automatically occur within a "transaction", which must either be committed or rolled back using the commit or rollback methods.
Statement Type: String, read-only. Returns the statement string passed to the most recent "prepare" or "do" method called in this database handle, even if that method failed.
STH Methods bind_param() Bind a param to a placeholder embedded in the prepared statement.
bind_param_array() Bind an array of values to a placeholder embedded in the prepared statement.
execute() Perform whatever processing is necessary to execute the prepared statement.
execute_array() Execute the prepared statement once for each parameter tuple
fetchrow_arrayref() Fetches the next row of data and returns a reference to an array holding the field values.
fetchrow_array() An alternative to fetchrow_arrayref. Fetches the next row of data and returns it as a list containing the field values.
fetchrow_hashref() An alternative to fetchrow_arrayref. Fetches the next row of data and returns it as a reference to a hash containing field name and field value pairs.
fetchall_arrayref() Fetches all the data to be returned from a prepared and executed statement handle.It returns a reference to an array that contains one reference per row.
fetchall_hashref() Fetches all the data to be returned from a prepared and executed statement handle.It returns a hash containing a key for each distinct value of the column that was fetched.
Private STH methods cubrid_lob_get() This method can get a column of the lob object from CUBRID database. You need to point out which column you want to fetch as lob object and the column start with 1.
cubrid_lob_export() This method will export a lob object as a file. You must specify the row you want to fetch and the name of the file you want to export, and the row start with 1. Attention, before use this function, you need to call cubrid_lob_get first.
cubrid_lob_import This method will import a file in CUBRID database. The parameter $index is indicated to which placeholder you want to bind the file in $filename, and $type can SQL_BLOB or SQL_CLOB.
cubrid_lob_close This method will close the lob object that cubrid_lob_get gets. Once you use cubrid_lob_get, you'd better use this method when you don't use the lob object any more.
STH Attributes rows Returns the number of rows affected by the last row affecting command, or -1 if the number of rows is not known or not available.
Statement Type: String, read-only. Returns the statement string passed to the most recent "prepare" or "do" method called in this database handle, even if that method failed.
NUM_OF_FIELDS Type: integer, read-only. Number of fields (columns) in the data the prepared statement may return.
NUM_OF_PARAMS Type: integer, read-only. The number of parameters (placeholders) in the prepared statement.
NAME Type: array-ref, read-only. Returns a reference to an array of field names for each column.
TYPE Type: array-ref, read-only. Returns a reference to an array of integer values for each column. The value indicates the data type of the corresponding column.
PRECISION Type: array-ref, read-only. Returns a reference to an array of integer values for each column.
SCALE Type: array-ref, read-only. Returns a reference to an array of integer values for each column.
NULLABLE Type: array-ref, read-only. Returns a reference to an array indicating the possibility of each column returning a null.


NOTE:

  • DRH: Driver Handle
  • DBH: Database Handle
  • STH: Statement Handle



The DBI code implements the majority of the methods which are accessed using the notation DBI->function. The following documented driver, database and statement functions which do not be written by the DBD driver writer.

Object Methods/Attributes Decription
DRH Methods parse_dsn() Breaks apart a DBI Data Source Name (DSN) and returns the individual parts
available_drivers() Returns a list of all available drivers by searching for DBD::* modules through the directories in @INC.
installed_drivers() Returns a list of driver name and driver handle pairs for all drivers 'installed' (loaded) into the current process. The driver name does not include the 'DBD::' prefix.
installed_versions() Calls available_drivers() and attempts to load each of them in turn using install_driver().
trace() The DBI->trace method sets the global default trace settings and returns the previous trace settings. It can also be used to change where the trace output is sent.
visit_handles() Where $coderef is a reference to a subroutine and $info is an arbitrary value which, if undefined, defaults to a reference to an empty hash. Returns $info.
data_string_desc() Returns an informal description of the string
data_string_diff() Returns an informal description of the first character difference between the strings.
data_diff() Returns an informal description of the first character difference between the strings.
neat() Return a string containing a neat (and tidy) representation of the supplied value.
neat_list(@listref, $maxlen, $field_sep) Calls neat on each element of the list and returns a string containing the results joined with $field_sep. $field_sep defaults to ", ".
looks_like_number() Returns true for each element that looks like a number. Returns false for each element that does not look like a number. Returns undef for each element that is undefined or empty.
hash($buffer, $type) Return a 32-bit integer 'hash' value corresponding to the contents of $buffer. The $type parameter selects which kind of hash algorithm should be used.
sql_type_cast($sv, $sql_type, $flags) sql_type_cast attempts to cast $sv to the SQL type (see "DBI Constants") specified in $sql_type. At present only the SQL types SQL_INTEGER, SQL_DOUBLE and SQL_NUMERIC are supported.
DRH Attributes $DBI::err Equivalent to $h->err.
$DBI::errstr Equivalent to $h->errstr.
$DBI::state Equivalent to $h->state.
$DBI::rows Equivalent to $h->rows.
$DBI::lasth Returns the DBI object handle used for the most recent DBI method call. If the last DBI method call was a DESTROY then $DBI::lasth will return the handle of the parent of the destroyed handle, if there is one.
Methods common to all handles err Returns the native database engine error code from the last driver method called. The code is typically an integer but you should not assume that.
errstr Returns the native database engine error message from the last DBI method called.
state Returns a state code in the standard SQLSTATE five character format.
set_err Set the err, errstr, and state values for the handle. This method is typically only used by DBI drivers and DBI subclasses.
trace The trace() method is used to alter the trace settings for a handle (and any future children of that handle). It can also be used to change where the trace output is sent.
trace_msg($message_text, $min_level) Writes $message_text to the trace file if the trace level is greater than or equal to $min_level (which defaults to 1).
can($method_name) Returns true if $method_name is implemented by the driver or a default method is provided by the DBI. It returns false where a driver hasn't implemented a method and the default method is provided by the DBI is just an empty stub.
parse_trace_flags() Parses a string containing trace settings and returns the corresponding integer value used internally by the DBI and drivers.
private_attribute_info() Returns a reference to a hash whose keys are the names of driver-private handle attributes available for the kind of handle (driver, database, statement) that the method was called on.
visit_child_handles( $coderef, $info ) Where $coderef is a reference to a subroutine and $info is an arbitrary value which, if undefined, defaults to a reference to an empty hash. Returns $info.
Attributes Common to all handles Warn Type: Boolean. The Warn attribute enables useful warnings for certain bad practices.
Active Type: Boolean. The Active attribute is true if the handle object is "active". This is rarely used in applications.
Executed Type: Boolean. The Executed attribute is true if the handle object has been "executed".
Kids Type: integer. For a driver handle, Kids is the number of currently existing database handles that were created from that driver handle.
ActiveKids Type: integer. Like Kids, but only counting those that are Active (as above).
CachedKids Type: hash ref. For a database handle, CachedKids returns a reference to the cache (hash) of statement handles created by the "prepare_cached" method. For a driver handle, returns a reference to the cache (hash) of database handles created by the "connect_cached" method.
CachedKids Type: scalar. The Type attribute identifies the type of a DBI handle. Returns "dr" for driver handles, "db" for database handles and "st" for statement handles.
ChildHandles Type: array ref. The ChildHandles attribute contains a reference to an array of all the handles created by this handle which are still accessible. The contents of the array are weak-refs and will become undef when the handle goes out of scope.
CompatMode Type: Boolean. The CompatMode attribute is used by emulation layers (such as Oraperl) to enable compatible behaviour in the underlying driver (e.g., DBD::Oracle) for this handle. Not normally set by application code.
InactiveDestroy Type: Boolean. The default value, false, means a handle will be fully destroyed as normal when the last reference to it is removed, just as you'd expect.
AutoInactiveDestroy Type: Boolean. The "InactiveDestroy" attribute, described above, needs to be explicitly set in the child process after a fork(). This is a problem if the code that performs the fork() is not under your control, perhaps in a third-party module. Use AutoInactiveDestroy to get around this situation.
PrintWarn Type: Boolean. The PrintWarn attribute controls the printing of warnings recorded by the driver.
PrintError Type: Boolean. The PrintError attribute can be used to force errors to generate warnings (using warn) in addition to returning error codes in the normal way.
RaiseError Type: Boolean. If you turn RaiseError on then you'd normally turn PrintError off. If PrintError is also on, then the PrintError is done first (naturally).
HandleSetErr Type: code ref. The HandleSetErr attribute can be used to intercept the setting of handle err, errstr, and state values.
ErrCount Type: unsigned integer. The ErrCount attribute is incremented whenever the set_err() method records an error. It isn't incremented by warnings or information states. It is not reset by the DBI at any time.
ShowErrorStatement Type: Boolean. The ShowErrorStatement attribute can be used to cause the relevant Statement text to be appended to the error messages generated by the RaiseError, PrintError, and PrintWarn attributes.
TraceLevel Type: integer. The TraceLevel attribute can be used as an alternative to the "trace" method to set the DBI trace level and trace flags for a specific handle.
FetchHashKeyName Type: string. The FetchHashKeyName attribute is used to specify whether the fetchrow_hashref() method should perform case conversion on the field names used for the hash keys.
ChopBlanks Type: Boolean. The ChopBlanks attribute can be used to control the trimming of trailing space characters from fixed width character (CHAR) fields.
ChopBlanks Type: unsigned integer. The LongReadLen attribute may be used to control the maximum length of 'long' type fields (LONG, BLOB, CLOB, MEMO, etc.) which the driver will read from the database automatically when it fetches each row of data.
LongReadLen Type: unsigned integer. The LongReadLen attribute may be used to control the maximum length of 'long' type fields (LONG, BLOB, CLOB, MEMO, etc.) which the driver will read from the database automatically when it fetches each row of data.
LongTruncOk Type: Boolean. The LongTruncOk attribute may be used to control the effect of fetching a long field value which has been truncated (typically because it's longer than the value of the LongReadLen attribute).
TaintIn Type: Boolean. If the TaintIn attribute is set to a true value and Perl is running in taint mode (e.g., started with the -T option), then all the arguments to most DBI method calls are checked for being tainted. This may change.
TaintOut Type: Boolean. If the TaintOut attribute is set to a true value and Perl is running in taint mode (e.g., started with the -T option), then most data fetched from the database is considered tainted. This may change.
Taint Type: Boolean. The Taint attribute is a shortcut for "TaintIn" and "TaintOut" (it is also present for backwards compatibility).
Profile The Profile attribute enables the collection and reporting of method call timing statistics.
ReadOnly Type: Boolean. An application can set the ReadOnly attribute of a handle to a true value to indicate that it will not be attempting to make any changes using that handle or any children of it.
DBH Methods clone() The clone method duplicates the $dbh connection by connecting with the same parameters ($dsn, $user, $password) as originally used.
do() Prepare and execute a single statement.
selectrow_array() This utility method combines "prepare", "execute" and "fetchrow_array" into a single call.
selectrow_arrayref() This utility method combines "prepare", "execute" and "fetchrow_arrayref" into a single call.
selectrow_hashref() This utility method combines "prepare", "execute" and "fetchrow_arrayref" into a single call.
selectall_arrayref() This utility method combines "prepare", "execute" and "fetchrow_arrayref" into a single call.
selectall_hashref() This utility method combines "prepare", "execute" and "fetchrow_arrayref" into a single call.
selectcol_arrayref() This utility method combines "prepare", "execute", and fetching one column from all the rows, into a single call.
prepare_cached() Like "prepare" except that the statement handle returned will be stored in a hash associated with the $dbh.
STH Methods bind_param_inout() This method acts like "bind_param", but also enables values to be updated by the statement. The statement is typically a call to a stored procedure.
execute_for_fetch() The execute_for_fetch() method is used to perform bulk operations and is most often used via the execute_array() method, not directly.
bind_col() Binds a Perl variable and/or some attributes to an output column (field) of a SELECT statement.
bind_columns() Calls "bind_col" for each column of the SELECT statement.
dump_results($maxlen, $lsep, $fsep, $fh) Fetches all the rows from $sth, calls DBI::neat_list for each row, and prints the results to $fh (defaults to STDOUT) separated by $lsep (default " "). $fsep defaults to ", " and $maxlen defaults to 35.
comments powered by Disqus
Page info
viewed 4864 times
translations en
Author
posted 3 years ago by
hellohuizhang
Contributors
updated 2 years ago by
View revisions
Share this article