Steffen Goeldner

NAME

DBD::monetdb - MonetDB Driver for DBI

SYNOPSIS

  use DBI();

  my $dbh = DBI->connect('dbi:monetdb:');

  my $sth = $dbh->prepare('SELECT * FROM env');
  $sth->execute;
  $sth->dump_results;

DESCRIPTION

DBD::monetdb is a Pure Perl client interface for the MonetDB Database Server. It requires MonetDB::CLI (and one of its implementations).

Outline Usage

From perl you activate the interface with the statement

  use DBI;

After that you can connect to multiple MonetDB database servers and send multiple queries to any of them via a 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 = DBI->connect("dbi:monetdb:host=$host",
    $user, $password, { RaiseError => 1 } );

Once you have connected to a database, you can can execute SQL statements with:

  my $sql = sprintf('INSERT INTO foo VALUES (%d, %s)',
    $number, $dbh->quote('name'));
  $dbh->do($sql);

See DBI for details on the quote and do methods. An alternative approach is

  $dbh->do('INSERT INTO foo VALUES (?, ?)', undef, $number, $name);

in which case the quote method is executed automatically. See also the bind_param method in DBI.

If you want to retrieve results, you need to create a so-called statement handle with:

  $sth = $dbh->prepare("SELECT id, name FROM $table");
  $sth->execute;

This statement handle can be used for multiple things. First of all you can retreive a row of data:

  my $row = $sth->fetch;

If your table has columns ID and NAME, then $row will be array ref with index 0 and 1.

Example

  #!/usr/bin/perl

  use strict;
  use DBI;

  # Connect to the database.
  my $dbh = DBI->connect('dbi:monetdb:host=localhost',
    'joe', "joe's password", { RaiseError => 1 } );

  # Drop table 'foo'. This may fail, if 'foo' doesn't exist.
  # Thus we put an eval around it.
  eval { $dbh->do('DROP TABLE foo') };
  print "Dropping foo failed: $@\n" if $@;

  # Create a new table 'foo'. This must not fail, thus we don't
  # catch errors.
  $dbh->do('CREATE TABLE foo (id INTEGER, name VARCHAR(20))');

  # INSERT some data into 'foo'. We are using $dbh->quote() for
  # quoting the name.
  $dbh->do('INSERT INTO foo VALUES (1, ' . $dbh->quote('Tim') . ')');

  # Same thing, but using placeholders
  $dbh->do('INSERT INTO foo VALUES (?, ?)', undef, 2, 'Jochen');

  # Now retrieve data from the table.
  my $sth = $dbh->prepare('SELECT id, name FROM foo');
  $sth->execute;
  while ( my $row = $sth->fetch ) {
    print "Found a row: id = $row->[0], name = $row->[1]\n";
  }

  # Disconnect from the database.
  $dbh->disconnect;

METHODS

Driver Handle Methods

connect
  use DBI();

  $dsn = 'dbi:monetdb:';
  $dsn = "dbi:monetdb:host=$host";
  $dsn = "dbi:monetdb:host=$host;port=$port";

  $dbh = DBI->connect($dsn, $user, $password);
host

The default host to connect to is 'localhost', i.e. your workstation.

port

The port where MonetDB daemon listens to. Default for MonetDB is 50000.

Database Handle Methods

The following methods are currently not supported:

  last_insert_id

All MetaData methods are supported. However, column_info() currently doesn't provide length (size, ...) related information. The foreign_key_info() method returns a SQL/CLI like result set, because it provides additional information about unique keys.

Statement Handle Methods

The following methods are currently not supported:

  bind_param_inout
  more_results
  blob_read

ATTRIBUTES

The following attributes are currently not supported:

  LongReadLen
  LongTruncOk

Database Handle Attributes

The following attributes are currently not supported:

  RowCacheSize

Statement Handle Attributes

The following attributes are currently not (or not correctly) supported:

  PRECISION  (MonetDB semantic != DBI semantic)
  SCALE      (empty)
  NULLABLE   (SQL_NULLABLE_UNKNOWN = 2)
  CursorName
  RowsInCache

AUTHORS

Martin Kersten <Martin.Kersten@cwi.nl> implemented the initial Mapi based version of the driver (monet.pm). Arjan Scherpenisse <acscherp@science.uva.nl> renamed this module to monetdbPP.pm and derived the new MapiLib based version (monetdb.pm). Current maintainer is Steffen Goeldner <sgoeldner@cpan.org>.

COPYRIGHT AND LICENCE

The contents of this file are subject to the MonetDB Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html

Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License.

The Original Code is the MonetDB Database System.

The Initial Developer of the Original Code is CWI. Portions created by CWI are Copyright (C) 1997-2006 CWI. All Rights Reserved.

Contributor(s): Steffen Goeldner.

SEE ALSO

MonetDB

  Homepage    : http://monetdb.cwi.nl
  SourceForge : http://sourceforge.net/projects/monetdb

Perl modules

DBI, MonetDB::CLI