mysql-native v2.1.0

bauss jj_1337 at live.dk
Wed Mar 7 21:53:42 UTC 2018


On Wednesday, 7 March 2018 at 19:36:57 UTC, bauss wrote:
> On Wednesday, 7 March 2018 at 11:04:10 UTC, Nick Sabalausky 
> (Abscissa) wrote:
>> On 03/06/2018 01:31 PM, bauss wrote:
>>> 
>>> I can't seem to find any examples on how they were updated 
>>> and what exactly to change in my code.
>>> 
>>
>> Also, FWIW, mysql-native uses semantic versioning (semver), so 
>> anything that worked in v2.0.0 should still continue working 
>> in all v2.x.x.
>
> I was all the way down at 1.1.2, because of other issues that I 
> can't remember on top of my head, but they have since been 
> resolved. There were only one issue back for which was the 
> locked connection thing, which my post above has a link to.

So I changed my code to do this with retrieving the pool and 
creating it:

/// Collection of connection pools.
private static __gshared MySQLPool[string] _pools;

/// Global pool lock to ensure we don't attempt to create a 
connection pool twice on same connection string.
private static shared globalPoolLock = new Object;

/**
* Gets a new mysql connection from the pool.
* Params:
*   connectionString = The connection string for the connection.
* Returns:
*   The mysql connection.
*/
private MySQLPool getPool(string connectionString)
{
   auto pool = _pools.get(connectionString, null);

   if (!pool)
   {
     synchronized (globalPoolLock)
     {
       pool = new MySQLPool(connectionString);

       _pools[connectionString] = pool;
     }

     return getPool(connectionString);
   }

   return pool;
}

And when using it:

   auto pool = getPool(useDbConnectionString);
   auto connection = pool.lockConnection();

   auto prepared = connection.prepare(sql);
   prepared.setArgs(params);

Rather than just returning the connection from it.

I can't seem to reproduce it now, but I'll keep an eye for it and 
see if it still happens, but I think the problem is when you 
return the connection from a function.

I had similar issues returning a raw connection created.


More information about the Digitalmars-d-announce mailing list