On 3/30/05 9:58, "Stas Bekman" <[EMAIL PROTECTED]> wrote:
> Tim Bunce wrote:
>> On Tue, Mar 29, 2005 at 11:46:28PM -0500, Stas Bekman wrote:
>>
>>> In order to properly test take_imp_data implementation, one needs to be
>>> able to test that when a second connect is issued and dbi_imp_data is
>>> passed:
>>>
>>> my $dbh = DBI->connect($test_dsn, $test_user, $test_password,
>>> { dbi_imp_data => $imp_data });
>>>
>>> a new connection won't be opened. Any ideas how to write such a test?
>>
>>
>> Looking at
>> http://search.cpan.org/~capttofu/DBD-mysql/lib/DBD/mysql.pm#DATABASE_HANDLES
>>
>> I'd have thought that $threadId = $dbh->{'mysql_thread_id'}; is what
>> you're looking for. It corresponds to the mysql_thread_id() API function:
>>
>> http://dev.mysql.com/doc/mysql/en/mysql-thread-id.html
>
> Yup, that did the trick! Thanks Tim.
>
You can also get it by issuing a SELECT CONNECTION_ID() statement, which
perhaps has the advantage that it will fail if the connection has gone away
and reconnect is off. mysql_thread_id() doesn't actually communicate with
the server. The corresponding disadvantage of CONNECTION_ID() is that it's
less efficient, of course.