Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Cannot insert into MS Access Memo field with DBI

by simon.proctor (Vicar)
on Jan 06, 2002 at 18:37 UTC ( [id://136679]=note: print w/replies, xml ) Need Help??


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

In their infintite wisdom, Microsoft decided to make Memo fields like Blobs but with some additional bits and bobs on top.

What this means is that you have to connect to the database in a totally different way. This is not a fault of the DBI or Perl as it catches you out in ASP code just as easily. To solve this, as far as I can see, you should use Win32::OLE and build recordsets to access your data. If not, then you'll have to save your data to disk and reference the filename in the database.

If you want the memo fields, the code (in VBScript) is as follows:
Set RS = Server.CreateObject("ADODB.RecordSet") RS.CursorLocation = adUseClient RS.Open table_name_or_sql_query, your_connection_object, adOpenKeyset

I took that from here. Now looking at the constants stuff, we need to define adUseClient and keyset which we can set as :
use constant adUseClient => 3; use constant adOpenKeyset => 1;


So all we need to do now is create the recordset and the connection object. Full code
use Win32::OLE; use strict; use constant adUseClient => 3; use constant adOpenKeySet => 1; my $db_connection = new Win32::OLE('ADODB.Connection'); my $rs = new Win32::OLE("ADODB.Recordset"); my $db_datasource = 'Driver={Microsoft Access Driver (*.mdb)}; +'; # My database is called test.mdb and is in the same dir. $db_datasource .= 'DBQ=test.mdb'; # Connect to the database and tie the recordset object to # the database. $db_connection->Open($db_datasource); # Set the connection doohickey $rs->CursorLocation(adUseClient); $rs->Open('test', $db_connection, adOpenKeySet);

I did a quick test on my win2k machine with an access2000 database and it ran without error (note that this is a DSN less connection). I hope that gives you a starting point :)
Cheers - Simon

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-03-19 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found