dear win32 perl users,

i found the wonderful 'dbd-anydata' module and installed it to my windows
activeperl 5.8.8 build 820 environment (on Windows XP 32 bit).

i am able to use it to READ data from a 'Tab' delimited file.

i have followed, almost verbatim, the sample code to INSERT new records
into such a file - but i can not get this to work.

there are three different code fragment attempts ive made.

when each of these three code blocks run (one at a time obviously), in all
cases the return code for the execute (or do) statement is 1 (true).  yet
none of these actually results in a new record being added to the file
'oldfile.txt'.

Note: that 'oldfile.txt' is a simple 2 line ascii file - record 1 contains
two field names seperated with one tab (FIELD1\tFIELD2\n) line ending with
a standard windows newline. record 2 contains a dummy data line
(abc\tdef\n).

hopefully someone can see what i am doing incorrectly here and educate me
as to my mistake.

as well, if anyone has further knowledge, i also read there is an ability
to CREATE A TABLE using this same module.  if anyone can provide a
complete, yet simple code fragment showing how to do this (as well as
stating clearly what the original file content should be before the create
table code is executed, this would also help me to better understand what
needs to be in a dbd-anydata 'Tab' delimited file so that thismodule can
properly work with the file.

thanks in advance,

greg aiken



use DBI;
use DBD::AnyData;

my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):');


#i am trying to insert new record to an existing tab delimited file
#'oldfile.txt' is an ascii encoded two line file:
#FIELD1\tFIELD2\n
#abc\tdef\n

$dbh->func('insertnewrecstooldfile', 'Tab', 'oldfile.txt', 'ad_import');



#test 1   - attempt using DO with hard-coded 'values'

#$return1 = $dbh->do("INSERT INTO insertnewrecstooldfile (FIELD1,FIELD2)
VALUES ('ghi', 'jkl')");
#print "return1 = $return1\n";
#$dbh->disconnect;
#exit;

#result: returns 1, but the file does NOT contain the new record!



#test 2   - next level of indirection, using scalar values in the sql
command

#$value1  = 'mno';
#$value2  = 'pqr';
#$sql2    = qq{ INSERT INTO insertnewrecstooldfile (FIELD1,FIELD2) VALUES
('$value1', '$value2') };
#$return2 = $dbh->do($sql2);
#print "return2 = $return2\n";
#$dbh->disconnect;
#exit;

#result: returns 1, but the file does NOT contain the new record!



#test 3  - to pass in vars
#by way of preparing placeholders for values, then execute

#$value1  = 'stu';
#$value2  = 'vwx';
#$sql3    = qq{  INSERT INTO insertnewrecstooldfile (FIELD1,FIELD2) VALUES
(?,?) };
#$sth3    = $dbh->prepare($sql3);
#$return3 = $sth3->execute($value1, $value2);
#print "return3 = $return3\n";
#$dbh->disconnect;
#exit;

#result: returns 1, but the file does NOT contain the new record!
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to