comparison Framework/Common/DatabaseManager.cpp @ 12:41543239072d

transactions for storage area
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 09 Jul 2018 18:34:56 +0200
parents 7cea966b6829
children c7c54993a92e
comparison
equal deleted inserted replaced
11:0217486720b3 12:41543239072d
284 284
285 return *result_; 285 return *result_;
286 } 286 }
287 287
288 288
289 void DatabaseManager::CachedStatement::Setup(const char* sql)
290 {
291 statement_ = manager_.LookupCachedStatement(location_);
292
293 if (statement_ == NULL)
294 {
295 query_.reset(new Query(sql));
296 }
297 else
298 {
299 LOG(TRACE) << "Reusing cached statement from "
300 << location_.GetFile() << ":" << location_.GetLine();
301 }
302 }
303
304
289 DatabaseManager::CachedStatement::CachedStatement(const StatementLocation& location, 305 DatabaseManager::CachedStatement::CachedStatement(const StatementLocation& location,
290 DatabaseManager& manager, 306 DatabaseManager& manager,
291 const char* sql) : 307 const char* sql) :
292 lock_(manager.mutex_), 308 lock_(manager.mutex_),
293 manager_(manager), 309 manager_(manager),
294 location_(location), 310 location_(location),
295 database_(manager.GetDatabase()),
296 transaction_(manager.GetTransaction()) 311 transaction_(manager.GetTransaction())
297 { 312 {
298 statement_ = manager_.LookupCachedStatement(location); 313 Setup(sql);
299 314 }
300 if (statement_ == NULL) 315
301 { 316
302 query_.reset(new Query(sql)); 317 DatabaseManager::CachedStatement::CachedStatement(const StatementLocation& location,
303 } 318 Transaction& transaction,
304 else 319 const char* sql) :
305 { 320 lock_(manager_.mutex_),
306 LOG(TRACE) << "Reusing cached statement from " 321 manager_(transaction.GetManager()),
307 << location.GetFile() << ":" << location.GetLine(); 322 location_(location),
308 } 323 transaction_(manager_.GetTransaction())
324 {
325 Setup(sql);
309 } 326 }
310 327
311 328
312 void DatabaseManager::CachedStatement::SetReadOnly(bool readOnly) 329 void DatabaseManager::CachedStatement::SetReadOnly(bool readOnly)
313 { 330 {