Rumah >pangkalan data >tutorial mysql >New release of Perl DBD::ODBC with support for MS SQL Server_MySQL
I just released the 3rddevelopment release of DBD::ODBC (1.39_3). Apart from a few bug fixes and other changes (see below) this release adds support for MS SQL Server Query Notification. Query notification allows an application to request a notification from SQL Server when the results of a query change. Once set up you can block on an execute call waiting for the query to change. Here is an excerpt from the pod:
Query notifications were introduced in SQL Server 2005 and SQL Server Native Client. Query notifications allow applications to be notified when data has changed.
DBD::ODBC supports query notification with MS SQL Server using the additional prepare attributes odbc_qn_msgtxt, odbc_qn_options and odbc_qn_timeout. When you pass suitable values for these attributes to the prepare method, DBD::ODBC will make the appropriate SQLSetStmtAttr calls after the statement has been allocated.
It is beyond the scope of this document to provide a tutorial on doing this but here are some notes that might help you get started.
# Prepare the statement.
# This is the SQL you want to know if the result changes later
my$sth=$dbh->prepare(q/SELECT a, b, c FROM dbo.QNtest WHERE a = 1/,
{odbc_qn_msgtxt=>'Message text',
odbc_qn_options=>'service=myService;local database=MyDatabase',
odbc_qn_timeout=>430000});
# Fetch and display the result set value.
while(my@row=$sth->fetchrow_array){
print"@row/n";
}
# select * from sys.dm_qn_subscriptions will return a record now you are subscribed
# This query generates a result telling you which query has changed
# It will block until the timeout or the query changes
my$sth=$dbh->prepare(q/WAITFOR (RECEIVE * FROM MyQueue)/);
$sth->execute();
# in the mean time someone does UPDATE dbo.QNtest SET c = '19981212' WHERE a = 1
# Fetch and display the result set value.
while(my@row=$sth->fetchrow_array){
print"@row/n";
}
# You now need to understand the result and look to decide which query has changed