Re: from pgsql_perl5 to DBD-Pg




How to port code from Pg[1] to DBI[2]
[bare bones instructions]
=======================================

Tested and working thus far:
----------------------------

Connect to the SQL server:
[1]: $dbh = Pg::connectdb("dbname=$dbname");
[2]: $dbh = DBI->connect("DBI:Pg:dbname=$dbname", "", "", {AutoCommit
=> 1});

Query the SQL server:
[1]: $dbh->exec("<SQL STATEMENT>");
[2]: $dbh->do("<SQL STATEMENT>"); # non select
[2]: $sth = $dbg->prepare("<SQL STATEMENT>"); $sth->execute; # select

Return the error message of the query, if any:
[1]: $dbh->status == 0
[2]: (not defined $dbh->errstr)

[1]: $dbh->resultStatus == 1 # command ok
[2]: (not defined $sbh->errstr)

[1]: $dbh->resultStatus == 7 # fatal error
[2]: (defined $dbh->errstr)

Return the number of records in the query result:
[1]: $ntuples = $sth->ntuples
[2]: $results = $sth->fetchall_arrayref(); $ntuples = @$sth;

N.B. The documented method is "$sth->rows", but it does not work. The
method @$sth is not documented, but works. RECOMMENDATION FOR Tim
Bunce: Define and document a method "$sth->nrecords" that works.

Return the number of fields in the query result:
[1]: $sth->nfields
[2]: $sth->{NUM_OF_FIELDS}

N.B. RECOMMENDATION FOR Tim Bunce: Define and document a method "$sth-
nfields" as alias for "$sth->{NUM_OF_FIELDS}".

Return the field name associated with the given field number:
[1] $sth->fname($i)
[2]: $sth->{NAME}->[$i]

Return the value of the given record and field number:
[1]: $value = $sth->getvalue($r,$f);
[2]: $results = $sth->fetchall_arrayref(); $value = $results->[$r]
[$f];


very simple example:
-------------------------------

[1]:
my $bag = $dbh->exec("<SQL STATEMENT>);
for (my $n = 0; $n < $bag->rows; $n++) { print $bag->getvalue($n,0) .
"\n"; }

[2] (assuming autocommit=1):
my $bag2 = $dbh->prepare("<SQL STATEMENT>");
$bag2->execute;
my $bag = $bag2->fetchall_arrayref();
my $bag_rows = @$bag;
for (my $n = 0; $n < $bag_rows; $n++) { print $bag->[$n][0] . "\n"; }


Pending solution thus far:
--------------------------

In case the last query was an INSERT command it returns the oid of the
inserted
tuple:
[1]: $dbh->oidStatus
[2]: $dbg->pg_oid_status [untested]

Print all the records in an intelligent manner:
[1]: $sth->print($fout, $header, $align, $standard, $html3, $expanded,
$pager, $
fieldSep, $tableOpt, $caption)
[2]: ? - open thread at http://groups.google.it/group/perl.dbi.users/browse_thre
ad/thread/3fa50f7b647ada6d?hl=en


.



Relevant Pages

  • Re: CONTAINS performance
    ... That said, and with the query plan, I can start to give you more ... relational join in the context of the free-text optimization, ... SQL Server tables. ...
    (microsoft.public.sqlserver.fulltext)
  • Re: Indexing Service, Openquery and sp_executesql
    ... SQL Server version and sp are you running? ... > data from the indexing service catalog when pasted into ... > query analyzer, but failed when put against sp_executesql ... I would choose Microsoft Indexing ...
    (microsoft.public.sqlserver.fulltext)
  • Re: Problem using Access or Query Designer to run queries in SQL Serve
    ... >or Query Designer within Enterprise Manager, it works and I get data back. ... >ODBC Call Failed [ODBC SQL Server Driver] Timeout Expirederror in Access ... >[ODBC SQL Server Driver] Timeout Expired ...
    (microsoft.public.sqlserver.odbc)
  • Re: Transaction Isolation Level
    ... This means that while I initiate a transaction selecting all new orders it ... My query is executed on a SQL server 2005. ... the isolation level you should use is snapshot isolation. ...
    (comp.databases.ms-sqlserver)
  • Extreme performance issues (SQL Server 2000/ADO.NET/C#)
    ... This process runs very quickly if run through Query ... same exact stored procedures and views, run in the same exact order, through ... system that runs SQL Server (a 4-cpu Xeons system with 2gigs of physical ... When I execute these steps manually through query analyser,, ...
    (microsoft.public.dotnet.framework.adonet)