mirror of
https://git.FreeBSD.org/ports.git
synced 2024-11-01 22:05:08 +00:00
59 lines
1.8 KiB
Plaintext
59 lines
1.8 KiB
Plaintext
|
What you achieve with MsqlPerl
|
||
|
------------------------------
|
||
|
|
||
|
MsqlPerl is an interface between the perl programming language and the
|
||
|
mSQL programming API that comes with the mSQL relational database
|
||
|
management system. All functions provided by the mSQL programming API
|
||
|
are supported.
|
||
|
|
||
|
From perl you activate the interface with the statement
|
||
|
|
||
|
use Msql;
|
||
|
|
||
|
After that you can connect to multiple msql database servers and send
|
||
|
multiple queries to any of them via an simple object oriented
|
||
|
interface. Two types of objects are available: database handles and
|
||
|
statement handles. Perl returns a database handle to the Connect
|
||
|
method like so:
|
||
|
|
||
|
$dbh = Msql->connect($hostname,$databasename);
|
||
|
|
||
|
Once you have connected to a database, you get a statement handle
|
||
|
with:
|
||
|
|
||
|
$sth = $dbh->query("select foo from bar");
|
||
|
|
||
|
You can open as many queries as you like simultaneously by selecting a
|
||
|
different scalar to hold the object:
|
||
|
|
||
|
$another_sth = $dbh->Query("select bar from foo");
|
||
|
|
||
|
|
||
|
The statement handle allows you to step through the virtual table
|
||
|
returned from the database with the FetchRow method:
|
||
|
|
||
|
@row = $sth->fetchrow;
|
||
|
or
|
||
|
%hash = $sth->fetchhash;
|
||
|
|
||
|
You can access all metadata that mSQL supplies for a given table. To
|
||
|
find out the number of rows or the number of fields returned by a
|
||
|
query you simply say:
|
||
|
|
||
|
$numrows = $sth->numrows;
|
||
|
$numfields = $sth->numfields;
|
||
|
|
||
|
To find out the size in bytes for the field with the offset 0 (the
|
||
|
first field of a query), you say:
|
||
|
|
||
|
$length = $sth->length->[0];
|
||
|
|
||
|
The list of the names for each column is returned by
|
||
|
|
||
|
@list => $sth->name;
|
||
|
|
||
|
As for other metadata available, consult the manpage that comes with
|
||
|
MsqlPerl and study the examples in the file t/msql.t, which is the
|
||
|
extensive testscript to test your installation, but is heavily
|
||
|
commented, so you may use it as a tutorial.
|