Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#! perl -w use strict; use warnings; $|++; use DBI; print "DBI::VERSION $DBI::VERSION\n"; ### 1 open my $user = ""; my $password = ""; my $datasource = "dbi:ADO:TestGuids"; my $dbh = DBI->connect($datasource, $user, $password, { PrintError => 1, RaiseError => 0, }) || die "Can't connect to $datasource: $DBI::errstr"; my ($sth, $rc); ### 2 recreate table $sth = $dbh->prepare( q{ DROP TABLE Typelibs }); $rc = $sth->execute; ### WORKAROUND FOR PROBLEM BELOW: LIBID CHAR(48), $sth = $dbh->prepare( q{ CREATE TABLE Typelibs ( LIBID GUID, Name CHAR(48), Docstring CHAR(255) ) }); $rc = $sth->execute; ### 3 insert some rows $sth = $dbh->prepare( q{ INSERT INTO Typelibs ( LIBID, Name, Docstring ) VALUES ( '67913000-C464-11D3-82CF-00C04F55136E', 'MyTypelib', 'For test only.' ) }); $rc = $sth->execute; $sth = $dbh->prepare( q{ INSERT INTO Typelibs ( LIBID, Name, Docstring ) VALUES ( '67913001-C464-11D3-82CF-00C04F55136E', 'OtherTypelib', 'For test also.' ) }); $rc = $sth->execute; ### 4 fetch the rows and print $sth = $dbh->prepare( q{ SELECT * FROM Typelibs }); $rc = $sth->execute; print "Field names: @{ $sth->{NAME} }\n"; while (my @arr = $sth->fetchrow_array) { print "@arr\n"; } ### 5 update a row $sth = $dbh->prepare( q{ UPDATE Typelibs SET Docstring = 'Hello from Rudi.' WHERE Name = 'MyTypelib'; }); $rc = $sth->execute; print "$rc\n"; # returns 1 ### 6 update a row $sth = $dbh->prepare( q{ UPDATE Typelibs SET Docstring = 'Problem from Rudi.' WHERE LIBID = '67913001-C464-11D3-82CF-00C04F55136E'; }); $rc = $sth->execute; print "$rc\n"; ### 7 update a row $sth = $dbh->prepare( q{ UPDATE Typelibs SET Docstring = 'Problem from Rudi.' WHERE LIBID = '{GUID {67913001-C464-11D3-82CF-00C04F55136E}} +'; }); $rc = $sth->execute; print "$rc\n"; # rc == 0 ### 8 update a row $sth = $dbh->prepare( q/ UPDATE Typelibs SET Docstring = 'Problem from Rudi.' WHERE LIBID = {GUID {67913001-C464-11D3-82CF-00C04F55136E}}; /); $rc = $sth->execute; print "$rc\n"; # rc == 0 #[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing opera +tor) in #query expression 'LIBID = GUID 67913001-C464-11D3-82CF-00C04F55136E}' +. $dbh->disconnect;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Access 97 Win2k DBI::ADO question: how do I pass a GUID value to an SQL WHERE clause?
by Rudif (Hermit) on Oct 12, 2000 at 23:50 UTC |