back forward index

Perl Database access


 

As I said I 'm no expert but I'll give you the benefit of the scripts on the mailing lists.

so here they are:=

  1. To check that the database service is running
  2. Byteserving from IIS
  3. How do I connect to an Oracle database from perl ?
  4. Using SDBM to store data

To check that the database service is running:

> >Aldo Calpini pointed out that:

----
use Win32::Service;

Win32::Service::GetServices ( NULL,\@list );
----
> >>
> >> The second argoment must be an associative array:
> >> Win32::Service::GetServices ( NULL,\%list );
>
> This gets over the 'usage' problem (but probably means that the HTML
> documentation needs some updating)...
>
> It looks though that GetServices (even combined with GetStatus) does
> not get me a list of which services are running... can this be true?
> The details that GetStatus returns don't correlate with the Control
> Panel 'Services' list in NT 3.51.

If you have values in the associative array values returned by
GetStatus, it means that the service is running; if it is stopped, all
the values of the array will be "".

Anyway, the array returned by GetStatus doesn't contain (apparently)
useful informations. If you want to get for example the startup type
for a service (auto, manual, disabled) you have to open the registry
key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\(servicename)

and then read the "Start" value, that equals to:
0x2 == Automatic
0x3 == Manual
0x4 == Disabled

Bye once again
Aldo Calpini

Back to top

Back to Perl page

 


Byteserving from IIS

I am currently trying to get Adobe's byteserver script for Acrobat 3.0
(Amber) running on our NT 3.51 server with IIS 1.0. I have successfully
install Perl32 and ran some small test scripts without a problem. When
the byteserver.pl script is ran it gives us all sorts of strange results.
It appears that the script is supposed to be saving the name of the .pdf
file that should be loaded as the $file variable. This is not what is
happening at all. It is using the Path_Translated environment variable
which is returning the path and name of the script not the file listed
after the script. I've listed the script below for reference.

Has anyone been able to get this thing working or have any experience
with this script?

Thanks in advance for any help.

Kevin

Adobe's Byetserver Perl Script:

#!/usr/bin/perl
# byteserver script
# byteserver.pl
# Last updated May 10, 1996
# This script implements the draft "Byte Range Retrieval Extension to
HTTP" described at
#"ftp://ds.internic.net/internet-drafts/draft-ietf-http-range-retrieval-00.txt".
# place this script wherever you can run CGIs on your Web server.
# query is of the form
# http://server/cgi-bin/byteserver/path/name/here
# with HTTP_RANGE specifying the ranges in the form
# "bytes=m1-n1,m2-n2,...,mn-nn"
# /path/name/here is relative to server root
# m-n are ranges (0 based). If m is absent, means n bytes from EOF,if n
# is absent, mean first m bytes of the file
# "bytes=..." syntax
# STDOUT the ranges
# The script issues HTTP1.0 206 Partial Content as a partial
# content response.
# Env. variables:
# PATH_TRANSLATED is the file name
# CONTENT_TYPE is what the server says is the mime type of file
# REQUEST_METHOD is the request method i.e. GET, POST etc. (we only
accept GET)
# HTTP_RANGE the byte range request
# Return syntax:
# if no ;bytes= is specified, returns:
# Accept-ranges: bytes
# Content-type: <content-type>
# Content-length: <file-length>
# <the file itself>
# if ;bytes= specified, returns:
#
# HTTP/1.0 206 Partial Content
# Accept-ranges: bytes
# Content-type: multipart/x-byteranges; boundary=$boundary
# < multipart-body >
sub badjob {
local($mesg) = @_;
print "Status: 403 \"BOGUS\"\r\n\r\n";
print "<HEAD><TITLE>403 BOGUS</TITLE></HEAD>"; print "<BODY><H1>403
BOGUS</H1>";
print "<pre>$mesg</pre>\r\n";
print "Bad Request\r\n\r\n";
exit 1;
}
$path = $ENV{'PATH_TRANSLATED'};
$ranges = $ENV{'HTTP_RANGE'};
($file, $query) = split(/;/,$path);
$contenttype = $ENV{'CONTENT_TYPE'};
if ($contenttype eq "")
{
$contenttype = "application/pdf";
}
if ((! -r $file) || (length $file <= 3))
{
&badjob("file $file not found");
}
if ($ENV{'REQUEST_METHOD'} ne 'GET')
{ # not URL-based query
&badjob("METHOD not GET");
}
$size = -s $file;
if (($query eq "") && ($ranges eq ""))
{

# respond that we can do ranges

print "Accept-ranges: bytes\r\n";

print "Content-type: $contenttype\r\n";

printf "Content-Length: %d\r\n\r\n", $size;

open(FILE, "< $file");

while(read(FILE, $buffer, 4096)) {
print STDOUT $buffer;
}
exit 0;
} else {
if ($ranges ne "")
{
$query = $ranges;
$query =~ s/bytes=//;
}
else
{
$query =~ s/\s+//g; # squeeze all whitespace out
$query =~ s/bytes=//;
}
#check that the ranges are properly formatted
@byterangeCheck = split(/[-,=]/,$query);
while (defined($fbyte = shift(@byterangeCheck))) {
$lbyte = shift(byterangeCheck);
if (($fbyte > 0) && ($lbyte < 0)) {
&badjob("query range malformed");
}
if (($fbyte < 0) && ($lbyte > 0)) {
&badjob("query range malformed");
}
if ($fbyte > $lbyte) {
&badjob("query range malformed");
}
}
@byterange = split(/[,]/,$query);
}
# print 206 only if called with official syntax
if ( $ranges ne "" )
{
print "Status: 206 Partial Content\r\n";
}
# print other header info
$boundary="multipart-boundary";
print "Accept-ranges: bytes\r\n";
print "Content-type: multipart/x-byteranges; boundary=$boundary\r\n\r\n";
# Serve up the bytes:
open(FILE, "< $file");
while (defined ($range = shift(@byterange))) {
($fbyte, $lbyte) = split('-', $range);
$i = index($range,"-");
if ($i == 0) { $fbyte = -1; }
if ($fbyte < 0) {
$fbyte = $size - $lbyte;
$lbyte = $size;
}
$nbytes = $lbyte - $fbyte + 1;
print "\r\n--$boundary\r\n";

print "Content-type: $contenttype\r\n";

printf "Content-Range: bytes %d-%d/%d\r\n\r\n", $fbyte, $lbyte,
$size;
seek(FILE, $fbyte, 0);
read(FILE, $buffer, $nbytes);
print STDOUT $buffer;
}
print "\r\n--$boundary--\r\n";
exit 0;

 

