Hello peeps,
Ok I've managed to connect to a remote SQL server with WIN32::ODBC and a FILEDSN - sorted!
Only because I'm new I could do with advice on file/table/record locking under my new found DB environment.
I am re-developing a site that currently uses flat text files (PIPE Dilemited) and would use the current code to open and lock the file while processing the foreach record rows...
$catal_file = "$txt/catal.txt";
open(CATAL, "+<$catal_file");
flock(CATAL, 2);
binmode(CATAL);
@lines = <CATAL>;
foreach $line (@lines){
$line =~ s/\s+$//g;
($n7,$n6,$n5,$n4,$n3,$n2,$n1) = split(/\|/, $line);
if($n1 == 9){$n1 = 0;&add1;}
else{$n1++;}
}
$line = "$n7|$n6|$n5|$n4|$n3|$n2|$n1";
truncate(CATAL, length($line));
seek(CATAL, 0, 0);
print CATAL $line;
close(CATAL);
==============================================
Works great, file gets locked as each call to the routine is made.
What is the method to acheive the same thing via ODBC does
opening the dbase connection do the same job in as follows
# Open DB Connection
$db = new Win32::ODBC("FILEDSN=$DSN;UID=$UID;PWD=$PWD;") || die "Error connecting: " . Win32::ODBC::Error();
# Display SQL Data
if( ! $db->Sql( "SELECT * FROM [TABLE NAME]" ) ) {
while( $db->FetchRow() ) {
%Data = $db->DataHash();
@key_entries = keys(%Data);
$Row++;
print "\n$Row)";
foreach $key ( keys( %Data ) )
{
print "\t'$key' = '$Data{$key}'\n";
}
}
}
else
{
print "\nUnable to execute query: " . $db->Error() . "\n";
}
# Close DB Connection
$db->Close();
===========================================================
is the dbase released with the ->close(); or do i need to set some type of locking else where.
Hope you can help.
Regards 1DMF.
Ok I've managed to connect to a remote SQL server with WIN32::ODBC and a FILEDSN - sorted!
Only because I'm new I could do with advice on file/table/record locking under my new found DB environment.
I am re-developing a site that currently uses flat text files (PIPE Dilemited) and would use the current code to open and lock the file while processing the foreach record rows...
$catal_file = "$txt/catal.txt";
open(CATAL, "+<$catal_file");
flock(CATAL, 2);
binmode(CATAL);
@lines = <CATAL>;
foreach $line (@lines){
$line =~ s/\s+$//g;
($n7,$n6,$n5,$n4,$n3,$n2,$n1) = split(/\|/, $line);
if($n1 == 9){$n1 = 0;&add1;}
else{$n1++;}
}
$line = "$n7|$n6|$n5|$n4|$n3|$n2|$n1";
truncate(CATAL, length($line));
seek(CATAL, 0, 0);
print CATAL $line;
close(CATAL);
==============================================
Works great, file gets locked as each call to the routine is made.
What is the method to acheive the same thing via ODBC does
opening the dbase connection do the same job in as follows
# Open DB Connection
$db = new Win32::ODBC("FILEDSN=$DSN;UID=$UID;PWD=$PWD;") || die "Error connecting: " . Win32::ODBC::Error();
# Display SQL Data
if( ! $db->Sql( "SELECT * FROM [TABLE NAME]" ) ) {
while( $db->FetchRow() ) {
%Data = $db->DataHash();
@key_entries = keys(%Data);
$Row++;
print "\n$Row)";
foreach $key ( keys( %Data ) )
{
print "\t'$key' = '$Data{$key}'\n";
}
}
}
else
{
print "\nUnable to execute query: " . $db->Error() . "\n";
}
# Close DB Connection
$db->Close();
===========================================================
is the dbase released with the ->close(); or do i need to set some type of locking else where.
Hope you can help.
Regards 1DMF.