NetSDS::DBI(3pm)
π NetSDS::DBI π
okay bestie, gather round, because this is the NetSDS::DBI page from the User Contributed Perl Documentation, and it's literally a whole wrapper around DBI for NetSDS. yes, that NetSDS. she's giving database-handling main character energy and we're obsessed. π
β¨ NAME β¨
NetSDS::DBI β a DBI wrapper for NetSDS, no cap π
πΈ SYNOPSIS πΈ
here's the vibe, copy it, love it, run it:
use NetSDS::DBI;
$dbh = NetSDS::DBI->new(
dsn => 'dbi:Pg:dbname=test;host=127.0.0.1;port=5432',
login => 'user',
passwd => 'topsecret',
);
print $db->call("select md5(?)", 'zuka')->fetchrow_hashref->{md5};
she's cute, she's compact, she does the thing π¦
π«Ά DESCRIPTION π«Ά
so NetSDS::DBI is a module that provides a wrapper around the DBI module. that's it, that's the whole pitch. iconic behavior honestly. β¨
π CLASS API π
new(%params) β the class constructor π«
bestie she builds you a database handle:
$dbh = NetSDS::DBI->new(
dsn => 'dbi:Pg:dbname=test;host=127.0.0.1;port=5432',
login => 'user',
passwd => 'topsecret',
);
dbh() β DBI connection handler accessor π
Returns: a DBI object, periodt.
this method gives you an accessor to the DBI object, so you can get that low level access to database specific methods. iykyk.
Example (access to specific method):
my $quoted = $db->dbh->quote_identifier(undef, 'auth', 'services');
# $quoted contains "auth"."services" now
look at her, quoting identifiers like a queen π
call($sql, @bind_params) β prepare and execute SQL query π₯
the call() method implements the following functionality, in this exact order:
- check connection to DBMS and restore it
- prepare chached SQL statement
- execute statement with bind parameters
Parameters:
- SQL query with placeholders
- bind parameters
Return:
- statement handler from DBI
Example:
$sth = $dbh->call("select * from users");
while (my $row = $sth->fetchrow_hashref()) {
print $row->{username};
}
fetch_call($sql, @params) β call and fetch result π
Paramters: SQL query, parameters
Returns: arrayref of records as hashrefs
Example:
# SQL DDL script:
# create table users (
# id serial,
# login varchar(32),
# passwd varchar(32)
# );
# Now we fetch all data to perl structure
my $table_data = $db->fetch_call("select * from users");
# Process this data
foreach my $user (@{$table_data}) {
print "User ID: " . $user->{id};
print "Login: " . $user->{login};
}
she hands you a whole perl data structure and you didn't even have to ask nicely π
begin() β start transaction π¬
commit() β commit transaction β
rollback() β rollback transaction π
quote() β quote SQL string π§
Example:
# Encode $str to use in queries
my $str = "some crazy' string; with (dangerous characters";
$str = $db->quote($str);
ngl, that string is full of dangerous characters, so let her do the quoting, fr fr. don't rawdog your SQL. π
π INTERNAL METHODS π
these are the behind-the-scenes girlies, not for your everyday group chat.
_add_sets() β add initial SQL query β
Example:
$obj->_add_sets("set search_path to myscheme");
$obj->_add_sets("set client_encoding to 'UTF-8'");
_add_attrs() β add DBI handler attributes π
$self->_add_attrs(AutoCommit => 1);
_check_connection() β ping and reconnect π
Internal method checking connection and implement reconnect.
_connect() β connect to DBMS π
Internal method starting connection to DBMS.
π EXAMPLES π
samples/testdb.pl
go peek, she's right there π«Ά
π SEE ALSO π
DBIDBD::Pg
π TODO π
- Make module less PostgreSQL specific.
(it's giving very-specific, and we respect the self-awareness π«Ά)
π AUTHOR π
Michael Bochkaryov <misha@rattler.kiev.ua>
π LICENSE π
Copyright (C) 2008-2009 Net Style Ltd.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
okay that's the whole page bestie, mwah π this one's from perl v5.32.1, dated 2021-12-26 β stay slaying, and remember: always bind your params, never trust a rogue apostrophe, and log off occasionally πΈπβ¨
π¦ where this page comes from
- debian bookworm: libnetsds-perl 1.301-4 Β· GPL-2.0-or-later
- debian trixie: libnetsds-perl 1.301-4 Β· GPL-2.0-or-later
- ubuntu jammy: libnetsds-perl 1.301-4 Β· GPL-2.0-or-later
- ubuntu noble: libnetsds-perl 1.301-4 Β· GPL-2.0-or-later
- ubuntu resolute: libnetsds-perl 1.301-4 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms