Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Cannot insert into MS Access Memo field with DBI

by drewbert2000 (Initiate)
on Jan 09, 2002 at 02:51 UTC ( #137287=note: print w/ replies, xml ) Need Help??


in reply to Cannot insert into MS Access Memo field with DBI

I managed to find a solution to this problem without using another module (but thank you for the suggestion anyway). I imagine that not many people are writing TO an Access DB which is probably why there are no posts regarding this exact situation. Here is the code to make it work:

my $dbh = DBI->connect('DBI:ODBC:whatever', 'whatever', 'whatever'); my $sql = q{ INSERT INTO tblGuestbook (name, email, country, website, publicmessage, privatemessage, IP) values (?,?,?,?,?,?,?) }; my $sth = $dbh->prepare($sql); # Do this line for each one being inserted into a Memo field. $sth->bind_param( 4, $publicmesage, DBI::SQL_LONGVARCHAR ); $sth->bind_param( 5, $privatemesage, DBI::SQL_LONGVARCHAR ); $sth->execute($name,$email,$country,$website,$publicmessage,$privateme +ssage,$ENV{REMOTE_ADDR}); $sth->finish; $dbh->disconnect;
Hope that helps someone out there... =) Drewbert2000 08-Jan-2002 ===========


Comment on Re: Cannot insert into MS Access Memo field with DBI
Download Code
Re: Re: Cannot insert into MS Access Memo field with DBI
by Anonymous Monk on Mar 15, 2004 at 15:10 UTC
    It did help - I came across the same problem and found your solution which worked for me also! Cheers, Bill
      same here... thanks for posting.

        I'm having the same darn problem but the bind_param line isn't helping. This is my code:

        use DBI; $dbh = DBI->connect('dbi:ODBC:driver=microsoft access driver (*.mdb);' + . "dbq=$db_path"); my $note = "Order"; $sth = $dbh->prepare("INSERT INTO tblCustomer ( BranchID, LastName, Fi +rstName, Street, Town, County, PostCode, PhoneNumber, Email, Note ) SELECT ? AS Expr1, ? AS Expr2, ? AS Expr3, ? AS Expr4, ? AS Expr5, ? A +S Expr6, ? AS Expr7, ? AS Expr8, ? AS Expr9, ? AS Expr10; "); ## MSAccess is a piece of crap so you have to do this to fix anything +inserted into ## a memo field ... $sth->bind_param( 10, $note, DBI::SQL_LONGVARCHAR ); $sth->execute( 'L1', $secondname, $firstname, $order->{addresses}->{delivery}->{street}, $order->{addresses}->{delivery}->{city}, $order->{addresses}->{delivery}->{county}, $order->{addresses}->{delivery}->{postcode}, $order->{phone}, $order->{email}, $note ) or die "Could not update DB!";

        Anyone have a clue? The error message just says that the SQL is improperly formatted, which it does not do if I take out the 'note' line, which is the Memo.

Re^2: Cannot insert into MS Access Memo field with DBI
by Anonymous Monk on Jul 16, 2009 at 14:38 UTC
    I don't know if something changed in subsequent versions of DBI:ODBC, but I got this to work only after counting the order of my fields starting with 1 instead of 0. I.E. for the above example to work for me it would need to be:
    $sth->bind_param( 5, $publicmesage, DBI::SQL_LONGVARCHAR ); $sth->bind_param( 6, $privatemesage, DBI::SQL_LONGVARCHAR );
      This sounds crazy but I had this problem trying to put a string into the ms access memo field and after pulling out my hair I got the data in by putting it in an array. edit: array is NOT NEEDED. just do the blob support i.e.:

      $dbh->{LongReadLen} = 20000; #(change 20000 to your needs)
      $dbh->{LongTruncOk}=1; #(truncate at 20000)

      ***update: the blob support fixes it for going in too so the array is not needed. you can put the big string in if LongReadLen is active. d'oh.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://137287]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2014-10-20 23:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (93 votes), past polls