Back to top

Back to Perl page


>How do I connect to an Oracle database from perl ?
>Which drivers do I need. Can anyone guide me through the prosess?

Maybe Oracle has written an ODBC driver, so you can use Dave Roth's ODBC =
module. Check in your Contral Panel/(32-bits) ODBC if Oracle is listed. =
If not, call them and ask. If you find a ODBC driver, check out Dave's =
package at ftp://ftp.roth.net/pub/ntperl/odbc.zip.

http://www.roth.net/users/rothd/perl/odbc.html

 

Back to top

Back to Perl page


Here's code I used to get fairly good results with SDBM, the NDBM-workalike
that comes with NT-Perl. I use SDBM to store data from WWW forms with good
results.

Note that you HAVE to force O_BINARY or everything goes kablooie.

~Evangelo

---8<---------
#testSDBM.pl -- tests the SDBM_File module.

use SDBM_File;

$O_BINARY = hex( '0x8000' ); # binary flag
$O_CREAT = hex( '0x0100' ); # create flag
$O_RDWR = hex( '0x0002' ); # read-write flag
$max_val = 10_000; # I've set this as far as 1_000_000 with no errors.

print "Creating the file.\n";

tie( %myhash, SDBM_File, "numbertest",
$O_BINARY | $O_CREAT | $O_RDWR, 0666 )
|| die "Can't tie: $!";

for( $val = 0; $val < $max_val; $val++ )
{
$myhash{$val} = $val;
}

print "Closing the file...\n";

untie( %myhash );

print "Opening it again...\n";

tie( %myhash, SDBM_File, "numbertest", $O_BINARY | $O_RDWR, 0666 ) ||
die "Can't tie: $!";

$errors = 0;

for( $val = 0; $val < $max_val; $val++ )
{
$errors++ if ( $myhash{$val} != $val );
}

print "There were $errors errors.\n";


# This script uses SDBM and it works !!

use SDBM_File;
dbmopen(%DBM,"test",0644) || die "dbmopen failed";

$DBM{"key1"} = "value1";
$DBM{"key2"} = "value2";
$DBM{"key3"} = "value3";

while (($key,$value) = each(%DBM))
{
 print "$key : $value\n";
 }

 dbmclose(%DBM);

 


Back to top


Copyright © Robin S. Chatterjee. All rights reserved.

back forward index

This page hosted by Get your own Free Home Page